Thanks for the feedback Xavier

Indeed, this “last resort” strategy only works if your project source is a git 
repository. I rely on the excellent setuptools_scm to handle that special case. 
By the way if someone knows an equivalent for other popular scm systems, please 
let me know (or better suggest it here: 
https://github.com/smarie/python-getversion/issues )

I forgot to add something in my previous email: the original reason for 
developing this library was to provide a version-aware persistency layer based 
on json. Basically when you deserialize an object, your code would receive the 
associated version, which allows for legacy-aware deserialization (typically 
storing a machine learning model for 6 months and needing to upgrade your code 
while still being able to deserialize it).

I guess that this use case could also apply to pickle – from what I remember, 
pickle does not like it too much when the object to deserialize does not 
correspond to the same versions of the classes used.

Best

Sylvain

De : Xavier Combelle <xavier.combe...@gmail.com>
Envoyé : samedi 6 juillet 2019 11:34
À : Sylvain MARIE <sylvain.ma...@se.com>
Objet : Re: [Python-ideas] Getting the version number for a package or module, 
reliably


[External email: Use caution with links and attachments]

________________________________


I'm certainly wrong, but version of a development version of a typical library 
is probably not reliable, as typically the version number is bumped when a new 
version is shipped so the code can be very different of the version given.

Le sam. 6 juil. 2019 11:13, Sylvain MARIE via Python-ideas 
<python-ideas@python.org<mailto:python-ideas@python.org>> a écrit :
Dear python enthusiasts,

For some industrial project a few years ago we needed a reliable way to get the 
version number for a package or module.
I found out that there was actually no method working in all edge cases, 
including:


  *   Built-in modules
  *   Unzipped wheels and eggs added to the python patch
  *   Non-installed project under development with version control information 
available
  *   Packages both installed and added to the python path (typically a 
developer working on a new version)

So I created one, and finally found the time to publish it.
No rocket science here, but you may find this new package useful: 
https://smarie.github.io/python-getversion/<https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fsmarie.github.io%2Fpython-getversion%2F&data=02%7C01%7Csylvain.marie%40se.com%7C20dc338bee554edb628108d701f519e8%7C6e51e1adc54b4b39b5980ffe9ae68fef%7C0%7C1%7C636980024523465904&sdata=tw6DivTCfYf5xFmEOUCkVjSdAK9ZB%2BVjjpfHwij%2Ba8s%3D&reserved=0>

It works with any imported module for now, including submodules.
Along with the version you get details about why a given version number is 
returned (is it because of the __version__ attribute that was found, or because 
of the Version metadata in the installed package, etc.)
Also, if one edge case is missing, it is fairly easy to add it.

If I missed something in the stdlib (I acme across the importlib.metadata 
initiative but as of now it does not seem to cover all of the above cases), 
please let me know so that I can cite it in the documentation and even redirect 
to it if it happens to already cover all the cases.

Happy summer to all !
--
Sylvain
_______________________________________________
Python-ideas mailing list -- 
python-ideas@python.org<mailto:python-ideas@python.org>
To unsubscribe send an email to 
python-ideas-le...@python.org<mailto:python-ideas-le...@python.org>
https://mail.python.org/mailman3/lists/python-ideas.python.org/<https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fmail.python.org%2Fmailman3%2Flists%2Fpython-ideas.python.org%2F&data=02%7C01%7Csylvain.marie%40se.com%7C20dc338bee554edb628108d701f519e8%7C6e51e1adc54b4b39b5980ffe9ae68fef%7C0%7C1%7C636980024523465904&sdata=Qwl176QO8d1S8%2FumncRb7YA9Nvo0G5eASUvYyYxvZhs%3D&reserved=0>
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/OEXCPM45R2YBE5GBVRXK54CZGZFSBNDI/<https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fmail.python.org%2Farchives%2Flist%2Fpython-ideas%40python.org%2Fmessage%2FOEXCPM45R2YBE5GBVRXK54CZGZFSBNDI%2F&data=02%7C01%7Csylvain.marie%40se.com%7C20dc338bee554edb628108d701f519e8%7C6e51e1adc54b4b39b5980ffe9ae68fef%7C0%7C1%7C636980024523475900&sdata=YyOpqRKVEIlHkxU73p%2B6eTRm0mOW%2Fssll%2B963z8GowU%3D&reserved=0>
Code of Conduct: 
http://python.org/psf/codeofconduct/<https://eur02.safelinks.protection.outlook.com/?url=http%3A%2F%2Fpython.org%2Fpsf%2Fcodeofconduct%2F&data=02%7C01%7Csylvain.marie%40se.com%7C20dc338bee554edb628108d701f519e8%7C6e51e1adc54b4b39b5980ffe9ae68fef%7C0%7C1%7C636980024523475900&sdata=FAeFYR6fjm%2FWGWnowP7boQC7kSgjXJVqRGoaEhdYk40%3D&reserved=0>

______________________________________________________________________
This email has been scanned by the Symantec Email Security.cloud service.
______________________________________________________________________
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/EO5YQH4JOSPQHTNYEZEUC6WLG44H7TJ2/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to