pypa / pyproject-hooks

A low-level library for calling build-backends in `pyproject.toml`-based project
https://pyproject-hooks.readthedocs.io/
MIT License
122 stars 49 forks source link

Improve interop with `importlib.metadata`: variation without `importlib_metadata` #199

Closed abravalheri closed 6 days ago

abravalheri commented 5 months ago

This is basically the same as https://github.com/pypa/pyproject-hooks/pull/195 but without using importlib_metadata.

Feel free to close if #195 is preferred.

This might be worthy considering:

In general, I find that the following works relatively fine:

  • using importlib_metadata.DistributionFinder, MetadataPathFinder to implement find_distrubitions, but then using importlib.metadata high-level APIs

And the following does not work:

  • using importlib.metadata.DistributionFinder, MetadataPathFinder to implement find_distrubitions, but then using importlib_metadata high-level APIs

i.e. while this approach decreases the "spooky action at distance" of a transitive dependency installing importlib_metadata, it may also be more error prone if some dependency is indeed using importlib_metadata.

Closes #192

takluyver commented 5 months ago

Thanks! Does this somehow avoid the exception you found in setuptools tests in this comment?

abravalheri commented 5 months ago

For setuptools, it should be fine https://github.com/abravalheri/setuptools/pull/14 (tests should OK, docs failing but that is unrelated).

(I went ahead and already added fixed the importlib.metadata compatibility in setuptools: https://github.com/pypa/setuptools/pull/4339)

takluyver commented 5 months ago

Aha, so this is functionally similar to the original version of #195 (before involving importlib_metadata), but setuptools has changed so that it works?

I prefer this approach. I'll give it a day or so in case anyone else wants to weigh in, but if not then I'd like to merge this and cut another release.

abravalheri commented 5 months ago

(before involving importlib_metadata), but setuptools has changed so that it works?

It is very nuanced 😅

The reason for introducing importlib_metadata was mainly motivated by https://github.com/pypa/pyproject-hooks/pull/195#discussion_r1586395214.

Trying to import importlib_metadata alone does not fix setuptools (because of the vendoring drama).

If setuptools did not have to use vendoring, then yes using importlib_metadata would be enough and no change in setuptools would be necessary. That is related to the drawbacks and considerations discussed in https://github.com/pypa/pyproject-hooks/pull/199#issue-2275281951.

ofek commented 3 months ago

What are the next steps for this to be merged?

abravalheri commented 3 weeks ago

Hi @takluyver, @jaraco (and/or any other maintainers) is this approach (or the one in https://github.com/pypa/pyproject-hooks/pull/195 which includes importlib_metadata), a direction that the project is interested in pursuing? Or is the project interested in pursuing a different approach?

jaraco commented 3 weeks ago

I unfortunately have paged out the rich context, but I agree that it sounds as if this narrow and surgical fix may be a very solid improvement. Let's go with it for now. Thanks for the diligent investigation and proposal.

nanonyme commented 1 week ago

Would it be possible to make a release with this soon? The bug this aims to fix is basically update blocker for pyproject-hooks for any distro-like entities.

icp1994 commented 1 week ago

And for any distro which has upgraded pyproject-hooks unaware of this cannot update affected packages - pex for example.

jaraco commented 1 week ago

@pradyunsg or @takluyver ^

takluyver commented 6 days ago

Sorry for the delay.

takluyver commented 6 days ago

v1.2 is tagged and on PyPI now - thanks for your patience and for the periodic reminders.