and
I think this is the key to the core of the conflict as I very much disagree with this.
Using PEP440 it is possible to generate a valid version string for every commit is a VCS (X.Y.Z.devN+gHHH is valid as is X.Y.Z.devN+dirty`) [1]. These release are not “final releases” per the terminology of the PyPA and not something we want downstream packagers to distribute (e.g. conda, linux distros, pypi, …), but they are well defined “versions” none the less[2] and quite useful.
One example of leveraging this is the nightly wheels we maintain in the scientific python space so we and our downstream packages can run CI against development versions [3]. Looking at the wheels for Matplotlib we are making good use of all of PEP440.
In the case of the nightly wheels we have gone through a build process and can generate a static version string, but for local development is orders of magnitude more pleasant to work with editable installs. With editable installs __version__ (which can be computed at runtime) will be correct, but importlib.metadata may not be. For example, with Matplotlib we now use meson for our build system (which automatically recompiles c-extensions as needed) you only have to run pip install -e . once and than any commit you change to [4] “just works” and has the correct matplotlib.__version__. However the version according to pip/importlib is what ever it happened to be when you initially ran the install [5]. This may not be a use case everyone has, but if you have it this functionality is critical!
Developers thinking that
__version__is anything more than legacy/convention and must set it whether they find it valuable or not
We also have decades of teaching our users to look at mod.__version__ to get the version of a package. Dropping the usage of __version__ [6] will require a massive reeducation campaign and code churn for (to me) nominal benefit.
The wide range of wrong ways currently used to handle the duplication.
Coming at this a different way, with my project maintainer hat on there is unavoidable duplication of the version information. The “Truth” is someplace between the VCS (tags), a static file in the source, and a social construct which is quite reasonably project dependent. That information then gets projected into __version__ (for our users to have runtime access to the version of the code they are running), into the filename of the sdist, and into dist-info. The version is then further reproduced into the binary-packaging ecosystems’ metadata (wheels, conda, debian, fedora/rhel, macports, nix, …) in what ever way that ecosystem encodes it. Each of these copies is important, each serves a different need, and each has different stakeholders/caretakers. I’m not sure they even are collapsible (for both technical and social reasons) let alone if they should all be collapsed. Once you accept you are going to have N copies, going to N-1 is not very compelling.
per Version specifiers - Python Packaging User Guide “Identifying hash information may also be included in local version labels.” ↩︎
unless there is an effort to remove dev, post, and local from the version strings that I am not aware of. ↩︎
You might say, “well, that is just a sign you need more testing”, but bugs (and intentional breaking changes) happen in all projects. For example, like @mdrissi noted I end up bisecting CPython about once a month to figure out why some downstream package broke on the main branch. ↩︎
to be pedantic, any commit after we change the build system to meson. ↩︎
my understanding is that this is still not technically possible to fix as there is a hard-coded string in
dist-info/METADATA, but I have not been fully following those discussions. If this is possible now can someone point me to it so we can fix Matplotlib. ↩︎assuming for argument we can fix the version that importlib/pip reports. ↩︎