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 pkg_resources refactoring #10511

Merged
merged 12 commits into from
Nov 22, 2021
Merged

More pkg_resources refactoring #10511

merged 12 commits into from
Nov 22, 2021

Conversation

uranusjr
Copy link
Member

@uranusjr uranusjr commented Sep 28, 2021

TODO: This will need review to make sure uninstallation works for PEP 660 editables.

@uranusjr uranusjr added the skip news Does not need a NEWS file entry (eg: trivial changes) label Sep 28, 2021
@uranusjr uranusjr force-pushed the metadata-uninstall branch 4 times, most recently from 05eb831 to d90011e Compare September 28, 2021 15:47
@sbidoul
Copy link
Member

sbidoul commented Sep 28, 2021

PEP 660 editables are regular wheels so uninstallation should not have to care that they are editables.

@github-actions github-actions bot added the needs rebase or merge PR has conflicts with current master label Sep 29, 2021
@uranusjr
Copy link
Member Author

uranusjr commented Sep 29, 2021

The "problem" is old editables do need special treatments, so uninstallation code needs to distinguish whether an editable is legacy or not so PEP 660 editables don't incorrectly fall into the legacy code path :p

(More specifically, pkg_resources does not treat PEP 660 editable as "editable" at all, but our pip._internal.metadata wrapper does.)

@sbidoul
Copy link
Member

sbidoul commented Sep 29, 2021

The "problem" is old editables do need special treatments, so uninstallation code needs to distinguish whether an editable is legacy or not so PEP 660 editables don't incorrectly fall into the legacy code path :p

Sure. But do you mean we should worry about uninstallation bugs now that PEP 660 is merged, or is your concern specific to this PR ?

@uranusjr
Copy link
Member Author

Specific to this PR.

@pypa-bot pypa-bot removed the needs rebase or merge PR has conflicts with current master label Sep 29, 2021
@uranusjr uranusjr force-pushed the metadata-uninstall branch 2 times, most recently from 78e6a76 to 9d42d7b Compare September 29, 2021 21:51
@uranusjr uranusjr marked this pull request as ready for review September 29, 2021 22:10
@uranusjr
Copy link
Member Author

This is rebased against main so I think PEP 660 should be covered correctly.

@pypa-bot pypa-bot removed the needs rebase or merge PR has conflicts with current master label Nov 18, 2021
@uranusjr
Copy link
Member Author

Anyone interested in taking a look at this?

@pfmoore
Copy link
Member

pfmoore commented Nov 18, 2021

Ping me again at the weekend, and I'll try to take a look then.

@pradyunsg
Copy link
Member

I'll take a look tomorrow morning.

Comment on lines -41 to +34
paths_to_remove = [exe_name]
if WINDOWS:
paths_to_remove.append(exe_name + ".exe")
paths_to_remove.append(exe_name + ".exe.manifest")
if is_gui:
paths_to_remove.append(exe_name + "-script.pyw")
else:
paths_to_remove.append(exe_name + "-script.py")
return paths_to_remove
yield exe_name
if not WINDOWS:
return
yield f"{exe_name}.exe"
yield f"{exe_name}.exe.manifest"
if is_gui:
yield f"{exe_name}-script.pyw"
else:
yield f"{exe_name}-script.py"
Copy link
Member

Choose a reason for hiding this comment

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

Hurray!

src/pip/_internal/req/req_uninstall.py Show resolved Hide resolved
src/pip/_internal/req/req_uninstall.py Outdated Show resolved Hide resolved
if "/$platlibdir/" in platlib and hasattr(sys, "platlibdir"):
platlib = platlib.replace("/$platlibdir/", f"/{sys.platlibdir}/")
if "/$platlibdir/" in platlib:
platlib = platlib.replace("/$platlibdir/", f"/{_PLATLIBDIR}/")
Copy link
Member

Choose a reason for hiding this comment

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

This seems unrelated to the rest of the changes.

Copy link
Member

@pradyunsg pradyunsg Nov 20, 2021

Choose a reason for hiding this comment

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

Yup, but it seems like the right thing to do; and I imagine it's here because TP noticed this bug while working on this. :)

Relevant definition has a fallback to lib if sys.platlibdir isn't defined. (see line 46)

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, I wasn't suggesting it shouldn't be done. And I have no objection to it being in this PR. I was mostly flagging it in case there was a reason it needed to be here that I'd missed 😉

Copy link
Member Author

@uranusjr uranusjr Nov 20, 2021

Choose a reason for hiding this comment

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

If I remember the details correctly (it’s been a while), this was fixing a Mypy error that somehow only shows up when I was working on this. I don’t know why main isn’t complaining, maybe it’s due to me running Mypy on Windows? Not sure, and this new code is margianlly better anyway.

Note that this does not actually change any behaviour because before 3.9, the /$platlibdir/ was just /lib/, and after 3.9 _PLATLIBDIR is always sys.platlibdir. It’s just Mypy is not smart enough to figure that out.

@uranusjr
Copy link
Member Author

Any more comments on this one?

@uranusjr uranusjr merged commit e0c7f24 into pypa:main Nov 22, 2021
@uranusjr uranusjr deleted the metadata-uninstall branch November 22, 2021 01:54
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 7, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
skip news Does not need a NEWS file entry (eg: trivial changes)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants