trezor / cython-hidapi

:snake: Python wrapper for the HIDAPI
Other
287 stars 110 forks source link

expose version of bindings as `hid.__version__` #143

Closed SomberNight closed 2 years ago

SomberNight commented 2 years ago

I believe it is good practice to expose the version of python libraries at runtime in the top-level __version__ attribute. Depending on how the package was installed, it might be possible to grab the version setup.py used during installation, using importlib, but this is not always the case.

For reference:

>>> import hid
>>> ver1 = hid.__version__
>>>
>>> from importlib.metadata import version
>>> try:
...     ver2 = version("hidapi")
... except ImportError:
...     ver2 = None
...
>>> print(f"{ver1!r}, {ver2!r}")
'0.12.0.post2', '0.12.0.post2'
prusnak commented 2 years ago

Thanks!