eclipse / paho.mqtt.python

paho.mqtt.python
Other
2.12k stars 722 forks source link

Adding __version__ so it can be queried #818

Closed mmattel closed 4 months ago

mmattel commented 4 months ago

Feature Description

It would be great to add a __version__ attribute based on semver which can be queried in the code like:

import paho.mqtt.client as mqtt
print(mqtt.__version__)

Note: The __version__ attribute is recommended by Python Enhancement Proposals (PEP) and is commonly implemented across many packages.

Additional Information

This would definitely help when upgrading the package when there are breaking changes as one could query the min/max version in the code and behave accordingly.

PierreF commented 4 months ago

Which PEP recommend this, I don't find it ? My search of PEP say that we should REMOVE the existing __version__: https://peps.python.org/pep-0396/#pep-rejection

This PEP say that we should do:

importlib.metadata.version("paho-mqtt")
mmattel commented 4 months ago

I am in sorry, you are right, I misunderstood it... 🤦‍♂️

>>> from importlib.metadata import distribution
>>> dist = distribution('paho-mqtt')
>>> dist.version
'2.0.0'