From ee980b27fed86100f8e24ea900a122a561d77b01 Mon Sep 17 00:00:00 2001 From: Bart Broere Date: Wed, 21 Oct 2026 12:44:26 +0200 Subject: [PATCH] Derive the version from git with verri Use verri's strawberry flavour through hatchling's code version source, so versions look like 2026.10.21.0: the HEAD commit date plus the number of earlier commits that day. Container images build the sdist in a separate stage that has the git repository, so they get the same version instead of a +vcs.missing one. Co-Authored-By: Claude Opus 5.5 --- .containerignore | 2 -- Containerfile | 21 +++++++++++++++++---- peo/__init__.py | 4 +++- pyproject.toml | 10 +++++++--- version.py | 5 +++++ 5 files changed, 32 insertions(+), 10 deletions(-) create mode 100644 version.py diff --git a/.containerignore b/.containerignore index a5835d0..4804273 100644 --- a/.containerignore +++ b/.containerignore @@ -1,8 +1,6 @@ -.git **/__pycache__ **/*.pyc .venv -tests **/build **/dist **/*.egg-info diff --git a/Containerfile b/Containerfile index e61513b..b8458f9 100644 --- a/Containerfile +++ b/Containerfile @@ -35,6 +35,21 @@ RUN yarn install --frozen-lockfile --network-timeout 600000 RUN yarn build && test -f dist/index.html +# Builds peo's sdist from the git repository, because verri derives the version +# from the git history (see version.py). The unpacked sdist carries that version +# in PKG-INFO, so the images below can be built without git. +FROM ${SLIM_BASE_IMAGE} AS sdist + +RUN apt-get update \ + && apt-get install -y --no-install-recommends git python3-build python3-venv \ + && rm -rf /var/lib/apt/lists/* + +COPY . /src +RUN python3 -m build --sdist --outdir /dist /src \ + && mkdir /peo \ + && tar -xzf /dist/peo-*.tar.gz --strip-components=1 -C /peo + + FROM ${SLIM_BASE_IMAGE} AS slim RUN apt-get update \ @@ -45,8 +60,7 @@ RUN apt-get update \ # notices: see THIRD_PARTY_NOTICES.md. COPY container/collect-python-licenses.py /tmp/ COPY container/licenses/ /tmp/licenses/ -COPY pyproject.toml README.md LICENSE /tmp/peo/ -COPY peo /tmp/peo/peo +COPY --from=sdist /peo /tmp/peo RUN python3 -m venv --system-site-packages /opt/peo/venv \ && /opt/peo/venv/bin/pip install --no-cache-dir "/tmp/peo[browser]" \ && /opt/peo/venv/bin/python /tmp/collect-python-licenses.py \ @@ -94,8 +108,7 @@ RUN /opt/pgadmin/bin/python /tmp/collect-python-licenses.py \ /usr/share/doc/peo/pgadmin-python-licenses /tmp/licenses # peo itself, using Debian's psycopg and the other dependencies from PyPI. -COPY pyproject.toml README.md LICENSE /tmp/peo/ -COPY peo /tmp/peo/peo +COPY --from=sdist /peo /tmp/peo RUN python3 -m venv --system-site-packages /opt/peo/venv \ && /opt/peo/venv/bin/pip install --no-cache-dir "/tmp/peo[browser]" \ && /opt/peo/venv/bin/python /tmp/collect-python-licenses.py \ diff --git a/peo/__init__.py b/peo/__init__.py index e3836d6..62a0636 100644 --- a/peo/__init__.py +++ b/peo/__init__.py @@ -2,4 +2,6 @@ # SPDX-License-Identifier: GPL-3.0-or-later """peo: serves neo4j-browser and translates Bolt/Cypher to PostgreSQL + AGE.""" -__version__ = "0.1.0" +from importlib.metadata import version + +__version__ = version("peo") diff --git a/pyproject.toml b/pyproject.toml index a2501b8..5b1c488 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,7 +2,7 @@ # SPDX-License-Identifier: GPL-3.0-or-later [build-system] -requires = ["hatchling>=1.27", "hatch-fancy-pypi-readme>=24.1"] +requires = ["hatchling>=1.27", "hatch-fancy-pypi-readme>=24.1", "verri>=2026.10.11"] build-backend = "hatchling.build" [project] @@ -31,11 +31,15 @@ Source = "https://git.bartbroe.re/bartbroere/peo" [project.scripts] peo = "peo.__main__:run" +# The version is derived from the date of the HEAD commit, plus the number of +# commits made earlier that day, like 2026.10.21.0. See version.py. [tool.hatch.version] -path = "peo/__init__.py" +source = "code" +path = "version.py" +expression = "strawberry()" [tool.hatch.build.targets.sdist] -include = ["/peo", "/README.md", "/LICENSE"] +include = ["/peo", "/README.md", "/LICENSE", "/version.py"] [tool.hatch.build.targets.wheel] packages = ["peo"] diff --git a/version.py b/version.py new file mode 100644 index 0000000..e6b5ace --- /dev/null +++ b/version.py @@ -0,0 +1,5 @@ +# SPDX-FileCopyrightText: 2026 Bart Broere +# SPDX-License-Identifier: GPL-3.0-or-later +"""Build-time version source for hatchling, see [tool.hatch.version].""" + +from verri.tasty import strawberry # noqa: F401