Skip to content

Commit

Permalink
Fix config file search and inclusion in header
Browse files Browse the repository at this point in the history
  • Loading branch information
chrysle committed Jan 22, 2024
1 parent d673c8e commit db7b044
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions piptools/scripts/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ def _get_default_option(option_name: str) -> Any:
src_files = click.argument(
"src_files",
nargs=-1,
is_eager=True,
type=click.Path(exists=True, allow_dash=True),
)

Expand Down
2 changes: 1 addition & 1 deletion piptools/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ def select_config_file(src_files: tuple[str, ...]) -> Path | None:
# NOTE: input.
working_directory = Path.cwd()
src_files_as_paths = (
(working_directory / src_file).resolve() for src_file in src_files or (".",)
(working_directory / src_file).resolve() for src_file in src_files + (".",)
)
candidate_dirs = (src if src.is_dir() else src.parent for src in src_files_as_paths)
config_file_path = next(
Expand Down
13 changes: 13 additions & 0 deletions tests/test_cli_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -3353,6 +3353,9 @@ def test_default_config_option(pip_conf, runner, make_config_file, tmpdir_cwd):

out = runner.invoke(cli)

print(out.stdout)
print(out.stderr)

assert out.exit_code == 0
assert "Dry-run, so nothing updated" in out.stderr

Expand Down Expand Up @@ -3635,3 +3638,13 @@ def test_stdout_should_not_be_read_when_stdin_is_not_a_plain_file(
out = runner.invoke(cli, [req_in.as_posix(), "--output-file", fifo.as_posix()])

assert out.exit_code == 0, out


def test_config_option_not_unnecessarily_added_in_output_header(runner, tmpdir_cwd):
req_in = tmpdir_cwd / "requirements.in"
req_in.touch()

out = runner.invoke(cli)

assert out.exit_code == 0, out
assert "--config" not in out.stderr
11 changes: 11 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -808,3 +808,14 @@ def test_select_config_file_prefers_pip_tools_toml_over_pyproject_toml(tmpdir_cw
)

assert select_config_file(()) == pip_tools_file


def test_select_config_file_with_config_file_in_different_directory(tmpdir_cwd, make_config_file):
config_file = make_config_file("dry-run", True, ".pip-tools.toml")

(tmpdir_cwd / "subdir").mkdir()

requirement_file = Path("subdir/requirements.in")
requirement_file.touch()

assert select_config_file((requirement_file.as_posix(),)) == config_file

0 comments on commit db7b044

Please sign in to comment.