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

cmdoptions: Check if format_control exists before accessing it #9459

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions news/9444.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Permit ``pip uninstall -r`` to accept requirements files containing ``--install-option`` or ``--global-option``.
5 changes: 3 additions & 2 deletions src/pip/_internal/cli/cmdoptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ def getname(n: str) -> Optional[Any]:
return getattr(check_options, n, None)

names = ["build_options", "global_options", "install_options"]
if any(map(getname, names)):
control = options.format_control

control = getattr(options, "format_control", None)
Copy link
Member

Choose a reason for hiding this comment

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

Why is format_control not present on the options object? Is there a way we can make it always available instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am unsure, as this approach is the one being used with the build/global/install_options

if control and any(map(getname, names)):
control.disallow_binaries()
warnings.warn(
"Disabling all use of wheels due to the use of --build-option "
Expand Down
29 changes: 29 additions & 0 deletions tests/functional/test_uninstall.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,35 @@ def test_uninstall_from_reqs_file(script, tmpdir):
)


def test_uninstall_per_setup_options(script):
"""
Check that uninstall works with per-setup options are specified
"""
pkg_name = 'pkga'
pkga_path = create_test_package_with_setup(
script,
name=pkg_name, version='1.0',
)
script.scratch_path.joinpath("test-req.txt").write_text(
textwrap.dedent(f"""
{pkg_name} --install-option="-v"
""")
)
uranusjr marked this conversation as resolved.
Show resolved Hide resolved

result = script.pip('install', pkga_path)
result2 = script.pip('uninstall', '-r', 'test-req.txt', '-y')
assert_all_changes(
result,
result2,
[
script.venv / 'build',
script.venv / 'src',
script.scratch / 'test-req.txt',
script.site_packages / 'easy-install.pth',
],
)
NoahGorny marked this conversation as resolved.
Show resolved Hide resolved


def test_uninstallpathset_no_paths(caplog):
"""
Test UninstallPathSet logs notification when there are no paths to
Expand Down