Allow --prefer-binary option in requirements file

This commit is contained in:
Devesh Kumar Singh 2020-04-08 09:19:33 +05:30
parent 80c640b5a8
commit 0d48186d1b
4 changed files with 16 additions and 0 deletions

1
news/7693.feature Normal file
View File

@ -0,0 +1 @@
Allow specifying --prefer-binary option in a requirements file

View File

@ -193,6 +193,8 @@ class BuildEnvironment(object):
args.extend(['--trusted-host', host])
if finder.allow_all_prereleases:
args.append('--pre')
if finder.prefer_binary:
args.append('--prefer-binary')
args.append('--')
args.extend(requirements)
with open_spinner(message) as spinner:

View File

@ -693,6 +693,15 @@ class PackageFinder(object):
# type: () -> None
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):
# type: (str) -> LinkEvaluator
canonical_name = canonicalize_name(project_name)

View File

@ -60,6 +60,7 @@ SUPPORTED_OPTIONS = [
cmdoptions.find_links,
cmdoptions.no_binary,
cmdoptions.only_binary,
cmdoptions.prefer_binary,
cmdoptions.require_hashes,
cmdoptions.pre,
cmdoptions.trusted_host,
@ -260,6 +261,9 @@ def handle_option_line(
if opts.pre:
finder.set_allow_all_prereleases()
if opts.prefer_binary:
finder.set_prefer_binary()
if session:
for host in opts.trusted_hosts or []:
source = 'line {} of {}'.format(lineno, filename)