Files
2026-09-04 21:58:28 +02:00

77 lines
3.1 KiB
Python

import datetime
import pathlib
import re
import subprocess
import tomllib
class SourceConfig:
site_url = "https://interdiode.fr/"
documentation_url = "https://interdiode.fr/static/latest/index.html"
cosign_key_url = "https://interdiode.fr/static/cosign.interdiode.fr.pub"
docker_user = "nonroot"
docker_group = "nonroot"
# noinspection SpellCheckingInspection
docker_env = """ PATH=/usr/local/bin/:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/interdiode/bin \
PIP_DISABLE_PIP_VERSION_CHECK=on \
PIP_NO_CACHE_DIR=on \
PYTHONUSERBASE=/usr/local/interdiode \
PYTHONFAULTHANDLER=1 \
PYTHONHASHSEED=random \
PYTHONUNBUFFERED=1
"""
# noinspection SpellCheckingInspection
def __init__(self, docker_version: str = "debian13-dev"):
self.source_dir = pathlib.Path(__file__).parent.parent
with open(self.source_dir / "pyproject.toml", "rb") as fd:
self.raw_metadata = tomllib.load(fd)
self.docker_version = docker_version
def get_python_versions(self) -> list[str]:
"""Return the list of Python versions supported by the project."""
python_versions = []
for classifier in self.raw_metadata["project"]["classifiers"]:
if matcher := re.match(
r"Programming Language :: Python :: (\d\.\d+)", classifier
):
python_versions.append(matcher.group(1))
return python_versions
def get_project_name(self) -> str:
"""Get the name of InterDiode from the pyproject.toml file."""
return self.raw_metadata["project"]["name"]
def get_project_version(self) -> str:
"""Get the version of InterDiode from the pyproject.toml file."""
return self.raw_metadata["project"]["version"]
def get_git_project_revision(self) -> str:
"""Get the git revision of the project."""
out = subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=self.source_dir) # nosec B607
return out.decode().strip()
def get_parameters(self, python_version: str | None = None) -> dict[str, str]:
python_version = python_version or self.get_python_versions()[-1]
return {
"build_date": datetime.datetime.now(tz=datetime.UTC).isoformat(),
"build_year": str(datetime.datetime.now(tz=datetime.UTC).year),
"docker_env": self.docker_env,
"docker_user": self.docker_user,
"docker_group": self.docker_group,
"docker_version": self.docker_version,
"documentation_url": self.documentation_url,
"interdiode_url": self.site_url,
"id_configurator_version": self.get_project_version(),
"python_version": python_version,
"vcs_revision": self.get_git_project_revision(),
}
def get_project_author_and_emails(self) -> list[dict[str, str]]:
"""Get the authors of InterDiode from the pyproject.toml file."""
return self.raw_metadata["project"]["authors"]
def get_project_authors(self) -> list[str]:
"""Get the authors of InterDiode from the pyproject.toml file."""
return [author["name"] for author in self.raw_metadata["project"]["authors"]]