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

Introduce --add-package/-A pip-compile flag #1742

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
21 changes: 18 additions & 3 deletions piptools/scripts/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,15 @@ def _determine_linesep(
multiple=True,
help="Specify a particular package to upgrade; may be used more than once",
)
@click.option(
"-A",
"--add-package",
"add_packages",
nargs=1,
multiple=True,
help="Like --upgrade-package, but only for packages that are not already "
"in the input file; may be used more than once",
)
@click.option(
"-o",
"--output-file",
Expand Down Expand Up @@ -312,6 +321,7 @@ def cli(
annotation_style: str,
upgrade: bool,
upgrade_packages: tuple[str, ...],
add_packages: tuple[str, ...],
output_file: LazyFile | IO[Any] | None,
newline: str,
allow_unsafe: bool,
Expand Down Expand Up @@ -416,6 +426,9 @@ def cli(
upgrade_install_reqs = {
key_from_ireq(install_req): install_req for install_req in upgrade_reqs_gen
}
# Similar procedure for --add-package/-E but the key is not needed since
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-E in this comment should be -A.

# the package doesn't need to be checked against the internal list
add_reqs_list = [install_req_from_line(pkg) for pkg in add_packages]

existing_pins_to_upgrade = set()

Expand Down Expand Up @@ -517,11 +530,13 @@ def cli(
key_from_ireq(ireq) for ireq in constraints if not ireq.constraint
}

allowed_upgrades = primary_packages | existing_pins_to_upgrade
constraints.extend(
ireq for key, ireq in upgrade_install_reqs.items() if key in allowed_upgrades
allowed_upgrades = (primary_packages | existing_pins_to_upgrade).intersection(
upgrade_install_reqs
)

constraints.extend(upgrade_install_reqs[key] for key in allowed_upgrades)
constraints.extend(add_reqs_list)

constraints = [req for req in constraints if req.match_markers(extras)]
for req in constraints:
drop_extras(req)
Expand Down