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.
De : Xavier Combelle firstname.lastname@example.org Envoyé : samedi 6 juillet 2019 11:34 À : Sylvain MARIE email@example.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 firstname.lastname@example.org<mailto:email@example.com> 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:
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.git...
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.
Python-ideas mailing list -- firstname.lastname@example.org:email@example.com To unsubscribe send an email to firstname.lastname@example.org:email@example.com https://mail.python.org/mailman3/lists/python-ideas.python.org/https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fmail.pytho... Message archived at https://firstname.lastname@example.org/message/OEXCPM...https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fmail.pytho... Code of Conduct: http://python.org/psf/codeofconduct/https://eur02.safelinks.protection.outlook.com/?url=http%3A%2F%2Fpython.org%...
This email has been scanned by the Symantec Email Security.cloud service.