Skip to content
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 changelog.d/2187.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Made `pip-sync` respect `src_files` set in the config file, matching `pip-compile` -- by {user}`Sanjays2402`.
8 changes: 8 additions & 0 deletions piptools/scripts/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@


@click.command(name="pip-sync")
@click.pass_context
@options.help_option(epilog=SYNC_EPILOG)
@options.version
@options.ask
Expand All @@ -69,6 +70,7 @@
@options.config
@options.no_config
def cli(
ctx: click.Context,
ask: bool,
dry_run: bool,
force: bool,
Expand All @@ -91,6 +93,12 @@ def cli(
"""Synchronize virtual environment with requirements.txt."""
log.verbosity = verbose - quiet

# 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 = tuple(ctx.default_map["src_files"])

if not src_files:
if os.path.exists(DEFAULT_REQUIREMENTS_FILE):
src_files = (DEFAULT_REQUIREMENTS_FILE,)
Expand Down
40 changes: 40 additions & 0 deletions tests/test_cli_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,3 +488,43 @@ def test_tool_specific_config_option(run, runner, make_config_file):

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


@mock.patch("piptools.sync.run")
def test_use_src_files_from_config_if_option_is_not_specified_from_cli(
run, runner, make_config_file
):
config_file = make_config_file(
"src-files", ["requirements_lock.txt"], section="pip-tools", subsection="sync"
)

with open("requirements_lock.txt", "w") as reqs_txt:
reqs_txt.write("six==1.10.0")

out = runner.invoke(cli, ["--dry-run", "--config", config_file.as_posix()])

assert out.exit_code == 1
assert "Would install:" in out.stdout
assert "six==1.10.0" in out.stdout


@mock.patch("piptools.sync.run")
def test_use_src_files_from_cli_if_option_is_specified_in_both_config_and_cli(
run, runner, make_config_file
):
config_file = make_config_file(
"src-files", ["requirements_lock.txt"], section="pip-tools", subsection="sync"
)

with open("requirements_lock.txt", "w") as reqs_txt:
reqs_txt.write("six==1.10.0")
with open("other.txt", "w") as reqs_txt:
reqs_txt.write("small-fake-a==0.1")

out = runner.invoke(
cli, ["other.txt", "--dry-run", "--config", config_file.as_posix()]
)

assert out.exit_code == 1
assert "small-fake-a==0.1" in out.stdout
assert "six==1.10.0" not in out.stdout
Loading