From 325eaef2b997dc19f2ace9ee15e687eedd6c2f8a Mon Sep 17 00:00:00 2001 From: Thomas Grainger Date: Thu, 6 Apr 2017 12:50:17 +0100 Subject: [PATCH] specifiy which wheels to download --- piptools/repositories/pypi.py | 4 +++ piptools/scripts/compile.py | 52 +++++++++++++++++++++++++---------- 2 files changed, 41 insertions(+), 15 deletions(-) diff --git a/piptools/repositories/pypi.py b/piptools/repositories/pypi.py index 080874ae9..5ec8002f3 100644 --- a/piptools/repositories/pypi.py +++ b/piptools/repositories/pypi.py @@ -49,6 +49,10 @@ def __init__(self, pip_options, session): allow_all_prereleases=pip_options.pre, process_dependency_links=pip_options.process_dependency_links, session=self.session, + platform=pip_options.platform, + versions=pip_options.python_version, + implementation=pip_options.implementation, + abi=pip_options.abi, ) # Caches diff --git a/piptools/scripts/compile.py b/piptools/scripts/compile.py index d88a72963..343f7ab8e 100755 --- a/piptools/scripts/compile.py +++ b/piptools/scripts/compile.py @@ -9,6 +9,7 @@ import pip from pip.req import InstallRequirement, parse_requirements +from pip.commands.download import DownloadCommand from .. import click from ..exceptions import PipToolsError @@ -25,7 +26,7 @@ DEFAULT_REQUIREMENTS_FILE = 'requirements.in' -class PipCommand(pip.basecommand.Command): +class PipCommand(DownloadCommand): name = 'PipCommand' @@ -63,11 +64,33 @@ class PipCommand(pip.basecommand.Command): help="Generate pip 8 style hashes in the resulting requirements file.") @click.option('--max-rounds', default=10, help="Maximum number of rounds before resolving the requirements aborts.") +@click.option('--platform', default=None, type=str, nargs=1, + help=('only download wheels compatible with .' + 'defaults to the platform of the running system.')) +@click.option('--python-version', default=None, type=str, nargs=1, + help=("Only download wheels compatible with Python " + "interpreter version . If not specified, then " + "the current system interpreter minor version is used. " + "A major version (e.g. '2') can be specified to match " + "all minor revs of that major version.\n" + "A minor version (e.g. '34') can also be specified.")) +@click.option('--implementation', default=None, type=str, nargs=1, + help=("Only download wheels compatible with Python " + "implementation , e.g. " + "'pp', 'jy', 'cp', or 'ip'. If not specified, then the " + "current interpreter implementation is used. " + "Use 'py' to force implementation-agnostic wheels.")) +@click.option('--abi', default=None, type=str, nargs=1, + help=("Only download wheels compatible with Python abi , " + "e.g. 'pypy_41'. If not specified, then the current " + "interpreter abi tag is used. Generally you will need " + "to specify --implementation, --platform, and " + "--python-version when using this option.")) @click.argument('src_files', nargs=-1, type=click.Path(exists=True, allow_dash=True)) def cli(verbose, dry_run, pre, rebuild, find_links, index_url, extra_index_url, client_cert, trusted_host, header, index, emit_trusted_host, annotate, upgrade, upgrade_packages, output_file, allow_unsafe, generate_hashes, - src_files, max_rounds): + src_files, max_rounds, platform, python_version, implementation, abi): """Compiles requirements.txt from requirements.in specs.""" log.verbose = verbose @@ -120,6 +143,14 @@ def cli(verbose, dry_run, pre, rebuild, find_links, index_url, extra_index_url, if trusted_host: for host in trusted_host: pip_args.extend(['--trusted-host', host]) + if platform: + pip_args.extend(['--platform', platform]) + if python_version: + pip_args.extend(['--python-version', python_version]) + if implementation: + pip_args.extend(['--implementation', implementation]) + if abi: + pip_args.extend(['--abi', abi]) pip_options, _ = pip_command.parse_args(pip_args) @@ -242,16 +273,7 @@ def cli(verbose, dry_run, pre, rebuild, find_links, index_url, extra_index_url, log.warning('Dry-run, so nothing updated.') -def get_pip_command(): - # Use pip's parser for pip.conf management and defaults. - # General options (find_links, index_url, extra_index_url, trusted_host, - # and pre) are defered to pip. - pip_command = PipCommand() - index_opts = pip.cmdoptions.make_option_group( - pip.cmdoptions.index_group, - pip_command.parser, - ) - pip_command.parser.insert_option_group(0, index_opts) - pip_command.parser.add_option(optparse.Option('--pre', action='store_true', default=False)) - - return pip_command +# Use pip's parser for pip.conf management and defaults. +# General options (find_links, index_url, extra_index_url, trusted_host, +# and pre) are defered to pip. +get_pip_command = PipCommand