Skip to content

Commit

Permalink
Merge pull request #831 from adamchainz/issues_829_830
Browse files Browse the repository at this point in the history
Always obey --upgrade-package, and allow it together with --upgrade
  • Loading branch information
atugushev committed Jun 6, 2019
2 parents 4438d98 + c1e79b6 commit 0c78c0e
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 29 deletions.
21 changes: 8 additions & 13 deletions piptools/scripts/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,6 @@ def cli(
# Close the file at the end of the context execution
ctx.call_on_close(safecall(output_file.close_intelligently))

if upgrade and upgrade_packages:
raise click.BadParameter(
"Only one of --upgrade or --upgrade-package can be provided as an argument."
)

###
# Setup
###
Expand Down Expand Up @@ -260,7 +255,12 @@ def cli(
session = pip_command._build_session(pip_options)
repository = PyPIRepository(pip_options, session, build_isolation)

upgrade_install_reqs = {}
# Parse all constraints coming from --upgrade-package/-P
upgrade_reqs_gen = (install_req_from_line(pkg) for pkg in upgrade_packages)
upgrade_install_reqs = {
key_from_req(install_req.req): install_req for install_req in upgrade_reqs_gen
}

# Proxy with a LocalRequirementsRepository if --upgrade is not specified
# (= default invocation)
if not upgrade and os.path.exists(output_file.name):
Expand All @@ -270,14 +270,9 @@ def cli(
session=repository.session,
options=pip_options,
)
# Exclude packages from --upgrade-package/-P from
# the existing pins: We want to upgrade.
upgrade_reqs_gen = (install_req_from_line(pkg) for pkg in upgrade_packages)
upgrade_install_reqs = {
key_from_req(install_req.req): install_req
for install_req in upgrade_reqs_gen
}

# Exclude packages from --upgrade-package/-P from the existing
# constraints
existing_pins = {
key_from_req(ireq.req): ireq
for ireq in ireqs
Expand Down
81 changes: 65 additions & 16 deletions tests/test_cli_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,21 @@ def test_upgrade_packages_option(runner):
assert "small-fake-b==0.3" in out.output


def test_upgrade_packages_option_no_existing_file(runner):
"""
piptools respects --upgrade-package/-P inline list when the output file
doesn't exist.
"""
with open("requirements.in", "w") as req_in:
req_in.write("small-fake-a\nsmall-fake-b")

out = runner.invoke(cli, ["-P", "small-fake-b", "-f", MINIMAL_WHEELS_PATH])

assert out.exit_code == 0
assert "small-fake-a==0.2" in out.output
assert "small-fake-b==0.3" in out.output


def test_upgrade_packages_version_option(runner):
"""
piptools respects --upgrade-package/-P inline list with specified versions.
Expand All @@ -394,6 +409,56 @@ def test_upgrade_packages_version_option(runner):
assert "small-fake-b==0.2" in out.output


def test_upgrade_packages_version_option_no_existing_file(runner):
"""
piptools respects --upgrade-package/-P inline list with specified versions.
"""
with open("requirements.in", "w") as req_in:
req_in.write("small-fake-a\nsmall-fake-b")

out = runner.invoke(cli, ["-P", "small-fake-b==0.2", "-f", MINIMAL_WHEELS_PATH])

assert out.exit_code == 0
assert "small-fake-a==0.2" in out.output
assert "small-fake-b==0.2" in out.output


def test_upgrade_packages_version_option_and_upgrade(runner):
"""
piptools respects --upgrade-package/-P inline list with specified versions
whilst also doing --upgrade.
"""
with open("requirements.in", "w") as req_in:
req_in.write("small-fake-a\nsmall-fake-b")
with open("requirements.txt", "w") as req_in:
req_in.write("small-fake-a==0.1\nsmall-fake-b==0.1")

out = runner.invoke(
cli, ["--upgrade", "-P", "small-fake-b==0.1", "-f", MINIMAL_WHEELS_PATH]
)

assert out.exit_code == 0
assert "small-fake-a==0.2" in out.output
assert "small-fake-b==0.1" in out.output


def test_upgrade_packages_version_option_and_upgrade_no_existing_file(runner):
"""
piptools respects --upgrade-package/-P inline list with specified versions
whilst also doing --upgrade and the output file doesn't exist.
"""
with open("requirements.in", "w") as req_in:
req_in.write("small-fake-a\nsmall-fake-b")

out = runner.invoke(
cli, ["--upgrade", "-P", "small-fake-b==0.1", "-f", MINIMAL_WHEELS_PATH]
)

assert out.exit_code == 0
assert "small-fake-a==0.2" in out.output
assert "small-fake-b==0.1" in out.output


def test_quiet_option(runner):
with open("requirements", "w"):
pass
Expand Down Expand Up @@ -554,22 +619,6 @@ def test_multiple_input_files_without_output_file(runner):
assert out.exit_code == 2


def test_mutually_exclusive_upgrade_options(runner):
"""
The options --upgrade and --upgrade-package should be mutual exclusive.
"""
with open("requirements.in", "w") as req_in:
req_in.write("six==1.10.0")

out = runner.invoke(cli, ["--upgrade", "--upgrade-package", "six"])

assert (
"Only one of --upgrade or --upgrade-package can be provided as an argument"
in out.output
)
assert out.exit_code == 2


@pytest.mark.parametrize(
"option, expected",
[
Expand Down

0 comments on commit 0c78c0e

Please sign in to comment.