You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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?
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.
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
The text was updated successfully, but these errors were encountered: