pkgsrc-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

pypi update checker



Hi!

The attached script checks a pypi pkgsrc package for updates.

Usage:
# pypi-update-checker archivers/py-brotli
(no change)
# pypi-update-checker www/py-werkzeug
www/py-werkzeug 2.2.3 2.3.2 UPDATE

Cheers,
 Thomas
#!/usr/bin/env python3

import argparse
import re
import subprocess

import json
import requests

project_re = re.compile('.*pythonhosted.org/packages/source/./([^/]*)/.*')

parser = argparse.ArgumentParser(description='Fetch list of releases for a pypi project')
parser.add_argument('path', type=str, nargs='+')
args = parser.parse_args()
for system in args.path:
    organization = None
    result = subprocess.run(['make', 'show-vars',
                             'VARNAMES=MASTER_SITES PKGVERSION_NOREV'],
                            cwd="/usr/pkgsrc/" + system, capture_output=True, encoding='utf-8')
    if result.returncode != 0:
        print("extracting variables failed for " + system)
        continue
    master_sites, pkgversion = result.stdout.splitlines()
    for site in master_sites.split():
        if m := project_re.match(site):
            project = m.group(1)
            break
    if project is None:
        print("no pypi project found for " + system)
        continue
    url = 'https://pypi.org/pypi/' + project + '/json'
    result = requests.get(url, timeout=5)
    if result.status_code != 200:
        print("error fetching release info for " + system + ": " + url)
        print(result)
        continue
    parsed = json.loads(result.text)
    latest_version = parsed['info']['version']
    if pkgversion != latest_version:
        print(system, pkgversion, latest_version, "UPDATE")


Home | Main Index | Thread Index | Old Index