-
Notifications
You must be signed in to change notification settings - Fork 23
Add API to retrieve project metadata from an installed package. #116
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |
| import os | ||
| import pathlib | ||
| import re | ||
| from importlib.metadata import metadata | ||
|
|
||
| from setuptools.config.setupcfg import read_configuration | ||
| from distutils.errors import DistutilsFileError | ||
|
|
@@ -47,6 +48,10 @@ def build_metadata(path, isolated=None): | |
| # metadata from PyPI, we just couldn't get the additional build data. | ||
| return {"_wheel_build_failed": True} | ||
|
|
||
| return normalize_metadata(metadata) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I'm right, this would be a bug that exists in master, but... isn't
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the call on L43 succeeds, then data metadata will be set on L51; if it fails, the return on L49 prevents L51 from being executed.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, right, sorry, I was thinking backwards. |
||
|
|
||
|
|
||
| def normalize_metadata(metadata): | ||
| # As far as I can tell, we can't trust that the builders normalize the keys, | ||
| # so we do it here. Definitely most builders do not lower case them, which | ||
| # Core Metadata Specs recommend. | ||
|
|
@@ -72,6 +77,11 @@ def build_metadata(path, isolated=None): | |
| return data | ||
|
|
||
|
|
||
| def installed_metadata(name): | ||
| """Retrieve the metadata for an package that is installed in the environment.""" | ||
| return normalize_metadata(metadata(name)) | ||
|
|
||
|
|
||
| def get_build_data(path, isolated=None): | ||
| metadata = build_metadata(path, isolated=isolated) | ||
| # Check if there is a pyproject_toml | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be worth importing this under an alias, rather than having both
metadatathe import andmetadatathe variable in the same file?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure - or we can rename some of the variables to avoid the collision.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with calling the variable just "md", that's what we use for metadata at my work anyway. :-)