Skip to content

Commit

Permalink
Fix config file discovery in src_files directories
Browse files Browse the repository at this point in the history
  • Loading branch information
un-def committed May 31, 2024
1 parent 5330964 commit 4de6dc6
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions piptools/scripts/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ def _get_default_option(option_name: str) -> Any:
"src_files",
nargs=-1,
type=click.Path(exists=True, allow_dash=True),
is_eager=True,
)

build_isolation = click.option(
Expand Down
18 changes: 18 additions & 0 deletions tests/test_cli_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from pip._vendor.packaging.version import Version

from piptools.build import ProjectMetadata
from piptools.locations import DEFAULT_CONFIG_FILE_NAMES
from piptools.scripts.compile import cli
from piptools.utils import (
COMPILE_EXCLUDE_OPTIONS,
Expand Down Expand Up @@ -3493,6 +3494,23 @@ def test_default_config_option(pip_conf, runner, make_config_file, tmpdir_cwd):
assert "Dry-run, so nothing updated" in out.stderr


@pytest.mark.parametrize("config_file_name", DEFAULT_CONFIG_FILE_NAMES)
def test_default_config_in_requirements_dir(
pip_conf, runner, make_config_file, tmpdir_cwd, config_file_name
):
make_config_file("dry-run", True, config_file_name=f"requirements/{config_file_name}")

req_dir = tmpdir_cwd / "requirements"
req_dir.mkdir(exist_ok=True, parents=True)
req_in = req_dir / "requirements.in"
req_in.touch()

out = runner.invoke(cli, [req_in.as_posix()])

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


def test_no_config_option_overrides_config_with_defaults(
pip_conf, runner, tmp_path, make_config_file
):
Expand Down
19 changes: 19 additions & 0 deletions tests/test_cli_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import pytest
from pip._vendor.packaging.version import Version

from piptools.locations import DEFAULT_CONFIG_FILE_NAMES
from piptools.scripts import sync
from piptools.scripts.sync import cli

Expand Down Expand Up @@ -387,6 +388,24 @@ def test_default_config_option(run, runner, make_config_file, tmpdir_cwd):
assert "Would install:" in out.stdout


@pytest.mark.parametrize("config_file_name", DEFAULT_CONFIG_FILE_NAMES)
@mock.patch("piptools.sync.run")
def test_default_config_in_requirements_dir(
run, runner, make_config_file, tmpdir_cwd, config_file_name
):
make_config_file("dry-run", True, config_file_name=f"requirements/{config_file_name}")

req_dir = tmpdir_cwd / "requirements"
req_dir.mkdir(exist_ok=True, parents=True)
req_in = req_dir / "requirements.txt"
req_in.write_text("six==1.10.0")

out = runner.invoke(cli, [req_in.as_posix()])

assert out.exit_code == 1, out.stderr
assert "Would install:" in out.stdout


@mock.patch("piptools.sync.run")
def test_config_option(run, runner, make_config_file):
config_file = make_config_file("dry-run", True)
Expand Down

0 comments on commit 4de6dc6

Please sign in to comment.