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

Field or API to report version? #567

Closed
mharbison72 opened this issue Mar 30, 2022 · 1 comment
Closed

Field or API to report version? #567

mharbison72 opened this issue Mar 30, 2022 · 1 comment
Labels

Comments

@mharbison72
Copy link

I'm trying to report the version of the keyring package from the mercurial_keyring extension to aid in debugging[1]. This is a similar request to #537, but the issue here is that when bundled with py2exe or py2app, pkg_resources.get_distribution() ignores what's bundled in the app and looks at what was installed by pip. What I think I need is the ability to import the keyring code, and either reference a field or call a function.

I've not used setuptools_scm mentioned in #537, but it looks like there's a write_to option mentioned in its readme that would generate a file with the version field. Does that work as it sounds like, or is there a better way of doing this?

[1] https://foss.heptapod.net/mercurial/mercurial_keyring/-/merge_requests/17

@jaraco
Copy link
Owner

jaraco commented Apr 3, 2022

It used to be the case that keyring and other packages would present the version as <module>.__version__, but it turns out that loading that value is sometimes problematic and provides little value over the recommended way to retrieve the version from metadata anyway, which is what I recommend. Use importlib.metadata (or its backport):

from importlib import metadata


keyring_version = metadata.version('keyring')

On Python 3.7 or earlier, you'll need the backport.

This technique will work for any package and not just keyring.

Hope that helps. Let me know if you have further questions.

@jaraco jaraco closed this as completed Apr 3, 2022
@jaraco jaraco added the question label Apr 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants