Skip to content

Commit

Permalink
Fix the --update-package option (#491)
Browse files Browse the repository at this point in the history
* Respect the --upgrade-packages list if given.
  • Loading branch information
vphilippon authored and davidovich committed Apr 11, 2017
1 parent 0588ae5 commit 1bac560
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
13 changes: 6 additions & 7 deletions piptools/scripts/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:')
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
23 changes: 23 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 1bac560

Please sign in to comment.