-
Notifications
You must be signed in to change notification settings - Fork 365
Scmversion #3606
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
base: main
Are you sure you want to change the base?
Scmversion #3606
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# SPDX-License-Identifier: LGPL-2.1-or-later | ||
__version__ = "25.3.post0" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# SPDX-License-Identifier: LGPL-2.1-or-later | ||
# The __version__ generation here supports the following modes | ||
# 1. The version is obtained from the environment variable MKOSI_VERSION, to trump all other e.g. for | ||
# debugging purposes | ||
# 2. By default the version is obtained von the Python distribution's metadata on installed packages, unless | ||
# a. the installed version of mkosi lacks this file | ||
# b. the path of that file is not equal to the path of this particular file | ||
# 3. If mkosi has not been installed as a Python package or the metadata pertains to a different mkosi than | ||
# is being called the version is | ||
# b. generated from the output of git describe | ||
# c. looked up in a static version file from resources | ||
# 4. If no version can be found, it is set to "0" | ||
|
||
import datetime | ||
import importlib.metadata | ||
|
||
import logging | ||
|
||
import os | ||
import subprocess | ||
from importlib.metadata import PackageNotFoundError | ||
from pathlib import Path | ||
from typing import Optional | ||
|
||
|
||
def version_from_metadata() -> Optional[str]: | ||
try: | ||
dist = importlib.metadata.distribution("mkosi") | ||
|
||
this_file = dist.locate_file("mkosi/_version.py") | ||
# If the installed version is too old, it might not have the _version.py file | ||
if not this_file.exists(): | ||
return None | ||
|
||
# If the file importlib.metadata thinks we are talking about is not this one, let's pretend we didn't | ||
# find anything at all and fall back | ||
if this_file != Path(__file__): | ||
return None | ||
|
||
return importlib.metadata.version("mkosi") | ||
except PackageNotFoundError: | ||
return None | ||
|
||
|
||
def version_from_git() -> Optional[str]: | ||
try: | ||
p = subprocess.run( | ||
["git", "describe"], | ||
cwd=Path(__file__).parent.parent, | ||
check=True, | ||
text=True, | ||
capture_output=True, | ||
) | ||
# output has form like v25.3-244-g8f491df9 when not on a tag, else just the tag | ||
tag, *rest = p.stdout.strip().split("-") | ||
tag = tag.lstrip("v") | ||
if rest: | ||
numcommits, commit = rest | ||
return f"{tag}.post1.dev{numcommits}+{commit}.d{datetime.datetime.now():%Y%m%d}" | ||
|
||
# we are exactly on a tag | ||
return tag | ||
except (subprocess.CalledProcessError, NotADirectoryError, FileNotFoundError): | ||
return None | ||
Comment on lines
+43
to
+62
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So this completely goes against the convention we adopted in systemd to have the devel version be of the next version we've developing, which is fundamentally incompatible with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To document the current state for others: We're a bit between the rock of UAPI version format spec and the hard place of Python's public version identifiers. Both are compatible as far as the set of allowed characters for Python's scheme is (mostly) subset (disregarding the local part divided by + and the epoch divided by !, but Using a version scheme anchored on the last release and counting commits since, allows to fit into both schemes, as described above, since this will hold
Unfortunately, there is no way to construct a version starting with the next release number, that compares smaller than that release under both the UAPI version spec and Python's, e.g. |
||
|
||
|
||
def version_from_static() -> Optional[str]: | ||
try: | ||
import mkosi._staticversion | ||
|
||
return mkosi._staticversion.__version__ | ||
except ImportError: | ||
return None | ||
|
||
|
||
def version_fallback() -> str: | ||
logging.warning("Unable to determine mkosi version") | ||
return "0" | ||
|
||
|
||
__version__ = ( | ||
os.getenv("MKOSI_VERSION") | ||
or version_from_metadata() | ||
or version_from_git() | ||
or version_from_static() | ||
or version_fallback() | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,26 @@ | ||
[build-system] | ||
requires = ["setuptools", "setuptools-scm"] | ||
requires = ["setuptools>=64", "setuptools-scm>=8"] | ||
build-backend = "setuptools.build_meta" | ||
|
||
[project] | ||
name = "mkosi" | ||
authors = [ | ||
{name = "mkosi contributors", email = "[email protected]"}, | ||
] | ||
version = "25.3" | ||
dynamic = ["version"] | ||
description = "Build Bespoke OS Images" | ||
readme = "README.md" | ||
requires-python = ">=3.9" | ||
license = {file = "LICENSE"} | ||
|
||
[project.optional-dependencies] | ||
bootable = [ | ||
"pefile >= 2021.9.3", | ||
"pefile >= 2021.9.3", | ||
] | ||
dev = [ | ||
"ruff", | ||
"mypy", | ||
"pyright", | ||
] | ||
|
||
[project.scripts] | ||
|
@@ -45,6 +50,9 @@ packages = [ | |
"tmpfiles.d/*", | ||
] | ||
|
||
[tool.setuptools_scm] | ||
version_scheme = "no-guess-dev" | ||
|
||
[tool.isort] | ||
profile = "black" | ||
include_trailing_comma = true | ||
|
Uh oh!
There was an error while loading. Please reload this page.