Refactor versioning and metadata handling in the Python module
This commit is contained in:
parent
1a11569e9a
commit
4a2ee88328
|
|
@ -1,5 +1,4 @@
|
|||
__pycache__/
|
||||
.venv/
|
||||
sls/_version.py
|
||||
sls_python.egg-info/
|
||||
dist/
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@ build-backend = "sls_build_backend"
|
|||
|
||||
[project]
|
||||
name = "sls_python"
|
||||
version = "0.1.0"
|
||||
description = "Python reimplementation skeleton of the SLS C project"
|
||||
version = "0.0.1-alpha"
|
||||
description = "Python reimplementation of the SLS C project"
|
||||
authors = [ { name = "Kyler Olsen" } ]
|
||||
readme = "README.md"
|
||||
license = { text = "MIT" }
|
||||
|
|
|
|||
|
|
@ -0,0 +1,17 @@
|
|||
import subprocess
|
||||
from datetime import datetime, timezone
|
||||
__result_hash = subprocess.check_output(
|
||||
["git", "describe", "--always", "--dirty", "--abbrev=7"],
|
||||
cwd=".",
|
||||
stderr=subprocess.DEVNULL,
|
||||
text=True
|
||||
).strip()
|
||||
__result_date = subprocess.check_output(
|
||||
["git", "show", "-s", "--format=%ci"],
|
||||
cwd=".",
|
||||
stderr=subprocess.DEVNULL,
|
||||
text=True
|
||||
).strip()
|
||||
version = "unknown"
|
||||
commit = __result_hash + " " + __result_date
|
||||
timestamp = datetime.now(timezone.utc).isoformat() + "Z"
|
||||
|
|
@ -4,34 +4,15 @@
|
|||
# November 2025
|
||||
|
||||
import sys
|
||||
from datetime import datetime, timezone
|
||||
try:
|
||||
from ._version import commit, timestamp # type: ignore
|
||||
from ._version import version, commit, timestamp # type: ignore
|
||||
except ImportError:
|
||||
try:
|
||||
import subprocess
|
||||
result_hash = subprocess.check_output(
|
||||
["git", "describe", "--always", "--dirty", "--abbrev=7"],
|
||||
cwd=".",
|
||||
stderr=subprocess.DEVNULL,
|
||||
text=True
|
||||
).strip()
|
||||
result_date = subprocess.check_output(
|
||||
["git", "show", "-s", "--format=%ci"],
|
||||
cwd=".",
|
||||
stderr=subprocess.DEVNULL,
|
||||
text=True
|
||||
).strip()
|
||||
commit = f"{result_hash} {result_date}"
|
||||
timestamp = datetime.now(timezone.utc).isoformat() + "Z"
|
||||
except Exception:
|
||||
commit = "unknown"
|
||||
timestamp = "unknown"
|
||||
version = "unknown"
|
||||
commit = "unknown"
|
||||
timestamp = "unknown"
|
||||
|
||||
|
||||
# Equivalent of SLS_NAME and SLS_VER
|
||||
SLS_NAME = "SLS_PYTHON"
|
||||
SLS_VER = "a.0.0"
|
||||
|
||||
# Runtime interpreter info (Python equivalent of compiler)
|
||||
_impl = sys.implementation
|
||||
|
|
@ -39,5 +20,5 @@ INTERPRETER_NAME = _impl.name.capitalize()
|
|||
INTERPRETER_VER = _impl.version.major
|
||||
|
||||
def print_version() -> None:
|
||||
print(f"YREA SLS ({SLS_NAME}) {SLS_VER} ({commit})")
|
||||
print(f"YREA SLS ({SLS_NAME}) {version} ({commit})")
|
||||
print(f"Running on {INTERPRETER_NAME} {INTERPRETER_VER} at {timestamp}")
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
# Auto-generated during build
|
||||
version = "{version}"
|
||||
commit = "{commit}"
|
||||
timestamp = "{timestamp}"
|
||||
|
|
|
|||
|
|
@ -0,0 +1,17 @@
|
|||
import subprocess
|
||||
from datetime import datetime, timezone
|
||||
__result_hash = subprocess.check_output(
|
||||
["git", "describe", "--always", "--dirty", "--abbrev=7"],
|
||||
cwd=".",
|
||||
stderr=subprocess.DEVNULL,
|
||||
text=True
|
||||
).strip()
|
||||
__result_date = subprocess.check_output(
|
||||
["git", "show", "-s", "--format=%ci"],
|
||||
cwd=".",
|
||||
stderr=subprocess.DEVNULL,
|
||||
text=True
|
||||
).strip()
|
||||
version = "{version}"
|
||||
commit = __result_hash + " " + __result_date
|
||||
timestamp = datetime.now(timezone.utc).isoformat() + "Z"
|
||||
|
|
@ -4,6 +4,7 @@ import pathlib
|
|||
|
||||
root = pathlib.Path(__file__).resolve().parents[1]
|
||||
template = root / "sls_build_backend" / "_version.py.in"
|
||||
template_dev = root / "sls_build_backend" / "_version_dev.py.in"
|
||||
output = root / "sls" / "_version.py"
|
||||
|
||||
def get_commit():
|
||||
|
|
@ -28,15 +29,19 @@ def get_timestamp():
|
|||
return datetime.datetime.now(datetime.timezone.utc).isoformat() + "Z"
|
||||
|
||||
def clean_output():
|
||||
if output.exists():
|
||||
output.unlink()
|
||||
version = "unknown"
|
||||
|
||||
text = template_dev.read_text()
|
||||
text = text.format(version=version)
|
||||
output.write_text(text)
|
||||
|
||||
def main():
|
||||
version = "unknown"
|
||||
commit = get_commit()
|
||||
timestamp = get_timestamp()
|
||||
|
||||
text = template.read_text()
|
||||
text = text.format(commit=commit, timestamp=timestamp)
|
||||
text = text.format(version=version, commit=commit, timestamp=timestamp)
|
||||
output.write_text(text)
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
|||
Loading…
Reference in New Issue