Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
#432 Use
importlib.metadata.version
to get the version #502#432 Use
importlib.metadata.version
to get the version #502Changes from 5 commits
c933cbb
89c3232
d8e281f
3aff9fb
ff05eed
69b197a
c2a23df
2af8e80
6b85972
819d160
7f1d8ce
1f28954
770eb48
9bbcb70
85a769e
30fe7ed
6ec518d
d5e0a60
f02a26a
8050a0b
5bee9d4
783e122
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
The
str
of a module is not something you can pass toimportlib.metadata.version
because you get a repr-like string:which is probably just a small mistake here, but it reminds me that in fact
version()
does not accept an Import Package name at all, but rather a Distribution Package. They're commonly the same but not necessarily so, to use some popular examples:As an example, let's say I'm the PyYAML developer, and I'm using towncrier with a
__version__
variable viapackage = "yaml"
. If I want to drop that variable and specify my version inpyproject.toml
instead, then we can't passyaml
toimportlib.metadata.version
. We have to load a mapping from one to the other:which in the context of
get_version
would be something like:So that's how we'd make towncrier use importlib.metadata in a backwards-compatible way (user doesn't have to change their
tool.towncrier
config).It's a little unfortunate, though, that I have to do this:
The version associated with the distribution package is right there, but then I have to tell towncrier one of the import packages I have so that it can look up the name of my distribution package.
PEP 621 says that the
project.name
is required to be statically defined, which means towncrier could try to readproject.name
by default ifpackage
is not defined and--version
is not passed.Notably Poetry doesn't yet support PEP 621 but the
package
would still be there for Poetry users.Footnotes
attrs also has its newer
attrs
namespace of course :-) ↩