From d7b1c27f643279e64bb0b0221dc678804561f8b2 Mon Sep 17 00:00:00 2001 From: Cristiano Salerno <119511125+csalerno-asml@users.noreply.github.com> Date: Fri, 3 Nov 2023 16:30:51 +0000 Subject: [PATCH 1/6] Fix --- piptools/scripts/compile.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/piptools/scripts/compile.py b/piptools/scripts/compile.py index 37bf042b..7f50c421 100755 --- a/piptools/scripts/compile.py +++ b/piptools/scripts/compile.py @@ -171,6 +171,10 @@ def cli( ctx.color = color log.verbosity = verbose - quiet + # src-files provided in a config file + if ctx.default_map and "src_files" in ctx.default_map: + src_files = ctx.default_map["src_files"] + if all_build_deps and build_deps_targets: raise click.BadParameter( "--build-deps-for has no effect when used with --all-build-deps" From 545c643fa73871afb0174695b2e152706651d4e7 Mon Sep 17 00:00:00 2001 From: Cristiano Salerno <119511125+csalerno-asml@users.noreply.github.com> Date: Tue, 7 Nov 2023 15:12:19 +0000 Subject: [PATCH 2/6] changed logic to skip this step if `src-files` --- piptools/scripts/compile.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/piptools/scripts/compile.py b/piptools/scripts/compile.py index 7f50c421..9868c98d 100755 --- a/piptools/scripts/compile.py +++ b/piptools/scripts/compile.py @@ -171,8 +171,10 @@ def cli( ctx.color = color log.verbosity = verbose - quiet - # src-files provided in a config file - if ctx.default_map and "src_files" in ctx.default_map: + # If `src-files` was not provided as input, but rather as config, + # it will be part of the click Context `ctx`. + # However, is `src_files` is specified, then we want to use that. + if not src_files and ctx.default_map and "src_files" in ctx.default_map: src_files = ctx.default_map["src_files"] if all_build_deps and build_deps_targets: From 7d1393dd26cbcf18fb226c1ac8dc72fc42522b48 Mon Sep 17 00:00:00 2001 From: Cristiano Salerno <119511125+csalerno-asml@users.noreply.github.com> Date: Tue, 7 Nov 2023 15:12:34 +0000 Subject: [PATCH 3/6] add two tests --- src/pip-tools | 1 + tests/test_cli_compile.py | 41 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 160000 src/pip-tools diff --git a/src/pip-tools b/src/pip-tools new file mode 160000 index 00000000..f97e62ec --- /dev/null +++ b/src/pip-tools @@ -0,0 +1 @@ +Subproject commit f97e62ecb0d9b70965c8eff952c001d8e2722e94 diff --git a/tests/test_cli_compile.py b/tests/test_cli_compile.py index 3341f751..6c6288d0 100644 --- a/tests/test_cli_compile.py +++ b/tests/test_cli_compile.py @@ -3447,6 +3447,47 @@ def test_allow_in_config_pip_sync_option(pip_conf, runner, tmp_path, make_config assert "Using pip-tools configuration defaults found" in out.stderr +def test_use_src_files_from_config_if_option_is_not_specified_from_cli(pip_conf, runner, tmp_path, make_config_file): + foo_in = tmp_path / "foo.in" + req_in = tmp_path / "requirements.in" + + config_file = make_config_file("src-files", [foo_in.as_posix()]) + + with open(req_in, "w") as f: + f.write("small-fake-a==0.1") + + with open(foo_in, "w") as f: + f.write("small-fake-b==0.1") + + out = runner.invoke( + cli, ["--config", config_file.as_posix()] + ) + + assert out.exit_code == 0 + assert "small-fake-b" in out.stderr + assert "small-fake-a" not in out.stderr + + +def test_use_src_files_from_cli_if_option_is_specified_in_both_config_and_cli(pip_conf, runner, tmp_path, make_config_file): + foo_in = tmp_path / "foo.in" + req_in = tmp_path / "requirements.in" + + config_file = make_config_file("src-files", [foo_in.as_posix()]) + + with open(req_in, "w") as f: + f.write("small-fake-a==0.1") + + with open(foo_in, "w") as f: + f.write("small-fake-b==0.1") + + out = runner.invoke( + cli, [req_in.as_posix(), "--config", config_file.as_posix()] + ) + + assert out.exit_code == 0 + assert "small-fake-a" in out.stderr + assert "small-fake-b" not in out.stderr + def test_cli_boolean_flag_config_option_has_valid_context( pip_conf, runner, tmp_path, make_config_file ): From f6ba1c4fae85c1e18e8068ca101820b41118c1c8 Mon Sep 17 00:00:00 2001 From: Cristiano Salerno <119511125+csalerno-asml@users.noreply.github.com> Date: Tue, 7 Nov 2023 15:17:49 +0000 Subject: [PATCH 4/6] linting --- tests/test_cli_compile.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/tests/test_cli_compile.py b/tests/test_cli_compile.py index 6c6288d0..e7bf5b59 100644 --- a/tests/test_cli_compile.py +++ b/tests/test_cli_compile.py @@ -3447,7 +3447,9 @@ def test_allow_in_config_pip_sync_option(pip_conf, runner, tmp_path, make_config assert "Using pip-tools configuration defaults found" in out.stderr -def test_use_src_files_from_config_if_option_is_not_specified_from_cli(pip_conf, runner, tmp_path, make_config_file): +def test_use_src_files_from_config_if_option_is_not_specified_from_cli( + pip_conf, runner, tmp_path, make_config_file +): foo_in = tmp_path / "foo.in" req_in = tmp_path / "requirements.in" @@ -3455,20 +3457,20 @@ def test_use_src_files_from_config_if_option_is_not_specified_from_cli(pip_conf, with open(req_in, "w") as f: f.write("small-fake-a==0.1") - + with open(foo_in, "w") as f: f.write("small-fake-b==0.1") - out = runner.invoke( - cli, ["--config", config_file.as_posix()] - ) + out = runner.invoke(cli, ["--config", config_file.as_posix()]) assert out.exit_code == 0 assert "small-fake-b" in out.stderr assert "small-fake-a" not in out.stderr -def test_use_src_files_from_cli_if_option_is_specified_in_both_config_and_cli(pip_conf, runner, tmp_path, make_config_file): +def test_use_src_files_from_cli_if_option_is_specified_in_both_config_and_cli( + pip_conf, runner, tmp_path, make_config_file +): foo_in = tmp_path / "foo.in" req_in = tmp_path / "requirements.in" @@ -3476,18 +3478,17 @@ def test_use_src_files_from_cli_if_option_is_specified_in_both_config_and_cli(pi with open(req_in, "w") as f: f.write("small-fake-a==0.1") - + with open(foo_in, "w") as f: f.write("small-fake-b==0.1") - out = runner.invoke( - cli, [req_in.as_posix(), "--config", config_file.as_posix()] - ) + out = runner.invoke(cli, [req_in.as_posix(), "--config", config_file.as_posix()]) assert out.exit_code == 0 assert "small-fake-a" in out.stderr assert "small-fake-b" not in out.stderr + def test_cli_boolean_flag_config_option_has_valid_context( pip_conf, runner, tmp_path, make_config_file ): From 64d1de3f1303995f297b17fbc10f833d82c7d6b8 Mon Sep 17 00:00:00 2001 From: Cristiano Salerno <119511125+csalerno-asml@users.noreply.github.com> Date: Thu, 9 Nov 2023 10:29:09 +0000 Subject: [PATCH 5/6] comments addressed --- piptools/scripts/compile.py | 6 +++--- tests/test_cli_compile.py | 18 ++++++------------ 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/piptools/scripts/compile.py b/piptools/scripts/compile.py index 9868c98d..5b14bc43 100755 --- a/piptools/scripts/compile.py +++ b/piptools/scripts/compile.py @@ -171,9 +171,9 @@ def cli( ctx.color = color log.verbosity = verbose - quiet - # If `src-files` was not provided as input, but rather as config, - # it will be part of the click Context `ctx`. - # However, is `src_files` is specified, then we want to use that. + # If ``src-files` was not provided as an input, but rather as config, + # it will be part of the click context ``ctx``. + # However, if ``src_files`` is specified, then we want to use that. if not src_files and ctx.default_map and "src_files" in ctx.default_map: src_files = ctx.default_map["src_files"] diff --git a/tests/test_cli_compile.py b/tests/test_cli_compile.py index e7bf5b59..f6c5be66 100644 --- a/tests/test_cli_compile.py +++ b/tests/test_cli_compile.py @@ -3455,15 +3455,12 @@ def test_use_src_files_from_config_if_option_is_not_specified_from_cli( config_file = make_config_file("src-files", [foo_in.as_posix()]) - with open(req_in, "w") as f: - f.write("small-fake-a==0.1") - - with open(foo_in, "w") as f: - f.write("small-fake-b==0.1") + req_in.write_text("small-fake-a==0.1", encoding="utf-8") + foo_in.write_text("small-fake-b==0.1", encoding="utf-8") out = runner.invoke(cli, ["--config", config_file.as_posix()]) - assert out.exit_code == 0 + assert out.exit_code == 0, out assert "small-fake-b" in out.stderr assert "small-fake-a" not in out.stderr @@ -3476,15 +3473,12 @@ def test_use_src_files_from_cli_if_option_is_specified_in_both_config_and_cli( config_file = make_config_file("src-files", [foo_in.as_posix()]) - with open(req_in, "w") as f: - f.write("small-fake-a==0.1") - - with open(foo_in, "w") as f: - f.write("small-fake-b==0.1") + req_in.write_text("small-fake-a==0.1", encoding="utf-8") + foo_in.write_text("small-fake-b==0.1", encoding="utf-8") out = runner.invoke(cli, [req_in.as_posix(), "--config", config_file.as_posix()]) - assert out.exit_code == 0 + assert out.exit_code == 0, out assert "small-fake-a" in out.stderr assert "small-fake-b" not in out.stderr From e216ad52f89f22b6b8a024c98f70109b13f89334 Mon Sep 17 00:00:00 2001 From: Cristiano Salerno <119511125+csalerno-asml@users.noreply.github.com> Date: Thu, 9 Nov 2023 10:35:02 +0000 Subject: [PATCH 6/6] rm submodule --- src/pip-tools | 1 - 1 file changed, 1 deletion(-) delete mode 160000 src/pip-tools diff --git a/src/pip-tools b/src/pip-tools deleted file mode 160000 index f97e62ec..00000000 --- a/src/pip-tools +++ /dev/null @@ -1 +0,0 @@ -Subproject commit f97e62ecb0d9b70965c8eff952c001d8e2722e94