Skip to content

Commit a31e507

Browse files
authored
fix: Gracefully handle invalid python_requires when finding minversion (#37317)
python_requires must follow the specification defined in: https://packaging.python.org/en/latest/specifications/version-specifiers/#id5 In the event that a package version specifies a `python_requires` that does not match that spec, execution terminates with an InvalidSpecifier exception. This commit makes it so that we catch and log the exception, ignoring the version that has the invalid python version specifier. An alternative solution could have been to attempt to correct the version specifier (e.g. '>= 3.5.*' is invalid, but it'd be trivial to correct it to '>=3.5'). But that would potentially invite a complexity that costs more than it's worth.
1 parent 0b71075 commit a31e507

File tree

1 file changed

+7
-3
lines changed
  • tools/azure-sdk-tools/pypi_tools

1 file changed

+7
-3
lines changed

tools/azure-sdk-tools/pypi_tools/pypi.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,19 @@ def project_release(self, package_name, version):
3939

4040
def filter_packages_for_compatibility(self, package_name, version_set):
4141
# only need the packaging.specifiers import if we're actually executing this filter.
42-
from packaging.specifiers import SpecifierSet
42+
from packaging.specifiers import InvalidSpecifier, SpecifierSet
4343

4444
results = []
4545

4646
for version in version_set:
4747
requires_python = self.project_release(package_name, version)["info"]["requires_python"]
4848
if requires_python:
49-
if Version(".".join(map(str, sys.version_info[:3]))) in SpecifierSet(requires_python):
50-
results.append(version)
49+
try:
50+
if Version(".".join(map(str, sys.version_info[:3]))) in SpecifierSet(requires_python):
51+
results.append(version)
52+
except InvalidSpecifier:
53+
logging.warn(f"Invalid python_requires {requires_python!r} for package {package_name}=={version}")
54+
continue
5155
else:
5256
results.append(version)
5357

0 commit comments

Comments
 (0)