mirror of https://github.com/pypa/pip
Merge pull request #7996 from deveshks/add-prefer-binary-to-req-file
This commit is contained in:
commit
403310e9b5
|
@ -0,0 +1 @@
|
||||||
|
Allow specifying ``--prefer-binary`` option in a requirements file
|
|
@ -193,6 +193,8 @@ class BuildEnvironment(object):
|
||||||
args.extend(['--trusted-host', host])
|
args.extend(['--trusted-host', host])
|
||||||
if finder.allow_all_prereleases:
|
if finder.allow_all_prereleases:
|
||||||
args.append('--pre')
|
args.append('--pre')
|
||||||
|
if finder.prefer_binary:
|
||||||
|
args.append('--prefer-binary')
|
||||||
args.append('--')
|
args.append('--')
|
||||||
args.extend(requirements)
|
args.extend(requirements)
|
||||||
with open_spinner(message) as spinner:
|
with open_spinner(message) as spinner:
|
||||||
|
|
|
@ -693,6 +693,15 @@ class PackageFinder(object):
|
||||||
# type: () -> None
|
# type: () -> None
|
||||||
self._candidate_prefs.allow_all_prereleases = True
|
self._candidate_prefs.allow_all_prereleases = True
|
||||||
|
|
||||||
|
@property
|
||||||
|
def prefer_binary(self):
|
||||||
|
# type: () -> bool
|
||||||
|
return self._candidate_prefs.prefer_binary
|
||||||
|
|
||||||
|
def set_prefer_binary(self):
|
||||||
|
# type: () -> None
|
||||||
|
self._candidate_prefs.prefer_binary = True
|
||||||
|
|
||||||
def make_link_evaluator(self, project_name):
|
def make_link_evaluator(self, project_name):
|
||||||
# type: (str) -> LinkEvaluator
|
# type: (str) -> LinkEvaluator
|
||||||
canonical_name = canonicalize_name(project_name)
|
canonical_name = canonicalize_name(project_name)
|
||||||
|
|
|
@ -60,6 +60,7 @@ SUPPORTED_OPTIONS = [
|
||||||
cmdoptions.find_links,
|
cmdoptions.find_links,
|
||||||
cmdoptions.no_binary,
|
cmdoptions.no_binary,
|
||||||
cmdoptions.only_binary,
|
cmdoptions.only_binary,
|
||||||
|
cmdoptions.prefer_binary,
|
||||||
cmdoptions.require_hashes,
|
cmdoptions.require_hashes,
|
||||||
cmdoptions.pre,
|
cmdoptions.pre,
|
||||||
cmdoptions.trusted_host,
|
cmdoptions.trusted_host,
|
||||||
|
@ -260,6 +261,9 @@ def handle_option_line(
|
||||||
if opts.pre:
|
if opts.pre:
|
||||||
finder.set_allow_all_prereleases()
|
finder.set_allow_all_prereleases()
|
||||||
|
|
||||||
|
if opts.prefer_binary:
|
||||||
|
finder.set_prefer_binary()
|
||||||
|
|
||||||
if session:
|
if session:
|
||||||
for host in opts.trusted_hosts or []:
|
for host in opts.trusted_hosts or []:
|
||||||
source = 'line {} of {}'.format(lineno, filename)
|
source = 'line {} of {}'.format(lineno, filename)
|
||||||
|
|
|
@ -689,6 +689,30 @@ def test_download_prefer_binary_when_tarball_higher_than_wheel(script, data):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_prefer_binary_tarball_higher_than_wheel_req_file(script, data):
|
||||||
|
fake_wheel(data, 'source-0.8-py2.py3-none-any.whl')
|
||||||
|
script.scratch_path.joinpath("test-req.txt").write_text(textwrap.dedent("""
|
||||||
|
--prefer-binary
|
||||||
|
source
|
||||||
|
"""))
|
||||||
|
result = script.pip(
|
||||||
|
'download',
|
||||||
|
'-r', script.scratch_path / 'test-req.txt',
|
||||||
|
'--no-index',
|
||||||
|
'-f', data.packages,
|
||||||
|
'-d', '.'
|
||||||
|
)
|
||||||
|
|
||||||
|
assert (
|
||||||
|
Path('scratch') / 'source-0.8-py2.py3-none-any.whl'
|
||||||
|
in result.files_created
|
||||||
|
)
|
||||||
|
assert (
|
||||||
|
Path('scratch') / 'source-1.0.tar.gz'
|
||||||
|
not in result.files_created
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_download_prefer_binary_when_wheel_doesnt_satisfy_req(script, data):
|
def test_download_prefer_binary_when_wheel_doesnt_satisfy_req(script, data):
|
||||||
fake_wheel(data, 'source-0.8-py2.py3-none-any.whl')
|
fake_wheel(data, 'source-0.8-py2.py3-none-any.whl')
|
||||||
script.scratch_path.joinpath("test-req.txt").write_text(textwrap.dedent("""
|
script.scratch_path.joinpath("test-req.txt").write_text(textwrap.dedent("""
|
||||||
|
@ -713,6 +737,30 @@ def test_download_prefer_binary_when_wheel_doesnt_satisfy_req(script, data):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_prefer_binary_when_wheel_doesnt_satisfy_req_req_file(script, data):
|
||||||
|
fake_wheel(data, 'source-0.8-py2.py3-none-any.whl')
|
||||||
|
script.scratch_path.joinpath("test-req.txt").write_text(textwrap.dedent("""
|
||||||
|
--prefer-binary
|
||||||
|
source>0.9
|
||||||
|
"""))
|
||||||
|
|
||||||
|
result = script.pip(
|
||||||
|
'download',
|
||||||
|
'--no-index',
|
||||||
|
'-f', data.packages,
|
||||||
|
'-d', '.',
|
||||||
|
'-r', script.scratch_path / 'test-req.txt'
|
||||||
|
)
|
||||||
|
assert (
|
||||||
|
Path('scratch') / 'source-1.0.tar.gz'
|
||||||
|
in result.files_created
|
||||||
|
)
|
||||||
|
assert (
|
||||||
|
Path('scratch') / 'source-0.8-py2.py3-none-any.whl'
|
||||||
|
not in result.files_created
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_download_prefer_binary_when_only_tarball_exists(script, data):
|
def test_download_prefer_binary_when_only_tarball_exists(script, data):
|
||||||
result = script.pip(
|
result = script.pip(
|
||||||
'download',
|
'download',
|
||||||
|
@ -727,6 +775,24 @@ def test_download_prefer_binary_when_only_tarball_exists(script, data):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_prefer_binary_when_only_tarball_exists_req_file(script, data):
|
||||||
|
script.scratch_path.joinpath("test-req.txt").write_text(textwrap.dedent("""
|
||||||
|
--prefer-binary
|
||||||
|
source
|
||||||
|
"""))
|
||||||
|
result = script.pip(
|
||||||
|
'download',
|
||||||
|
'--no-index',
|
||||||
|
'-f', data.packages,
|
||||||
|
'-d', '.',
|
||||||
|
'-r', script.scratch_path / 'test-req.txt'
|
||||||
|
)
|
||||||
|
assert (
|
||||||
|
Path('scratch') / 'source-1.0.tar.gz'
|
||||||
|
in result.files_created
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="session")
|
@pytest.fixture(scope="session")
|
||||||
def shared_script(tmpdir_factory, script_factory):
|
def shared_script(tmpdir_factory, script_factory):
|
||||||
tmpdir = Path(str(tmpdir_factory.mktemp("download_shared_script")))
|
tmpdir = Path(str(tmpdir_factory.mktemp("download_shared_script")))
|
||||||
|
|
Loading…
Reference in New Issue