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

Ensure */extern/__init__.py is in sync with */_vendor/vendored.txt #4320

Merged
merged 7 commits into from
Apr 25, 2024

Conversation

abravalheri
Copy link
Contributor

Sometimes I have the feeling that the vendored packages, _vendor/vendored.txt and extern/__init__.py drift apart. This is an attempt to minimise that.

Please feel free to close if you don't think this is relevant.

  • Note: I haven't run tox -e vendor in this PR.

Summary of changes

  • Added a small cog script that attempts to derive the *.extern.names from the */_vendor/vendored.txt file
  • Added support function in tools/vendored.py
  • Modified tox -e vendor to automatically run cog
  • Added tox -e check-extern.
  • Added more_itertools to pkg_resources/_vendor/vendored.txt? (maybe it was missing?)

Closes

Pull Request Checklist

'jaraco',
'importlib_resources',
'zipp',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jaraco, zipp was not in this pkg_resources/extern/__init__.py, but the vendored.txt file says:

# required for importlib_resources on older Pythons
zipp==3.7.0

Maybe that was a bug? Or is "older Pythons" here referring to Python < 3.7? In that case maybe we can remove it?

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 unsure what older Pythons means, as it's dependent on the version of importlib_resources that's resolved. I would keep a version compatible with whatever importlib_resources declares.

names = (
'packaging',
'platformdirs',
'typing_extensions',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was not listed. The vendored.txt file says the following:

# required for platformdirs on Python < 3.8
typing_extensions==4.4.0

But now we removed support to Python < 3.8, so I guess we can remove this vendored dependency?

Comment on lines +84 to +87
'importlib_resources',
'importlib_metadata',
'typing_extensions',
'zipp',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Minor change: automatic reordering, just so it matches vendored.txt.

@@ -9,5 +9,7 @@ jaraco.text==3.7.0
importlib_resources==5.10.2
# required for importlib_resources on older Pythons
zipp==3.7.0
# required for jaraco.functools
more_itertools==10.2.0
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added this here because it was listed in pkg_resources.extern.names.
The version corresponds to the version that already exists in the pkg_resources/_vendor the directory... But that is different from the version in setuptools/_vendor/vendored.txt. Maybe we should synchronise these versions so that it makes the life easier for downstream packagers "de-vendoring" setuptools?

Copy link
Member

@jaraco jaraco left a comment

Choose a reason for hiding this comment

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

Thanks for taking care of this. I've never loved the two-step manual sync aspect of the vendoring design. I've been thinking we may be able to simplify it by merely adding _vendor to sys.path (and eliminating extern altogether), but I haven't experimented with that and I'm unsure what dragons might lurk in that approach.

'jaraco',
'importlib_resources',
'zipp',
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 unsure what older Pythons means, as it's dependent on the version of importlib_resources that's resolved. I would keep a version compatible with whatever importlib_resources declares.

@jaraco jaraco changed the title Ensure */extern/__init__.py is in sync wiht */_vendor/vendored.txt Ensure */extern/__init__.py is in sync with */_vendor/vendored.txt Apr 22, 2024
@abravalheri abravalheri marked this pull request as ready for review April 22, 2024 22:32
@Avasam
Copy link
Contributor

Avasam commented Apr 25, 2024

I've been thinking we may be able to simplify it by merely adding _vendor to sys.path (and eliminating extern altogether)

@jaraco Eliminating extern in favor of importing from _vendor (or making it so import vendored_module imports _vendor.vendored_module) would also solve type imports issues (like #4242) for type-checkers.

@abravalheri
Copy link
Contributor Author

I think we can go with this one for now and any improvements can follow up. I also opened other issues for the comments we left.

I've been thinking we may be able to simplify it by merely adding _vendor to sys.path (and eliminating extern altogether), but I haven't experimented with that and I'm unsure what dragons might lurk in that approach.

Yeah, that would be good. The obvious drawback is the dependency clash if other packages installed in the same environment require conflicting versions.

A different approach (as referred by @Avasam) would be to eliminate the MetaPathFinder (and therefore the extern), but still explicitly import from setuptools._vendor. That would simply a little while avoiding the version clash. We still would have to keep the patching for absolute imports of all modules installed inside of _vendor.

@abravalheri abravalheri merged commit 0156e24 into pypa:main Apr 25, 2024
22 checks passed
@abravalheri abravalheri deleted the check-extern branch April 25, 2024 18:03
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

Successfully merging this pull request may close these issues.

3 participants