We had several overly-scope variables in prepare_files which weren't needed.
install is fully modelled by satisfied_by, if we move some logic into the right
guarded conditions, which this does.
not_found was already obsolete.
best_installed really only needed to exist and be checked within the
index-consulting upgrade block.
We had this structure widely spread out:
unpack = True
if link:
if thing:
raise
else:
stuff
else:
unpack = False
if unpack:
stuff2
First transform was:
if link:
if thing:
raise
stuff
unpack = True
else:
unpack = False
if unpack:
stuff2
Which made it obvious that we didn't need unpack:
if link:
if thing:
raise
stuff
stuff2
- reduce the scope for some variables
- stop accessing private member of req_to_install
the cleanup code is idempotent and safe to call multiple times,
so we only need to decide *if* we want to cleanup, not whether
the requirement needs it done.
To fix the code duplication we need to be able to iterate without mutating the
loop variables inside the inner code. This prepares for removing the code
duplication.
If an exact version is specified for install, and that version is
already installed, then there is no point going to pypi as no install
is needed.
Adds a test called
`test_upgrade_no_look_at_pypi_if_exact_version_installed`.
This is a rework of PR #771, because that PR is old and has merge
conflicts that were easier to fix by applying the changes manually.
Need to access the extras defined on the distribution itself. This way I could just check for membership in the set of extras defined, and throw an error for each, instead of stopping entirely.
use pkg_resources.Distribution.requires instead of
Requirements.requirements to have environment markers parsing for free
It also unifies a little the process for wheel and non-wheel installs
closes#2174
"Downloading/unpacking" was misleading and confusing, especially when
the package is never found, as nothing was ever downloaded or unpacked
in this case.
The word "collecting" seems general enough to be accurate and it goes
well with the fact that later on pip will say, "Installing collected
packages".
Fixes: GH-376