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

Disallow using both the --ignore-installed and --force-reinstall options at the same time #9317

Open
mattficke opened this issue Dec 18, 2020 · 0 comments

Comments

@mattficke
Copy link

What's the problem this feature will solve?

When running pip install with both the --ignore-installed and --force-reinstall flags, --force-reinstall is effectively disabled by --ignore-installed. It's not entirely intuitive that these options are in conflict and that ignore-installed has priority.

Here's my understanding of what happens. The force-reinstall option only takes effect if the package being installed is returned by the get_dist_to_uninstall function:

# Check if there is already an installation under the same name,
# and set a flag for later stages to uninstall it, if needed.
installed_dist = self.factory.get_dist_to_uninstall(candidate)
if installed_dist is None:
# There is no existing installation -- nothing to uninstall.
ireq.should_reinstall = False
elif self.factory.force_reinstall:
# The --force-reinstall flag is set -- reinstall.
ireq.should_reinstall = True

get_dist_to_uninstall checks the _installed_dists dict to see if the package is already installed:

def get_dist_to_uninstall(self, candidate):
# type: (Candidate) -> Optional[Distribution]
# TODO: Are there more cases this needs to return True? Editable?
dist = self._installed_dists.get(candidate.name)
if dist is None: # Not installed, no uninstallation required.
return None

Before any of this happened, though, _installed_dists was set to an empty dict by the ignore-installed option:

if not ignore_installed:
self._installed_dists = {
canonicalize_name(dist.project_name): dist
for dist in get_installed_distributions(local_only=False)
}
else:
self._installed_dists = {}

This prevents force-reinstall from having any effect.

Describe the solution you'd like

This behavior seems to mean that there's never any situation in which you'd want to (or be able to) use --ignore-installed and --force-reinstall at the same time. Given this, can pip throw an error if both flags are used? Explicitly failing with instructions to choose one seems better than silently disabling force-reinstall.

Say you're trying to resolve some mysterious dependency problems. You're using the force-reinstall option, but you're still having issues, so you look at the available pip install options and see ignore-installed. You might try that too, thinking that the effect will be additive, but this silently disables force-reinstall instead, sending you on a wild goose chase.

Alternative Solutions

A warning could be printed when using both flags, instead of throwing an error. The ignore-installed help text could also be updated to inform users that it shouldn't be used with the force-reinstall option.

I think throwing an error would be better since this seems like a fundamentally invalid combination of options, but warning messages or usage instructions would be less intrusive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant