Skip to content

Instantly share code, notes, and snippets.

@robilic
Created June 2, 2022 14:59
Show Gist options
  • Save robilic/dcaa57f7805a940baddc8756b673570f to your computer and use it in GitHub Desktop.
Save robilic/dcaa57f7805a940baddc8756b673570f to your computer and use it in GitHub Desktop.
Find a package that works with your outdated requirements
# Search pypi to find a package old enough to work with your requirements
import requests
import json
import re
from packaging import version
packageName = 'dask'
subPackageName = 'pyyaml'
desiredVersion = '5.1.2'
url = 'https://pypi.org/pypi/{}/json'
pkginfo = requests.get(url.format(packageName)).json()
releases = sorted(pkginfo['releases'].keys(),reverse=True)
# step through all releases
for k in releases:
print("Checking release ", k)
url = 'https://pypi.org/pypi/{}/{}/json'
data = requests.get(url.format(packageName, k)).json()
subPackages = data['info']['requires_dist']
for p in subPackages:
# is this the package we are looking for?
if re.search(subPackageName.upper(), p.upper()):
# extract version number - fails on versionless packages
thisVersion = re.search(r'[\d\.]+', p)
if thisVersion:
if version.parse(thisVersion.group()) > version.parse(desiredVersion):
print("Found ", thisVersion.group(), " which is too new")
else:
print("Found ", thisVersion.group(), " which is old enough")
exit()
else:
print("No version specified, but it might work")
exit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment