Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

An API to get the version of anything (instance, class, function, module, package) reliably #1

Open
smarie opened this issue Nov 20, 2019 · 0 comments

Comments

@smarie
Copy link
Owner

smarie commented Nov 20, 2019

Our original need for an industrial project was to persist python objects (actually, machine learning models) with the guarantee that they could be deserialized again later. We knew that the environment would change as the libraries used in the production environment were already old at the time of development.

As libraries evolve, their object models and public APIs change (even if this is not recommended), and it is difficult to be sure that module names, class names, attribute names... will continue to be the same ones in the deserialization environment. So I wrote a json serialization library (not yet published) that actually stores the version and namespace of the class when serializing an object, in order for the deserialization code to be able to make the most informed decision. For example maybe a field did not exist in a previous version of the library and now exists, but it can safely be set with a default value. Or a field changed from a private name to a public name, the value just has to be routed.

A prerequisite for such automation was to be able to get the version of every package and module. As it turned out, this was absolutely not an easy thing to do, as PEP396 and PEP345+PEP427 only cover part of the problem. I wrote getversion as a reference implementation of what I would have loved to find in the stdlib.

Is this a potential PEP ? Well I don't know. Maybe. But at the same time since the version information can come from Source Code Management tools (git, svn, ...) we should be very caution to propose reference practices so that PEP396 __version__ is easy to create in real-world development cycles.

See also this stackoverflow post and this other one.

@smarie smarie changed the title [getversion] An API to get the version of anything reliably An API to get the version of anything (instance, class, function, module, package) reliably Sep 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant