From af5f9fc3fb6fb433e937faa4a33ab310ce495073 Mon Sep 17 00:00:00 2001 From: Mark Final Date: Thu, 26 Jun 2025 17:14:55 +0100 Subject: [PATCH 1/2] Support --use-pep517 and --no-use-pep517 inside requirements files. --- news/6438.feature.rst | 2 ++ src/pip/_internal/req/req_file.py | 4 ++++ tests/unit/test_req_file.py | 27 +++++++++++++++++++++++++++ 3 files changed, 33 insertions(+) create mode 100644 news/6438.feature.rst diff --git a/news/6438.feature.rst b/news/6438.feature.rst new file mode 100644 index 00000000000..dcc260cacd4 --- /dev/null +++ b/news/6438.feature.rst @@ -0,0 +1,2 @@ +Support using ``--use-pep517`` and ``--no-use-pep517`` inside requirements +files for all packages installed. diff --git a/src/pip/_internal/req/req_file.py b/src/pip/_internal/req/req_file.py index 0aad0a36602..99fb8194c20 100644 --- a/src/pip/_internal/req/req_file.py +++ b/src/pip/_internal/req/req_file.py @@ -53,6 +53,8 @@ cmdoptions.constraints, cmdoptions.requirements, cmdoptions.editable, + cmdoptions.use_pep517, + cmdoptions.no_use_pep517, cmdoptions.find_links, cmdoptions.no_binary, cmdoptions.only_binary, @@ -239,6 +241,8 @@ def handle_option_line( options.features_enabled.extend( f for f in opts.features_enabled if f not in options.features_enabled ) + if opts.use_pep517 is not None: + options.use_pep517 = opts.use_pep517 # set finder options if finder: diff --git a/tests/unit/test_req_file.py b/tests/unit/test_req_file.py index 248171c7b5c..3632926f7c5 100644 --- a/tests/unit/test_req_file.py +++ b/tests/unit/test_req_file.py @@ -53,6 +53,7 @@ def options(session: PipSession) -> mock.Mock: index_url="default_url", format_control=FormatControl(set(), set()), features_enabled=[], + use_pep517=None, ) @@ -675,6 +676,32 @@ def get_file_content( assert result[0].name == req_name assert not result[0].constraint + @pytest.mark.parametrize('use_pep517_cmd_line, line, expected', [ + # Test passing use_pep517=None. + (None, '', None), + (None, '--use-pep517', True), + (None, '--no-use-pep517', False), + # Test passing use_pep517=True. + (True, '', True), + (True, '--use-pep517', True), + (True, '--no-use-pep517', False), + # Test passing use_pep517=False. + (False, '', False), + (False, '--use-pep517', True), + (False, '--no-use-pep517', False), + ]) + def test_set_pep517_option_in_req_file( + self, use_pep517_cmd_line, line, expected, line_processor: LineProcessor, options: mock.Mock + ) -> None: + """ + Test that using --use-pep517 or --no-use-pep517 in a requirements file is both accepted + and overrides the command line choices for that pep. + """ + filename = "filename" + options.use_pep517 = use_pep517_cmd_line + line_processor(line, filename, 1, options=options) + assert options.use_pep517 == expected + class TestBreakOptionsArgs: def test_no_args(self) -> None: From b05e7099729940c598de30b3ba7cb30cae29081d Mon Sep 17 00:00:00 2001 From: Mark Final Date: Wed, 17 Sep 2025 19:47:23 +0100 Subject: [PATCH 2/2] Fixing black formatting and mypy missing annotations --- tests/unit/test_req_file.py | 42 ++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/tests/unit/test_req_file.py b/tests/unit/test_req_file.py index 3632926f7c5..a2f9bb0b611 100644 --- a/tests/unit/test_req_file.py +++ b/tests/unit/test_req_file.py @@ -676,26 +676,34 @@ def get_file_content( assert result[0].name == req_name assert not result[0].constraint - @pytest.mark.parametrize('use_pep517_cmd_line, line, expected', [ - # Test passing use_pep517=None. - (None, '', None), - (None, '--use-pep517', True), - (None, '--no-use-pep517', False), - # Test passing use_pep517=True. - (True, '', True), - (True, '--use-pep517', True), - (True, '--no-use-pep517', False), - # Test passing use_pep517=False. - (False, '', False), - (False, '--use-pep517', True), - (False, '--no-use-pep517', False), - ]) + @pytest.mark.parametrize( + "use_pep517_cmd_line, line, expected", + [ + # Test passing use_pep517=None. + (None, "", None), + (None, "--use-pep517", True), + (None, "--no-use-pep517", False), + # Test passing use_pep517=True. + (True, "", True), + (True, "--use-pep517", True), + (True, "--no-use-pep517", False), + # Test passing use_pep517=False. + (False, "", False), + (False, "--use-pep517", True), + (False, "--no-use-pep517", False), + ], + ) def test_set_pep517_option_in_req_file( - self, use_pep517_cmd_line, line, expected, line_processor: LineProcessor, options: mock.Mock + self, + use_pep517_cmd_line: bool | None, + line: str, + expected: bool | None, + line_processor: LineProcessor, + options: mock.Mock, ) -> None: """ - Test that using --use-pep517 or --no-use-pep517 in a requirements file is both accepted - and overrides the command line choices for that pep. + Test that using --use-pep517 or --no-use-pep517 in a requirements file + is both accepted and overrides the command line choices for that pep. """ filename = "filename" options.use_pep517 = use_pep517_cmd_line