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

Always obey --upgrade-package, and allow it together with --upgrade #831

Merged
merged 2 commits into from
Jun 6, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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
59 changes: 35 additions & 24 deletions tests/test_cli_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,38 +362,65 @@ def test_input_file_without_extension(runner):
assert os.path.exists("requirements.txt")


def test_upgrade_packages_option(runner):
@pytest.mark.parametrize("existing_requirements_txt", [True, False])
def test_upgrade_packages_option(runner, existing_requirements_txt):
"""
piptools respects --upgrade-package/-P inline list.
"""
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")
if existing_requirements_txt:
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, ["-P", "small-fake-b", "-f", MINIMAL_WHEELS_PATH])

assert out.exit_code == 0
assert "small-fake-a==0.1" in out.output
if existing_requirements_txt:
assert "small-fake-a==0.1" in out.output
adamchainz marked this conversation as resolved.
Show resolved Hide resolved
assert "small-fake-b==0.3" in out.output


def test_upgrade_packages_version_option(runner):
@pytest.mark.parametrize("existing_requirements_txt", [True, False])
def test_upgrade_packages_version_option(runner, existing_requirements_txt):
"""
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")
with open("requirements.txt", "w") as req_in:
req_in.write("small-fake-a==0.1\nsmall-fake-b==0.1")
if existing_requirements_txt:
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, ["-P", "small-fake-b==0.2", "-f", MINIMAL_WHEELS_PATH])

assert out.exit_code == 0
assert "small-fake-a==0.1" in out.output
if existing_requirements_txt:
assert "small-fake-a==0.1" in out.output
adamchainz marked this conversation as resolved.
Show resolved Hide resolved
assert "small-fake-b==0.2" in out.output


@pytest.mark.parametrize("existing_requirements_txt", [True, False])
def test_upgrade_packages_version_option_and_upgrade(runner, existing_requirements_txt):
"""
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")
if existing_requirements_txt:
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
adamchainz marked this conversation as resolved.
Show resolved Hide resolved


def test_quiet_option(runner):
with open("requirements", "w"):
pass
Expand Down Expand Up @@ -554,22 +581,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