Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix config file discovery in src_files directories #2097

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
20 changes: 20 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,25 @@ 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
21 changes: 21 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,26 @@ 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
Loading