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

Clean up handling of plugin distribution metadata #1073

Merged
merged 2 commits into from Sep 22, 2022

Conversation

dairiki
Copy link
Contributor

@dairiki dairiki commented Sep 20, 2022

This fixes and cleans up work done in #1061.

The issue is how to find the distribution which provides a particular Lektor plugin.
Importlib.metadata provides the packages_distribution function which sort of does the right thing, but,
it turns out that it is not totally reliable1.

In any case, under the hood, packages_distribution just iterates over all the distributions. It’s cleaner just to
iterate the distributions to find the plugins — then we know for sure which distribution a given plugin comes from.

Issue(s) Resolved

Fixes #

Related Issues / Links

Description of Changes

  • Wrote at least one-line docstrings (for any new functions)
  • Added unit test(s) covering the changes (if testable)

Footnotes

  1. Packages_distributions (more-or-less) depends on the distribution(s) providing a top_level.txt in its .pkg-info.
    It appears that top_level.txt is not specified in any PEP and is a remnant from the days of eggs. Most distributions
    still provide them, but some do not (e.g. poetry build wheel file. not found top_level.txt python-poetry/poetry#3093.)

This fixes at least one subtle bug: Some distributions do
not include a `top_level.txt` in their `.dist-info`, however
`importlib.metadata.packages_distributions` more-or-less relies
on it to work properly.

See python-poetry/poetry#3093
and https://github.com/python/cpython/blob/6cc6b13308b3202270ea7ac0ee776762a66f6a2f/Lib/importlib/metadata/__init__.py#L1043
@dairiki dairiki marked this pull request as ready for review September 20, 2022 01:31
@dairiki dairiki merged commit c8adfea into lektor:master Sep 22, 2022
@dairiki dairiki deleted the feature.refactor-plugin-dist-metadata branch September 22, 2022 18:20
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.

None yet

1 participant