Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Latest/Minimum filter retrieved packages by pyVersion compatibility #16510

Merged
merged 3 commits into from
Feb 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -42,6 +42,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