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

More refactoring of req_set #2587

Merged
merged 14 commits into from
Mar 24, 2015
Merged

More refactoring of req_set #2587

merged 14 commits into from
Mar 24, 2015

Conversation

rbtcollins
Copy link

No description provided.

@rbtcollins rbtcollins force-pushed the develop branch 4 times, most recently from f2c1fac to 6dd7605 Compare March 23, 2015 22:20
@xavfernandez
Copy link
Member

Really nice refactor :)
The only thing I dislike is the find_requirement caching on the finder. I would find it cleaner to store/save it in the req_to_install object.

req_to_install, finder)
if req_to_install.satisfied_by:
logger.info(
'Requirement already %s: %s', skip_reason,
Copy link
Member

Choose a reason for hiding this comment

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

I think the conditional logic has changed here. Previously these logging statements would only ever happen if req_to_install.editable was False and req.ignore_installed was also False, however now the logging statement will be attempted if req_to_install.editable is False only.

I think the

if req_to_install.satisfied_by:
    skip_reason = self._check_skip_installed(req_to_install, finder)
if req_to_install.satisfied_by:
    logger.info(...)

was changed to

if req_to_install.satisfied_by:
    skip_reason = self._check_skip_installed(req_to_install, finder)
    if req_to_install.satisfied_by:
        logger.info(...)

That would restore the old conditional logic. It would also fix a problem where skip_reason might be unset (If --ignore-installed is being used and the item is already installed).

Copy link
Member

Choose a reason for hiding this comment

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

Hmm, doing that here would change the logging down below though, since that needs to know if we're supposed to skip install or not to know if it needs to execute, not just execute only when we are ignoring the install.

Copy link
Member

Choose a reason for hiding this comment

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

Ok, so maybe the real answer here is to change

if req_to_install.satisfied_by:
    skip_reason = self._check_skip_installed(req_to_install, finder)
if req_to_install.satisfied_by:
    logger.info(...)
else:
    if req_to_install.link and req_to_install.link.scheme == "file"):
        path = url_to_path(req_to_install.link.url)
        logger.info(...)
    else:
        logger.info(...)

to

skip_reason = None
if req_to_install.satisfied_by:
    skip_reason = self._check_skip_installed(req_to_install, finder)

if skip_reason is not None and req_to_install.satisfied_by:
    logger.info(...)
else:
    if req_to_install.link and req_to_install.link.scheme == "file"):
        path = url_to_path(req_to_install.link.url)
        logger.info(...)
    else:
        logger.info(...)

I'd also prefer an empty line between the two if statement chains just to separate them more cleanly (as I showed in my example).

Copy link
Member

Choose a reason for hiding this comment

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

Looking further, I wonder if we really need the skip_reason variable. It appears that the only time this will actually be skipped is if the version is up to date. So we could just assume that's what it is and drop that variable all together? In that case your code as written is fine, just move the up-to-date information into the string and return a boolean from _check_skip_installed() instead. This might work better with the code down below.

I'd still like the newline though.

@dstufft
Copy link
Member

dstufft commented Mar 24, 2015

Overall I like this cleanup, but I added some comments to it.

* Move the caching of find_requirement into find_requirement.

* Move the decision to set / not-set link into InstallRequirement.
It makes no sense to say we're doing something we're not.
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.
This is now isolated enough to sanely factor out. Yay.
Still need to chat with dstufft on that.
This is a small change to make prepare_file easier to read. It is slightly
complicated by the round-about way it was being assigned in non-editable cases.
This makes the code in IsSDist a bit simpler.
We had what looked like buggy code - nothing happening when link is false - but
actually link is always true by that point.
This allows introducing detection logic for different sources of source trees.
dstufft added a commit that referenced this pull request Mar 24, 2015
More refactoring of req_set
@dstufft dstufft merged commit 610db0c into pypa:develop Mar 24, 2015
@lock lock bot added the auto-locked Outdated issues that have been locked by automation label Jun 4, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Jun 4, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
auto-locked Outdated issues that have been locked by automation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants