Skip to content

Commit

Permalink
Allow to specify wheel platform
Browse files Browse the repository at this point in the history
  • Loading branch information
ozobotnovako committed Apr 9, 2024
1 parent e83ba52 commit d954a87
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
15 changes: 11 additions & 4 deletions pip2nix/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import re
import shutil

from pip._internal.models.target_python import TargetPython

try:
from pip._internal.cli import cmdoptions
except:
Expand Down Expand Up @@ -98,7 +100,8 @@ def process_requirements(self, options, requirement_set, finder, resolver):
packages = {
req.name: PythonPackage.from_requirements(
req, resolver._discovered_dependencies.get(req.name, []),
finder, self.config["pip2nix"].get("check_inputs")
finder, self.config["pip2nix"].get("check_inputs"),
self.config.get_config("pip2nix", "platform")
)
for req in packages_base
if not req.constraint
Expand Down Expand Up @@ -137,14 +140,16 @@ def process_requirements(self, options, requirement_set, finder, resolver):
packages[req.name] = PythonPackage.from_requirements(
requirement_set.requirements[req.name],
resolver._discovered_dependencies.get(req.name, []),
finder, self.config["pip2nix"].get("check_inputs")
finder, self.config["pip2nix"].get("check_inputs"),
self.config.get_config("pip2nix", "platform")
)
except KeyError:
req.req.name = req.name.lower() # try to work around case differences
packages[req.name] = PythonPackage.from_requirements(
requirement_set.requirements[req.name],
resolver._discovered_dependencies.get(req.name, []),
finder, self.config["pip2nix"].get("check_inputs")
finder, self.config["pip2nix"].get("check_inputs"),
self.config.get_config("pip2nix", "platform")
)

# If you need a newer version of setuptools or wheel, you know it and
Expand Down Expand Up @@ -194,7 +199,9 @@ def super_run(self, options, args):
upgrade_strategy = options.upgrade_strategy

with self._build_session(options) as session:
finder = self._build_package_finder(options, session)
platform = self.config.get_config("pip2nix", "platform")
target_python = TargetPython(platform)
finder = self._build_package_finder(options, session, target_python)
wheel_cache = WheelCache(options.cache_dir, options.format_control)
try:
requirement_set = RequirementSet(
Expand Down
8 changes: 6 additions & 2 deletions pip2nix/models/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def __init__(self, name, version, dependencies, source, pip_req, setup_requires,
self.pip_req = pip_req

@classmethod
def from_requirements(cls, req, deps, finder, check):
def from_requirements(cls, req, deps, finder, check, platform):
def name_version(dep):
return (
dep.name,
Expand Down Expand Up @@ -158,7 +158,11 @@ def name_version(dep):
pass
break

if ((source.path.endswith('.whl') and not source.path.endswith('-any.whl'))
platform_suffixes = ["-any.whl"]
if platform:
platform_suffixes.append(f"{platform}.whl")

if ((source.path.endswith('.whl') and not any(source.path.endswith(suffix) for suffix in platform_suffixes))
or source.path.endswith('.egg')):
finder.format_control.disallow_binaries()
source = finder.find_requirement(req, upgrade=False)
Expand Down

0 comments on commit d954a87

Please sign in to comment.