From 3eef588a03ad406794d7d35113f254756272aab5 Mon Sep 17 00:00:00 2001 From: Andy Freeland Date: Sat, 18 Jul 2020 15:59:28 -0700 Subject: [PATCH 1/4] Support '--use-feature' in requirements files This patch adds support for `--use-feature` in requirements files so that a project that wants all contributors using the same pip features can specify it in the requirements file. For example, to ensure a requirements file uses the new resolver: ``` --use-feature=2020-resolver boto3 boto3==1.13.13 ``` This is a new version of #8293. --- news/8601.feature | 1 + src/pip/_internal/req/req_file.py | 1 + tests/unit/test_req_file.py | 4 ++++ 3 files changed, 6 insertions(+) create mode 100644 news/8601.feature diff --git a/news/8601.feature b/news/8601.feature new file mode 100644 index 000000000..3e56c66ab --- /dev/null +++ b/news/8601.feature @@ -0,0 +1 @@ +Support ``--use-feature`` in requirements files diff --git a/src/pip/_internal/req/req_file.py b/src/pip/_internal/req/req_file.py index e120ad91b..f991cd32d 100644 --- a/src/pip/_internal/req/req_file.py +++ b/src/pip/_internal/req/req_file.py @@ -62,6 +62,7 @@ SUPPORTED_OPTIONS = [ cmdoptions.require_hashes, cmdoptions.pre, cmdoptions.trusted_host, + cmdoptions.use_new_feature, ] # type: List[Callable[..., optparse.Option]] # options to be passed to requirements diff --git a/tests/unit/test_req_file.py b/tests/unit/test_req_file.py index b22ce2013..b7c321851 100644 --- a/tests/unit/test_req_file.py +++ b/tests/unit/test_req_file.py @@ -382,6 +382,10 @@ class TestProcessLine(object): line_processor("--pre", "file", 1, finder=finder) assert finder.allow_all_prereleases + def test_use_feature(self, line_processor): + """--use-feature can be set in requirements files.""" + line_processor("--use-feature=2020-resolver", "filename", 1) + def test_relative_local_find_links( self, line_processor, finder, monkeypatch, tmpdir ): From d6b0481c8cc4ad59320e1ee1fe2981ebcae93934 Mon Sep 17 00:00:00 2001 From: Andy Freeland Date: Sun, 19 Jul 2020 02:35:50 -0700 Subject: [PATCH 2/4] Add --use-feature to pip freeze requirements parsing --- src/pip/_internal/operations/freeze.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/pip/_internal/operations/freeze.py b/src/pip/_internal/operations/freeze.py index e15f3e3da..ddb9cb232 100644 --- a/src/pip/_internal/operations/freeze.py +++ b/src/pip/_internal/operations/freeze.py @@ -100,7 +100,8 @@ def freeze( '--pre', '--trusted-host', '--process-dependency-links', - '--extra-index-url'))): + '--extra-index-url', + '--use-feature'))): line = line.rstrip() if line not in emitted_options: emitted_options.add(line) From 7a3c8026261e0a5f5c0eb8ff07005fd0605bebfa Mon Sep 17 00:00:00 2001 From: Andy Freeland Date: Sun, 19 Jul 2020 02:44:12 -0700 Subject: [PATCH 3/4] Attempt to test --use-feature in pip freeze I can't get the functional tests to run locally... --- tests/functional/test_freeze.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/functional/test_freeze.py b/tests/functional/test_freeze.py index 3792beeca..ef2216986 100644 --- a/tests/functional/test_freeze.py +++ b/tests/functional/test_freeze.py @@ -548,6 +548,7 @@ _freeze_req_opts = textwrap.dedent("""\ --extra-index-url http://ignore --find-links http://ignore --index-url http://ignore + --use-feature 2020-resolver """) From 38fe3c2f149ae7664a637dfd49ff7fac1ff12243 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Bidoul?= Date: Sat, 25 Jul 2020 11:11:36 +0200 Subject: [PATCH 4/4] Percolate --use-feature from req file upwards We explicitly propagate --use-feature options from req files upwards. This is not strictly necessary for the option to be enabled, because of the default value is a global list, but that implicit behaviour is certainly accidental, so we make it explicit, with a test. --- src/pip/_internal/req/req_file.py | 14 ++++++++++---- tests/unit/test_req_file.py | 8 ++++++-- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/pip/_internal/req/req_file.py b/src/pip/_internal/req/req_file.py index f991cd32d..105058228 100644 --- a/src/pip/_internal/req/req_file.py +++ b/src/pip/_internal/req/req_file.py @@ -225,12 +225,18 @@ def handle_option_line( ): # type: (...) -> None - # percolate hash-checking option upward - if options and opts.require_hashes: - options.require_hashes = opts.require_hashes + if options: + # percolate options upward + if opts.require_hashes: + options.require_hashes = opts.require_hashes + if opts.features_enabled: + options.features_enabled.extend( + f for f in opts.features_enabled + if f not in options.features_enabled + ) # set finder options - elif finder: + if finder: find_links = finder.find_links index_urls = finder.index_urls if opts.index_url: diff --git a/tests/unit/test_req_file.py b/tests/unit/test_req_file.py index b7c321851..879f088a4 100644 --- a/tests/unit/test_req_file.py +++ b/tests/unit/test_req_file.py @@ -47,6 +47,7 @@ def options(session): isolated_mode=False, index_url='default_url', format_control=FormatControl(set(), set()), + features_enabled=[], ) @@ -382,9 +383,12 @@ class TestProcessLine(object): line_processor("--pre", "file", 1, finder=finder) assert finder.allow_all_prereleases - def test_use_feature(self, line_processor): + def test_use_feature(self, line_processor, options): """--use-feature can be set in requirements files.""" - line_processor("--use-feature=2020-resolver", "filename", 1) + line_processor( + "--use-feature=2020-resolver", "filename", 1, options=options + ) + assert "2020-resolver" in options.features_enabled def test_relative_local_find_links( self, line_processor, finder, monkeypatch, tmpdir