Scmversion
This commit changes the versioning scheme of non-release versions of mkosi to align with the standard Python version scheme [1]. Unfortunately this scheme is not fully compatible with the UAPI group version format specification.
Concretely, this changes
26~devel
to
25.3.post1.dev244+g0eac3718
The used format ensures that for prereleases the following inequalities still hold
25.3 < 25.3.post1.dev244+g0eac3718 < 25.4 < 26
Usage of this new format has the following benefits:
-
It is compatible with PyPI and allows publishing mkosi there in the future
-
Since it contains the number of commits since the last tag as well as part of the commit hash in the "local part" of the version, it becomes easier for bug reporters to show the version they are on no matter how mkosi has been installed.
-
The version no longer needs to be managed manually.
The current implementation moves the version from mkosi/sandbox.py to a new file _version.py that obtains the version either via importlib metadata (in case mkosi has been installed) or by calling setuptools-scm directly, to support the bin/ shims. Since the version is no longer available in mkosi/sandbox.py, it passed as an environment variable for scripts.
[1] https://packaging.python.org/en/latest/specifications/version-specifiers/
Also, what happens when people have installed (an older version) of mkosi via pip (or their distro) but call a local mkosi clone via the bin/ wrappers?
Also, what happens when people have installed (an older version) of mkosi via pip (or their distro) but call a local mkosi clone via the bin/ wrappers?
Good catch, added a check for that.
Maybe the version fallback should happen in the bin/ scripts directly (i.e. they would set the env var) if that is the only way we encourage people to use it without installing it?
I think it's nicer to have it in the module, since it gives the power of both a proper language as well as making it unnecessery to implement this multiple times.
I've tested this with for mkosi, mkosi-addon, mkosi-initrd and mkosi-sandbox
- called as Python modules while in the repo
- via the shims while in the repo
- via the shims with a different working directory
- via the shims symlinked into
PATH - installed in a virtual environment generated with the standard library and installed via pip
- installed in a virtual environment generated with the standard library and installed via pip as an editable install
- installed in a virtual environment generated with uv and installed via uv pip
- installed in a virtual environment generated with uv and installed via uf pip as an editable install
- running the modules from an unpacked tarball
- running the shims from an unpacked tarball
- running a zipapp
All of them with a distribution mkosi installed and not installed. All output a version like 25.3.post1.dev244+g293af6b3.d20250404 except for the tarballs, which show the version from the static file.