|
8 | 8 |
|
9 | 9 | import distlib.markers
|
10 | 10 | from packaging.version import Version, parse
|
| 11 | +from pkg_resources import RequirementParseError |
11 | 12 |
|
12 | 13 | from .nixpkgs import NixpkgsIndex
|
13 | 14 | from mach_nix.requirements import filter_reqs_by_eval_marker, Requirement, parse_reqs, context
|
@@ -65,7 +66,7 @@ def __init__(self, pkg_name, pkg_ver, provider_name, *args, **kwargs):
|
65 | 66 |
|
66 | 67 | class DependencyProviderBase(ABC):
|
67 | 68 | def __init__(self, py_ver: PyVer, platform, system, *args, **kwargs):
|
68 |
| - self.context = context(py_ver) |
| 69 | + self.context = context(py_ver, platform, system) |
69 | 70 | self.context_wheel = self.context.copy()
|
70 | 71 | self.context_wheel['extra'] = None
|
71 | 72 | self.py_ver_digits = py_ver.digits()
|
@@ -202,11 +203,6 @@ def _available_versions(self, pkg_name: str) -> Iterable[Version]:
|
202 | 203 |
|
203 | 204 | class NixpkgsDependencyProvider(DependencyProviderBase):
|
204 | 205 | name = 'nixpkgs'
|
205 |
| - # mapping from pypi name to nix key |
206 |
| - # _aliases = dict( |
207 |
| - # torch='pytorch', |
208 |
| - # tensorboard='tensorflow-tensorboard' |
209 |
| - # ) |
210 | 206 |
|
211 | 207 | # TODO: implement extras by looking them up via the equivalent wheel
|
212 | 208 | def __init__(
|
@@ -261,22 +257,24 @@ class WheelDependencyProvider(DependencyProviderBase):
|
261 | 257 | def __init__(self, data_dir: str, *args, **kwargs):
|
262 | 258 | super(WheelDependencyProvider, self).__init__(*args, **kwargs)
|
263 | 259 | self.data = LazyBucketDict(data_dir)
|
264 |
| - m = self.py_ver_digits[-1] |
| 260 | + maj = self.py_ver_digits[0] # major version |
| 261 | + min = self.py_ver_digits[1] # minor version |
265 | 262 | if self.system == "linux":
|
| 263 | + cp_abi = f"cp{maj}{min}mu" if int(maj) == 2 else f"cp{maj}{min}m" |
266 | 264 | self.preferred_wheels = (
|
267 |
| - re.compile(rf"(py3|cp3){m}?-(cp3{m}m|abi3|none)-manylinux2014_{self.platform}"), |
268 |
| - re.compile(rf"(py3|cp3){m}?-(cp3{m}m|abi3|none)-manylinux2010_{self.platform}"), |
269 |
| - re.compile(rf"(py3|cp3){m}?-(cp3{m}m|abi3|none)-manylinux1_{self.platform}"), |
270 |
| - re.compile(rf"(py3|cp3){m}?-(cp3{m}m|abi3|none)-linux_{self.platform}"), |
271 |
| - re.compile(rf"(py3|cp3){m}?-(cp3{m}m|abi3|none)-any"), |
| 265 | + re.compile(rf"(py{maj}|cp{maj}){min}?-({cp_abi}|abi3|none)-manylinux2014_{self.platform}"), |
| 266 | + re.compile(rf"(py{maj}|cp{maj}){min}?-({cp_abi}|abi3|none)-manylinux2010_{self.platform}"), |
| 267 | + re.compile(rf"(py{maj}|cp{maj}){min}?-({cp_abi}|abi3|none)-manylinux1_{self.platform}"), |
| 268 | + re.compile(rf"(py{maj}|cp{maj}){min}?-({cp_abi}|abi3|none)-linux_{self.platform}"), |
| 269 | + re.compile(rf"(py{maj}|cp{maj}){min}?-({cp_abi}|abi3|none)-any"), |
272 | 270 | )
|
273 | 271 | elif self.system == "darwin":
|
274 | 272 | self.preferred_wheels = (
|
275 |
| - re.compile(rf"(py3|cp3){m}?-(cp3{m}|abi3|none)-macosx_\d*_\d*_universal"), |
276 |
| - re.compile(rf"(py3|cp3){m}?-(cp3{m}|abi3|none)-macosx_\d*_\d*_x86_64"), |
277 |
| - re.compile(rf"(py3|cp3){m}?-(cp3{m}|abi3|none)-macosx_\d*_\d*_intel"), |
278 |
| - re.compile(rf"(py3|cp3){m}?-(cp3{m}|abi3|none)-macosx_\d*_\d*_(fat64|fat32)"), |
279 |
| - re.compile(rf"(py3|cp3){m}?-(cp3{m}|abi3|none)-any"),) |
| 273 | + re.compile(rf"(py{maj}|cp{maj}){min}?-(cp{maj}{min}|abi3|none)-macosx_\d*_\d*_universal"), |
| 274 | + re.compile(rf"(py{maj}|cp{maj}){min}?-(cp{maj}{min}|abi3|none)-macosx_\d*_\d*_x86_64"), |
| 275 | + re.compile(rf"(py{maj}|cp{maj}){min}?-(cp{maj}{min}|abi3|none)-macosx_\d*_\d*_intel"), |
| 276 | + re.compile(rf"(py{maj}|cp{maj}){min}?-(cp{maj}{min}|abi3|none)-macosx_\d*_\d*_(fat64|fat32)"), |
| 277 | + re.compile(rf"(py{maj}|cp{maj}){min}?-(cp{maj}{min}|abi3|none)-any"),) |
280 | 278 | else:
|
281 | 279 | raise Exception(f"Unsupported Platform {platform.system()}")
|
282 | 280 |
|
@@ -317,7 +315,7 @@ def _all_releases(self, pkg_name):
|
317 | 315 | fn,
|
318 | 316 | deps['requires_dist'] if 'requires_dist' in deps else None,
|
319 | 317 | deps['requires_extras'] if 'requires_extras' in deps else None,
|
320 |
| - deps['requires_python'] if 'requires_python' in deps else None, |
| 318 | + deps['requires_python'].strip(',') if 'requires_python' in deps else None, |
321 | 319 | )
|
322 | 320 |
|
323 | 321 | def _apply_filters(self, filters: List[callable], objects: Iterable):
|
@@ -362,7 +360,12 @@ def _python_requires_ok(self, wheel: WheelRelease):
|
362 | 360 | if not wheel.requires_python:
|
363 | 361 | return True
|
364 | 362 | ver = parse('.'.join(self.py_ver_digits))
|
365 |
| - return bool(filter_versions([ver], list(parse_reqs(f"python{wheel.requires_python}"))[0].specs)) |
| 363 | + try: |
| 364 | + parsed_py_requires = list(parse_reqs(f"python{wheel.requires_python}")) |
| 365 | + return bool(filter_versions([ver], parsed_py_requires[0].specs)) |
| 366 | + except RequirementParseError: |
| 367 | + print(f"WARNING: `requires_python` attribute of wheel {wheel.name}:{wheel.ver} could not be parsed") |
| 368 | + return False |
366 | 369 |
|
367 | 370 |
|
368 | 371 | class SdistDependencyProvider(DependencyProviderBase):
|
|
0 commit comments