From 19607b908ca8a6b908fc0ad240f1910070efdb26 Mon Sep 17 00:00:00 2001 From: Walter Gates Date: Mon, 15 Apr 2024 18:55:07 -0400 Subject: [PATCH 1/5] Allow build deps as long as at least one setup file is in sources list. Passing ``--build-deps-for`` or ``--all-build-deps`` should not emit an error as long as at least one file in the sources list is a setup file. --- piptools/scripts/compile.py | 14 +++++------ tests/test_cli_compile.py | 49 +++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 7 deletions(-) diff --git a/piptools/scripts/compile.py b/piptools/scripts/compile.py index 195faa75..313b981f 100755 --- a/piptools/scripts/compile.py +++ b/piptools/scripts/compile.py @@ -332,13 +332,6 @@ def cli( setup_file_found = False for src_file in src_files: is_setup_file = os.path.basename(src_file) in METADATA_FILENAMES - if not is_setup_file and build_deps_targets: - msg = ( - "--build-deps-for and --all-build-deps can be used only with the " - "setup.py, setup.cfg and pyproject.toml specs." - ) - raise click.BadParameter(msg) - if src_file == "-": # pip requires filenames and not files. Since we want to support # piping from stdin, we need to briefly save the input from stdin @@ -430,6 +423,13 @@ def cli( msg = "--extra has effect only with setup.py and PEP-517 input formats" raise click.BadParameter(msg) + if build_deps_targets and not setup_file_found: + msg = ( + "--build-deps-for and --all-build-deps can be used only with the " + "setup.py, setup.cfg and pyproject.toml specs." + ) + raise click.BadParameter(msg) + primary_packages = { key_from_ireq(ireq) for ireq in constraints if not ireq.constraint } diff --git a/tests/test_cli_compile.py b/tests/test_cli_compile.py index a098e045..42883c55 100644 --- a/tests/test_cli_compile.py +++ b/tests/test_cli_compile.py @@ -2964,6 +2964,55 @@ def test_build_deps_fail_without_setup_file(runner, tmpdir, option): assert exp in out.stderr +@backtracking_resolver_only +@pytest.mark.parametrize("option", ("--all-build-deps", "--build-deps-for=wheel")) +def test_build_deps_does_not_error_when_setup_included_with_multiple_source_files( + fake_dists_with_build_deps, + runner, + tmp_path, + monkeypatch, + current_resolver, + option, +): + """ + Test that passing ``--build-deps-for`` or ``--all-build-deps`` does not emit an + error as long as at least one file in the sources list is a setup file. + """ + src_pkg_path = pathlib.Path(PACKAGES_PATH) / "small_fake_with_build_deps" + # When used as argument to the runner it is not passed to pip + monkeypatch.setenv("PIP_FIND_LINKS", fake_dists_with_build_deps) + + requirements_path = pathlib.Path(tmp_path) / "requirements.in" + requirements_path.write_text("\n") + + pyproject_toml_path = pathlib.Path(tmp_path) / "pyproject.toml" + pyproject_toml_path.write_text("\n") + + with runner.isolated_filesystem(tmp_path) as tmp_pkg_path: + shutil.copytree(src_pkg_path, tmp_pkg_path, dirs_exist_ok=True) + out = runner.invoke( + cli, + [ + "--allow-unsafe", + "--output-file", + "-", + "--quiet", + "--no-emit-options", + "--no-header", + option, + os.fspath(requirements_path), + os.fspath(pyproject_toml_path) + ], + ) + + exp = ( + "--build-deps-for and --all-build-deps can be used only with the " + "setup.py, setup.cfg and pyproject.toml specs." + ) + assert exp not in out.stderr + assert out.exit_code == 0 + + def test_extras_fail_with_requirements_in(runner, tmpdir): """ Test that passing ``--extra`` with ``requirements.in`` input file fails. From 94bb2f054d0e074cbe87d6b014d2645d58573bee Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 15 Apr 2024 23:00:34 +0000 Subject: [PATCH 2/5] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/test_cli_compile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_cli_compile.py b/tests/test_cli_compile.py index 42883c55..72dadcd1 100644 --- a/tests/test_cli_compile.py +++ b/tests/test_cli_compile.py @@ -3001,7 +3001,7 @@ def test_build_deps_does_not_error_when_setup_included_with_multiple_source_file "--no-header", option, os.fspath(requirements_path), - os.fspath(pyproject_toml_path) + os.fspath(pyproject_toml_path), ], ) From 2f5e3e34513357b433e350bb8cd1ced5275a4446 Mon Sep 17 00:00:00 2001 From: Walter Gates Date: Mon, 15 Apr 2024 19:49:30 -0400 Subject: [PATCH 3/5] Add test to show that multiple setup files in source list is valid https://github.com/jazzband/pip-tools/issues/2076#issuecomment-2057957477 --- tests/test_cli_compile.py | 49 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/tests/test_cli_compile.py b/tests/test_cli_compile.py index 42883c55..e37ca8bc 100644 --- a/tests/test_cli_compile.py +++ b/tests/test_cli_compile.py @@ -3013,6 +3013,55 @@ def test_build_deps_does_not_error_when_setup_included_with_multiple_source_file assert out.exit_code == 0 +@backtracking_resolver_only +@pytest.mark.parametrize("option", ("--all-build-deps", "--build-deps-for=wheel")) +def test_build_deps_does_not_error_when_multiple_setup_included_in_source_files( + fake_dists_with_build_deps, + runner, + tmp_path, + monkeypatch, + current_resolver, + option, +): + """ + Test that passing ``--build-deps-for`` or ``--all-build-deps`` does not emit an + error as long as at least one file in the sources list is a setup file. + """ + src_pkg_path = pathlib.Path(PACKAGES_PATH) / "small_fake_with_build_deps" + # When used as argument to the runner it is not passed to pip + monkeypatch.setenv("PIP_FIND_LINKS", fake_dists_with_build_deps) + + pyproject_toml_path = pathlib.Path(tmp_path) / "pyproject.toml" + pyproject_toml_path.write_text("\n") + + pyproject_toml_2_path = pathlib.Path(tmp_path) / "pyproject.toml" + pyproject_toml_2_path.write_text("\n") + + with runner.isolated_filesystem(tmp_path) as tmp_pkg_path: + shutil.copytree(src_pkg_path, tmp_pkg_path, dirs_exist_ok=True) + out = runner.invoke( + cli, + [ + "--allow-unsafe", + "--output-file", + "-", + "--quiet", + "--no-emit-options", + "--no-header", + option, + os.fspath(pyproject_toml_path), + os.fspath(pyproject_toml_2_path) + ], + ) + + exp = ( + "--build-deps-for and --all-build-deps can be used only with the " + "setup.py, setup.cfg and pyproject.toml specs." + ) + assert exp not in out.stderr + assert out.exit_code == 0 + + def test_extras_fail_with_requirements_in(runner, tmpdir): """ Test that passing ``--extra`` with ``requirements.in`` input file fails. From 2f5d137dea04e2f4b871f18c46bf9e621cfffab5 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 15 Apr 2024 23:49:59 +0000 Subject: [PATCH 4/5] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/test_cli_compile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_cli_compile.py b/tests/test_cli_compile.py index 20accc0d..9d0545ba 100644 --- a/tests/test_cli_compile.py +++ b/tests/test_cli_compile.py @@ -3050,7 +3050,7 @@ def test_build_deps_does_not_error_when_multiple_setup_included_in_source_files( "--no-header", option, os.fspath(pyproject_toml_path), - os.fspath(pyproject_toml_2_path) + os.fspath(pyproject_toml_2_path), ], ) From f687491b630a7fd74e237a47ae113375cda12c9c Mon Sep 17 00:00:00 2001 From: Walter Gates Date: Mon, 15 Apr 2024 19:52:15 -0400 Subject: [PATCH 5/5] Updated comment --- tests/test_cli_compile.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_cli_compile.py b/tests/test_cli_compile.py index 20accc0d..a92e28f3 100644 --- a/tests/test_cli_compile.py +++ b/tests/test_cli_compile.py @@ -3025,7 +3025,7 @@ def test_build_deps_does_not_error_when_multiple_setup_included_in_source_files( ): """ Test that passing ``--build-deps-for`` or ``--all-build-deps`` does not emit an - error as long as at least one file in the sources list is a setup file. + error as long when multiple setup files are included in the source files list. """ src_pkg_path = pathlib.Path(PACKAGES_PATH) / "small_fake_with_build_deps" # When used as argument to the runner it is not passed to pip @@ -3050,7 +3050,7 @@ def test_build_deps_does_not_error_when_multiple_setup_included_in_source_files( "--no-header", option, os.fspath(pyproject_toml_path), - os.fspath(pyproject_toml_2_path) + os.fspath(pyproject_toml_2_path), ], )