diff --git a/CHANGELOG.md b/CHANGELOG.md index 33052b010..4a9c5f3dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ Features: - Preserve environment markers in generated requirements.txt. ([#460](https://github.com/jazzband/pip-tools/pull/460)). Thanks @barrywhart. Bug Fixes: +- Fixed the --upgrade-package option to respect the given package list to update ([#491](https://github.com/jazzband/pip-tools/pull/491)). - Fixed the default output file name when the source file has no extension ([#488](https://github.com/jazzband/pip-tools/pull/488)). Thanks @vphilippon - Fixed crash on editable requirements introduced in 1.8.2. - Fixed duplicated --trusted-host, --extra-index-url and --index-url in the generated requirements. diff --git a/piptools/scripts/compile.py b/piptools/scripts/compile.py index 850e4a503..da3ce085e 100755 --- a/piptools/scripts/compile.py +++ b/piptools/scripts/compile.py @@ -126,16 +126,15 @@ def cli(verbose, dry_run, pre, rebuild, find_links, index_url, extra_index_url, session = pip_command._build_session(pip_options) repository = PyPIRepository(pip_options, session) - # Pre-parse the inline package upgrade specs: they should take precedence - # over the stuff in the requirements files - upgrade_packages = [InstallRequirement.from_line(pkg) - for pkg in upgrade_packages] - # Proxy with a LocalRequirementsRepository if --upgrade is not specified # (= default invocation) - if not (upgrade or upgrade_packages) and os.path.exists(dst_file): + if not upgrade and os.path.exists(dst_file): ireqs = parse_requirements(dst_file, finder=repository.finder, session=repository.session, options=pip_options) - existing_pins = {key_from_req(ireq.req): ireq for ireq in ireqs if is_pinned_requirement(ireq)} + # Exclude packages from --upgrade-package/-P from the existing pins: We want to upgrade. + upgrade_pkgs_key = {key_from_req(InstallRequirement.from_line(pkg).req) for pkg in upgrade_packages} + existing_pins = {key_from_req(ireq.req): ireq + for ireq in ireqs + if is_pinned_requirement(ireq) and key_from_req(ireq.req) not in upgrade_pkgs_key} repository = LocalRequirementsRepository(existing_pins, repository) log.debug('Using indexes:') diff --git a/tests/fixtures/minimal_wheels/small_fake_a-0.1-py2.py3-none-any.whl b/tests/fixtures/minimal_wheels/small_fake_a-0.1-py2.py3-none-any.whl new file mode 100644 index 000000000..e59cae74b Binary files /dev/null and b/tests/fixtures/minimal_wheels/small_fake_a-0.1-py2.py3-none-any.whl differ diff --git a/tests/fixtures/minimal_wheels/small_fake_a-0.2-py2.py3-none-any.whl b/tests/fixtures/minimal_wheels/small_fake_a-0.2-py2.py3-none-any.whl new file mode 100644 index 000000000..33e623188 Binary files /dev/null and b/tests/fixtures/minimal_wheels/small_fake_a-0.2-py2.py3-none-any.whl differ diff --git a/tests/fixtures/minimal_wheels/small_fake_b-0.1-py2.py3-none-any.whl b/tests/fixtures/minimal_wheels/small_fake_b-0.1-py2.py3-none-any.whl new file mode 100644 index 000000000..9140599c9 Binary files /dev/null and b/tests/fixtures/minimal_wheels/small_fake_b-0.1-py2.py3-none-any.whl differ diff --git a/tests/fixtures/minimal_wheels/small_fake_b-0.2-py2.py3-none-any.whl b/tests/fixtures/minimal_wheels/small_fake_b-0.2-py2.py3-none-any.whl new file mode 100644 index 000000000..dabb5cfa9 Binary files /dev/null and b/tests/fixtures/minimal_wheels/small_fake_b-0.2-py2.py3-none-any.whl differ diff --git a/tests/test_cli.py b/tests/test_cli.py index 0976ecfda..d2ea9d699 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -237,3 +237,26 @@ def test_input_file_without_extension(tmpdir): assert out.exit_code == 0 assert '--output-file requirements.txt' in out.output assert 'six==1.10.0' in out.output + + +def test_upgrade_packages_option(tmpdir): + """ + piptools respects --upgrade-package/-P inline list. + """ + fake_package_dir = os.path.join(os.path.split(__file__)[0], 'fixtures', 'minimal_wheels') + runner = CliRunner() + with runner.isolated_filesystem(): + 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, [ + '-P', 'small_fake_b', + '-f', fake_package_dir, + ]) + + print(out.output) + assert out.exit_code == 0 + assert 'small-fake-a==0.1' in out.output + assert 'small-fake-b==0.2' in out.output