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

Implement PEP 376 REQUESTED #8026

Merged
merged 6 commits into from
Jun 24, 2020
Merged

Implement PEP 376 REQUESTED #8026

merged 6 commits into from
Jun 24, 2020

Conversation

sbidoul
Copy link
Member

@sbidoul sbidoul commented Apr 12, 2020

closes #7811
closes #8242

TODO

  • integration tests

@sbidoul
Copy link
Member Author

sbidoul commented Apr 12, 2020

InstallRequirement has a is_direct flag that seems to be quite close to meaning "top level requirement".

is_direct is currently only used in the legacy resolver in relation to the upgrade strategy here:

assert self.upgrade_strategy == "only-if-needed"
return req.is_direct

What I don't understand is why is_direct is set to True also for constraints here.

Can anyone shed some light on this matter?

@sbidoul sbidoul force-pushed the requested-sbi branch 2 times, most recently from 8176019 to 8bc9185 Compare April 12, 2020 17:17
@sbidoul
Copy link
Member Author

sbidoul commented Apr 12, 2020

So I set is_direct = False for constraints, so is_direct really means top level requirement, and I return req.is_direct or req.constraint in _is_upgrade_allowed(). This should be equivalent.

@sbidoul sbidoul marked this pull request as ready for review April 12, 2020 17:25
@uranusjr
Copy link
Member

uranusjr commented Apr 12, 2020

I think the original intention of is_direct is to indicate an InstallRequirement being specified by the user. In that sense constraints should set is_direct=True because they are user-specified by definition.

These meanings don’t really matter for REQUESTED though. InstallRequirement.install() is only called if constraint is false1, so the Record the REQUESTED file block should never be reached is an InstallRequirement is a constraint. I would stick an assert at the beginning of InstallRequirement.install(), and avoid changing is_direct logic.

Note 1: The method’s only caller is install_given_reqs(), which in turn is only called only once in InstallRequirement.run(). The to_install list it receives is generated by get_installation_order() of the (legacy) resolver, which only returns an InstallRequirement is it is not a constraint.

@sbidoul
Copy link
Member Author

sbidoul commented Apr 12, 2020

@uranusjr thanks for the analysis. Actually it does matter though, because constraints are added first in the requirements set and then updated with constraint=False when a corresponding requirement to install is found. If they are marked as is_direct=True we end up generating REQUESTED for them (test_install_requested_reqs_and_constraints exercises that).

@pradyunsg
Copy link
Member

I don't see any particular reason to "rush" this for pip 20.1; so I'm gonna say this isn't gonna be on the pip 20.1 train.

@uranusjr
Copy link
Member

@sbidoul Thanks, it definitely makes much more sense to change the meaning of is_direct considering the information.

Maybe we should also take this chance to change the attribute name (maybe to something like is_user_supplied_requirement), and add a comment to explain the various caveats (what qualifies as user-supplied, contraints should set this to false, etc.)

@BrownTruck
Copy link
Contributor

Hello!

I am an automated bot and I have noticed that this pull request is not currently able to be merged. If you are able to either merge the master branch into this pull request or rebase this pull request against master then it will be eligible for code review and hopefully merging!

@BrownTruck BrownTruck added the needs rebase or merge PR has conflicts with current master label May 5, 2020
@pypa-bot pypa-bot removed the needs rebase or merge PR has conflicts with current master label May 15, 2020
@@ -310,15 +310,15 @@ def get_requirements(
parsed_req,
isolated=options.isolated_mode,
)
req_to_add.is_direct = True
req_to_add.user_supplied = False
Copy link
Member

Choose a reason for hiding this comment

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

IIUC, this is intentional, to avoid constraint = True and user_supplied = True, correct?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes that's because the (legacy) resolver sometimes flips the constraint flag to False and then we would have something that is merely a constraints that has the REQUESTED file.

@pfmoore

This comment has been minimized.

@sbidoul

This comment has been minimized.

@sbidoul
Copy link
Member Author

sbidoul commented May 15, 2020

I rebased. The new tests for REQUESTED fail with the new resolver, though. Could it be it loses the user_supplied flag on the way?

@pypa-bot

This comment has been minimized.

@pypa-bot pypa-bot added the needs rebase or merge PR has conflicts with current master label May 16, 2020
@pypa-bot pypa-bot removed the needs rebase or merge PR has conflicts with current master label May 16, 2020
@sbidoul sbidoul force-pushed the requested-sbi branch 3 times, most recently from 179d30d to 5d5fc74 Compare May 16, 2020 09:39
@sbidoul
Copy link
Member Author

sbidoul commented May 16, 2020

Now test pass with the new resolver too. This should be good to go now.

Copy link
Member

@pfmoore pfmoore left a comment

Choose a reason for hiding this comment

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

I'm still not convinced of the value of the REQUESTED file in the first place, but whatever, it's part of the PEP so that's fine.

Other than a couple of small style nits, this LGTM.

src/pip/_internal/req/req_set.py Outdated Show resolved Hide resolved
src/pip/_internal/req/req_set.py Outdated Show resolved Hide resolved
@BrownTruck
Copy link
Contributor

Hello!

I am an automated bot and I have noticed that this pull request is not currently able to be merged. If you are able to either merge the master branch into this pull request or rebase this pull request against master then it will be eligible for code review and hopefully merging!

@BrownTruck BrownTruck added the needs rebase or merge PR has conflicts with current master label May 28, 2020
@pypa-bot pypa-bot removed the needs rebase or merge PR has conflicts with current master label May 29, 2020
@sbidoul
Copy link
Member Author

sbidoul commented May 29, 2020

I rebased to handle the conflict following the parent -> template renaming.

I guess this is good to go, if still green.

@@ -278,7 +278,7 @@ def test_std_install(self, data, tmpdir):
scheme=self.scheme,
req_description=str(self.req),
)
self.assert_installed(0o644)
self.assert_installed()
Copy link
Member

Choose a reason for hiding this comment

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

Nit, I would favour reverting this since the implicit 0o644 is not obvious IMO.

Copy link
Member Author

Choose a reason for hiding this comment

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

@uranusjr I think it reads better with the default, since here (as well as in the new test added in this PR) we don't want to test permissions. Only in the specific test that checks for permission, we pass a specific expected_permissions.

Copy link
Member

Choose a reason for hiding this comment

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

I’m not following. The new implementation still implicitly checks the permission against 0o644, doesn’t it? The proposed change seems to make the fact less obviously than it was to me.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok I reverted that bit.

@pradyunsg
Copy link
Member

Thanks for doing this @sbidoul! ^>^

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

Successfully merging this pull request may close these issues.

Rename InstallRequirement is_direct to user_specified Implement PEP 376 REQUESTED
6 participants