Skip to content

Commit

Permalink
Latest/Minimum filter retrieved packages by pyVersion compatibility (#…
Browse files Browse the repository at this point in the history
…16510)

* filter packages by python_requires release info retrieved by pypi. now we only select package versions that are compatible with current platform
  • Loading branch information
scbedd authored Feb 4, 2021
1 parent 45b4231 commit cfe7f84
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion eng/tox/install_depend_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def process_requirement(req, dependency_type):

# get available versions on PyPI
client = PyPIClient()
versions = [str(v) for v in client.get_ordered_versions(pkg_name)]
versions = [str(v) for v in client.get_ordered_versions(pkg_name, True)]
logging.info("Versions available on PyPI for %s: %s", pkg_name, versions)

if pkg_name in MINIMUM_VERSION_SUPPORTED_OVERRIDE:
Expand Down
1 change: 1 addition & 0 deletions scripts/devops_tasks/common_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"azure",
"azure-mgmt",
"azure-storage",
"azure-mgmt-regionmove"
]
MANAGEMENT_PACKAGE_IDENTIFIERS = [
"mgmt",
Expand Down
24 changes: 23 additions & 1 deletion tools/azure-sdk-tools/pypi_tools/pypi.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from packaging.version import parse as Version
import sys

import requests

Expand Down Expand Up @@ -34,14 +35,35 @@ def project_release(self, package_name, version):
response.raise_for_status()
return response.json()

def get_ordered_versions(self, package_name):
def filter_packages_for_compatibility(self, package_name, version_set):
# only need the packaging.specifiers import if we're actually executing this filter.
from packaging.specifiers import SpecifierSet

results = []

for version in version_set:
requires_python = self.project_release(package_name, version)["info"]["requires_python"]
if requires_python:
if Version('.'.join(map(str, sys.version_info[:3]))) in SpecifierSet(requires_python):
results.append(version)
else:
results.append(version)

return results

def get_ordered_versions(self, package_name, filter_by_compatibility = False):
project = self.project(package_name)

versions = [
Version(package_version)
for package_version
in project["releases"].keys()
]
versions.sort()

if filter_by_compatibility:
return self.filter_packages_for_compatibility(package_name, versions)

return versions

def get_relevant_versions(self, package_name):
Expand Down

0 comments on commit cfe7f84

Please sign in to comment.