This is an automated email from the ASF dual-hosted git repository.

sbp pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tooling-atr-experiments.git

commit efa1223bc1d1ee983c2eb65ab7ee07c4511b34fa
Author: Sean B. Palmer <[email protected]>
AuthorDate: Tue Mar 4 21:19:18 2025 +0200

    Use dunamai inside containers to discover the version
---
 .dockerignore     |  1 -
 Dockerfile.alpine | 20 ++++++++------------
 Dockerfile.ubuntu | 21 +++++++++------------
 atr/server.py     |  6 +++---
 atr/version.py    | 16 +++++++++++-----
 poetry.lock       | 42 +++++++++++++++++++++---------------------
 pyproject.toml    |  2 +-
 7 files changed, 53 insertions(+), 55 deletions(-)

diff --git a/.dockerignore b/.dockerignore
index a6a542e..3cb4c14 100644
--- a/.dockerignore
+++ b/.dockerignore
@@ -5,7 +5,6 @@
 .Python
 .coverage
 .dmypy.json
-.git
 .gitignore
 .hypothesis/
 .mypy_cache/
diff --git a/Dockerfile.alpine b/Dockerfile.alpine
index 052b5fc..88b70d2 100644
--- a/Dockerfile.alpine
+++ b/Dockerfile.alpine
@@ -4,10 +4,6 @@ ARG BIND=127.0.0.1:8080
 ENV BIND=${BIND}
 ARG SCRIPTS=scripts/poetry
 ENV SCRIPTS=${SCRIPTS}
-ARG VERSION=unknown
-ENV VERSION=${VERSION}
-ARG COMMIT=unknown
-ENV COMMIT=${COMMIT}
 
 # gcompat is required for ruff to work
 # # go is required for syft
@@ -32,18 +28,18 @@ ENV PYTHONUNBUFFERED=1
 RUN pip3 install setuptools wheel pip-tools poetry
 WORKDIR /opt/atr
 COPY . /opt/atr
-RUN mkdir -p /tmp/apache-rat && \
-    cd /tmp/apache-rat && \
-    curl -L 
https://dlcdn.apache.org/creadur/apache-rat-0.16.1/apache-rat-0.16.1-bin.tar.gz 
-o apache-rat.tar.gz && \
-    tar -xzf apache-rat.tar.gz && \
-    find apache-rat-0.16.1 -type f -name "*.jar" -exec cp {} . \; && \
-    # Rename to match expected filename if needed
-    [ -f apache-rat-0.16.1.jar ] || mv $(find . -maxdepth 1 -type f -name 
"apache-rat*.jar" | head -1) apache-rat-0.16.1.jar
+RUN mkdir -p /tmp/apache-rat
+WORKDIR /tmp/apache-rat
+RUN curl -L 
https://dlcdn.apache.org/creadur/apache-rat-0.16.1/apache-rat-0.16.1-bin.tar.gz 
-o apache-rat.tar.gz
+RUN tar -xzf apache-rat.tar.gz
+RUN find apache-rat-0.16.1 -type f -name "*.jar" -exec cp {} . \;
+# Rename to match expected filename if needed
+RUN [ -f apache-rat-0.16.1.jar ] || mv $(find . -maxdepth 1 -type f -name 
"apache-rat*.jar" | head -1) apache-rat-0.16.1.jar
 RUN java -version
+WORKDIR /opt/atr
 # TODO: We should pin the syft version
 # RUN GOPATH=/usr/local go install github.com/anchore/syft/cmd/syft@latest
 RUN curl -sSfL https://raw.githubusercontent.com/anchore/syft/main/install.sh 
| sh -s -- -b /usr/local/bin
-RUN sed -i "s%ATR-VERSION%${VERSION}%" atr/templates/includes/footer.html
 RUN rm -rf .venv-*
 RUN make sync PYTHON="$(which python3)"
 EXPOSE 8080
diff --git a/Dockerfile.ubuntu b/Dockerfile.ubuntu
index c3ecd7b..3c923d9 100644
--- a/Dockerfile.ubuntu
+++ b/Dockerfile.ubuntu
@@ -5,10 +5,6 @@ ARG BIND=127.0.0.1:8080
 ENV BIND=${BIND}
 ARG SCRIPTS=scripts/poetry
 ENV SCRIPTS=${SCRIPTS}
-ARG VERSION=unknown
-ENV VERSION=${VERSION}
-ARG COMMIT=unknown
-ENV COMMIT=${COMMIT}
 
 RUN apt-get update && apt-get install -y \
     curl \
@@ -29,19 +25,20 @@ ENV PYTHONUNBUFFERED=1
 RUN rm -rf /usr/local && python3.13 -m venv /usr/local
 RUN pip3 install setuptools wheel pip-tools poetry uv
 WORKDIR /opt/atr
-RUN mkdir -p /tmp/apache-rat && \
-    cd /tmp/apache-rat && \
-    curl -L 
https://dlcdn.apache.org/creadur/apache-rat-0.16.1/apache-rat-0.16.1-bin.tar.gz 
-o apache-rat.tar.gz && \
-    tar -xzf apache-rat.tar.gz && \
-    find apache-rat-0.16.1 -type f -name "*.jar" -exec cp {} . \; && \
-    # Rename to match expected filename if needed
-    [ -f apache-rat-0.16.1.jar ] || mv $(find . -maxdepth 1 -type f -name 
"apache-rat*.jar" | head -1) apache-rat-0.16.1.jar
+COPY . /opt/atr
+RUN mkdir -p /tmp/apache-rat
+WORKDIR /tmp/apache-rat
+RUN curl -L 
https://dlcdn.apache.org/creadur/apache-rat-0.16.1/apache-rat-0.16.1-bin.tar.gz 
-o apache-rat.tar.gz
+RUN tar -xzf apache-rat.tar.gz
+RUN find apache-rat-0.16.1 -type f -name "*.jar" -exec cp {} . \;
+# Rename to match expected filename if needed
+RUN [ -f apache-rat-0.16.1.jar ] || mv $(find . -maxdepth 1 -type f -name 
"apache-rat*.jar" | head -1) apache-rat-0.16.1.jar
 RUN java -version
+WORKDIR /opt/atr
 # TODO: We should pin the syft version
 # RUN GOPATH=/usr/local go install github.com/anchore/syft/cmd/syft@latest
 RUN curl -sSfL https://raw.githubusercontent.com/anchore/syft/main/install.sh 
| sh -s -- -b /usr/local/bin
 COPY . /opt/atr
-RUN sed -i "s%ATR-VERSION%${VERSION}%" atr/templates/includes/footer.html
 RUN rm -rf .venv-*
 RUN make sync PYTHON="$(find /usr/bin -name python3.13 | head -n 1)"
 EXPOSE 8080
diff --git a/atr/server.py b/atr/server.py
index db256b2..1d47f72 100644
--- a/atr/server.py
+++ b/atr/server.py
@@ -121,13 +121,13 @@ def app_setup_context(app: QuartApp) -> None:
     @app.context_processor
     async def app_wide() -> dict[str, Any]:
         from atr.util import is_admin
-        from atr.version import __commit__, __version__
+        from atr.version import commit, version
 
         return {
             "current_user": await asfquart.session.read(),
             "is_admin": is_admin,
-            "commit": __commit__,
-            "version": __version__,
+            "commit": commit,
+            "version": version,
         }
 
 
diff --git a/atr/version.py b/atr/version.py
index c879c90..b338159 100644
--- a/atr/version.py
+++ b/atr/version.py
@@ -18,7 +18,7 @@
 import os
 
 
-def _get_development_version() -> tuple[str, str] | None:
+def get_development_version() -> tuple[str, str] | None:
     """Returns the version when within a development environment."""
 
     try:
@@ -29,7 +29,10 @@ def _get_development_version() -> tuple[str, str] | None:
         return None
 
     try:
-        version = Version.from_git()
+        from pathlib import Path
+
+        # We start in state/, so we need to go up one level
+        version = Version.from_git(path=Path(".."))
         if version.distance > 0:
             return version.serialize(format="v{base}+{distance}.{commit}", 
bump=True), version.serialize(
                 format="{commit}"
@@ -41,12 +44,15 @@ def _get_development_version() -> tuple[str, str] | None:
         return None
 
 
-def _get_version_from_env() -> tuple[str, str | None]:
+def get_version_from_env() -> tuple[str, str | None]:
     """Returns the version from an environment variable."""
 
-    return os.environ.get("VERSION", "undefined"), os.environ.get("COMMIT")
+    # Use the commit where dunamai was added by default
+    # TODO: Use a better default value
+    return os.environ.get("VERSION", "undefined"), os.environ.get("COMMIT", 
"4e5bff1")
 
 
 # Try to determine the version from a development environment first.
 # If this fails, try to get it from environment variables that are set when 
building a docker image.
-__version__, __commit__ = _get_development_version() or _get_version_from_env()
+# We don't use __version__ and __commit__ as these are not reserved words in 
Python
+version, commit = get_development_version() or get_version_from_env()
diff --git a/poetry.lock b/poetry.lock
index 183654a..0ceb278 100644
--- a/poetry.lock
+++ b/poetry.lock
@@ -1,4 +1,4 @@
-# This file is automatically @generated by Poetry 2.1.1 and should not be 
changed by hand.
+# This file is automatically @generated by Poetry 2.0.1 and should not be 
changed by hand.
 
 [[package]]
 name = "aiofiles"
@@ -125,7 +125,7 @@ propcache = ">=0.2.0"
 yarl = ">=1.17.0,<2.0"
 
 [package.extras]
-speedups = ["Brotli ; platform_python_implementation == \"CPython\"", "aiodns 
(>=3.2.0) ; sys_platform == \"linux\" or sys_platform == \"darwin\"", 
"brotlicffi ; platform_python_implementation != \"CPython\""]
+speedups = ["Brotli", "aiodns (>=3.2.0)", "brotlicffi"]
 
 [[package]]
 name = "aiosignal"
@@ -179,7 +179,7 @@ SQLAlchemy = ">=1.3.0"
 typing-extensions = ">=4"
 
 [package.extras]
-tz = ["backports.zoneinfo ; python_version < \"3.9\"", "tzdata"]
+tz = ["backports.zoneinfo", "tzdata"]
 
 [[package]]
 name = "annotated-types"
@@ -211,7 +211,7 @@ sniffio = ">=1.1"
 
 [package.extras]
 doc = ["Sphinx (>=7.4,<8.0)", "packaging", "sphinx-autodoc-typehints 
(>=1.2.0)", "sphinx_rtd_theme"]
-test = ["anyio[trio]", "coverage[toml] (>=7)", "exceptiongroup (>=1.2.0)", 
"hypothesis (>=4.0)", "psutil (>=5.9)", "pytest (>=7.0)", "trustme", 
"truststore (>=0.9.1) ; python_version >= \"3.10\"", "uvloop (>=0.21) ; 
platform_python_implementation == \"CPython\" and platform_system != 
\"Windows\" and python_version < \"3.14\""]
+test = ["anyio[trio]", "coverage[toml] (>=7)", "exceptiongroup (>=1.2.0)", 
"hypothesis (>=4.0)", "psutil (>=5.9)", "pytest (>=7.0)", "trustme", 
"truststore (>=0.9.1)", "uvloop (>=0.21)"]
 trio = ["trio (>=0.26.1)"]
 
 [[package]]
@@ -284,12 +284,12 @@ files = [
 ]
 
 [package.extras]
-benchmark = ["cloudpickle ; platform_python_implementation == \"CPython\"", 
"hypothesis", "mypy (>=1.11.1) ; platform_python_implementation == \"CPython\" 
and python_version >= \"3.10\"", "pympler", "pytest (>=4.3.0)", 
"pytest-codspeed", "pytest-mypy-plugins ; platform_python_implementation == 
\"CPython\" and python_version >= \"3.10\"", "pytest-xdist[psutil]"]
-cov = ["cloudpickle ; platform_python_implementation == \"CPython\"", 
"coverage[toml] (>=5.3)", "hypothesis", "mypy (>=1.11.1) ; 
platform_python_implementation == \"CPython\" and python_version >= \"3.10\"", 
"pympler", "pytest (>=4.3.0)", "pytest-mypy-plugins ; 
platform_python_implementation == \"CPython\" and python_version >= \"3.10\"", 
"pytest-xdist[psutil]"]
-dev = ["cloudpickle ; platform_python_implementation == \"CPython\"", 
"hypothesis", "mypy (>=1.11.1) ; platform_python_implementation == \"CPython\" 
and python_version >= \"3.10\"", "pre-commit-uv", "pympler", "pytest 
(>=4.3.0)", "pytest-mypy-plugins ; platform_python_implementation == 
\"CPython\" and python_version >= \"3.10\"", "pytest-xdist[psutil]"]
+benchmark = ["cloudpickle", "hypothesis", "mypy (>=1.11.1)", "pympler", 
"pytest (>=4.3.0)", "pytest-codspeed", "pytest-mypy-plugins", 
"pytest-xdist[psutil]"]
+cov = ["cloudpickle", "coverage[toml] (>=5.3)", "hypothesis", "mypy 
(>=1.11.1)", "pympler", "pytest (>=4.3.0)", "pytest-mypy-plugins", 
"pytest-xdist[psutil]"]
+dev = ["cloudpickle", "hypothesis", "mypy (>=1.11.1)", "pre-commit-uv", 
"pympler", "pytest (>=4.3.0)", "pytest-mypy-plugins", "pytest-xdist[psutil]"]
 docs = ["cogapp", "furo", "myst-parser", "sphinx", "sphinx-notfound-page", 
"sphinxcontrib-towncrier", "towncrier (<24.7)"]
-tests = ["cloudpickle ; platform_python_implementation == \"CPython\"", 
"hypothesis", "mypy (>=1.11.1) ; platform_python_implementation == \"CPython\" 
and python_version >= \"3.10\"", "pympler", "pytest (>=4.3.0)", 
"pytest-mypy-plugins ; platform_python_implementation == \"CPython\" and 
python_version >= \"3.10\"", "pytest-xdist[psutil]"]
-tests-mypy = ["mypy (>=1.11.1) ; platform_python_implementation == \"CPython\" 
and python_version >= \"3.10\"", "pytest-mypy-plugins ; 
platform_python_implementation == \"CPython\" and python_version >= \"3.10\""]
+tests = ["cloudpickle", "hypothesis", "mypy (>=1.11.1)", "pympler", "pytest 
(>=4.3.0)", "pytest-mypy-plugins", "pytest-xdist[psutil]"]
+tests-mypy = ["mypy (>=1.11.1)", "pytest-mypy-plugins"]
 
 [[package]]
 name = "blinker"
@@ -602,10 +602,10 @@ files = [
 cffi = {version = ">=1.12", markers = "platform_python_implementation != 
\"PyPy\""}
 
 [package.extras]
-docs = ["sphinx (>=5.3.0)", "sphinx-rtd-theme (>=3.0.0) ; python_version >= 
\"3.8\""]
+docs = ["sphinx (>=5.3.0)", "sphinx-rtd-theme (>=3.0.0)"]
 docstest = ["pyenchant (>=3)", "readme-renderer (>=30.0)", 
"sphinxcontrib-spelling (>=7.3.1)"]
-nox = ["nox (>=2024.4.15)", "nox[uv] (>=2024.3.2) ; python_version >= \"3.8\""]
-pep8test = ["check-sdist ; python_version >= \"3.8\"", "click (>=8.0.1)", 
"mypy (>=1.4)", "ruff (>=0.3.6)"]
+nox = ["nox (>=2024.4.15)", "nox[uv] (>=2024.3.2)"]
+pep8test = ["check-sdist", "click (>=8.0.1)", "mypy (>=1.4)", "ruff (>=0.3.6)"]
 sdist = ["build (>=1.0.0)"]
 ssh = ["bcrypt (>=3.1.5)"]
 test = ["certifi (>=2024)", "cryptography-vectors (==44.0.2)", "pretend 
(>=0.7)", "pytest (>=7.4.0)", "pytest-benchmark (>=4.0)", "pytest-cov 
(>=2.10.1)", "pytest-xdist (>=3.5.0)"]
@@ -689,7 +689,7 @@ version = "1.23.0"
 description = "Dynamic version generation"
 optional = false
 python-versions = ">=3.5"
-groups = ["dev"]
+groups = ["main", "dev"]
 files = [
     {file = "dunamai-1.23.0-py3-none-any.whl", hash = 
"sha256:a0906d876e92441793c6a423e16a4802752e723e9c9a5aabdc5535df02dbe041"},
     {file = "dunamai-1.23.0.tar.gz", hash = 
"sha256:a163746de7ea5acb6dacdab3a6ad621ebc612ed1e528aaa8beedb8887fccd2c4"},
@@ -748,7 +748,7 @@ files = [
 [package.extras]
 docs = ["furo (>=2024.8.6)", "sphinx (>=8.1.3)", "sphinx-autodoc-typehints 
(>=3)"]
 testing = ["covdefaults (>=2.3)", "coverage (>=7.6.10)", "diff-cover 
(>=9.2.1)", "pytest (>=8.3.4)", "pytest-asyncio (>=0.25.2)", "pytest-cov 
(>=6)", "pytest-mock (>=3.14)", "pytest-timeout (>=2.3.1)", "virtualenv 
(>=20.28.1)"]
-typing = ["typing-extensions (>=4.12.2) ; python_version < \"3.11\""]
+typing = ["typing-extensions (>=4.12.2)"]
 
 [[package]]
 name = "flask"
@@ -1054,7 +1054,7 @@ httpcore = "==1.*"
 idna = "*"
 
 [package.extras]
-brotli = ["brotli ; platform_python_implementation == \"CPython\"", 
"brotlicffi ; platform_python_implementation != \"CPython\""]
+brotli = ["brotli", "brotlicffi"]
 cli = ["click (==8.*)", "pygments (==2.*)", "rich (>=10,<14)"]
 http2 = ["h2 (>=3,<5)"]
 socks = ["socksio (==1.*)"]
@@ -1082,7 +1082,7 @@ wsproto = ">=0.14.0"
 docs = ["pydata_sphinx_theme", "sphinxcontrib_mermaid"]
 h3 = ["aioquic (>=0.9.0,<1.0)"]
 trio = ["trio (>=0.22.0)"]
-uvloop = ["uvloop (>=0.18) ; platform_system != \"Windows\""]
+uvloop = ["uvloop (>=0.18)"]
 
 [[package]]
 name = "hyperframe"
@@ -1475,7 +1475,7 @@ version = "24.2"
 description = "Core utilities for Python packages"
 optional = false
 python-versions = ">=3.8"
-groups = ["dev", "test"]
+groups = ["main", "dev", "test"]
 files = [
     {file = "packaging-24.2-py3-none-any.whl", hash = 
"sha256:09abb1bccd265c01f4a3aa3f7a7db064b36514d2cba19a2f694fe6150451a759"},
     {file = "packaging-24.2.tar.gz", hash = 
"sha256:c228a6dc5e932d346bc5739379109d49e8853dd8223571c7c5b55260edc0b97f"},
@@ -1697,7 +1697,7 @@ typing-extensions = ">=4.12.2"
 
 [package.extras]
 email = ["email-validator (>=2.0.0)"]
-timezone = ["tzdata ; python_version >= \"3.9\" and platform_system == 
\"Windows\""]
+timezone = ["tzdata"]
 
 [[package]]
 name = "pydantic-core"
@@ -2368,7 +2368,7 @@ files = [
 ]
 
 [package.extras]
-brotli = ["brotli (>=1.0.9) ; platform_python_implementation == \"CPython\"", 
"brotlicffi (>=0.8.0) ; platform_python_implementation != \"CPython\""]
+brotli = ["brotli (>=1.0.9)", "brotlicffi (>=0.8.0)"]
 h2 = ["h2 (>=4,<5)"]
 socks = ["pysocks (>=1.5.6,!=1.5.7,<2.0)"]
 zstd = ["zstandard (>=0.18.0)"]
@@ -2392,7 +2392,7 @@ platformdirs = ">=3.9.1,<5"
 
 [package.extras]
 docs = ["furo (>=2023.7.26)", "proselint (>=0.13)", "sphinx (>=7.1.2,!=7.3)", 
"sphinx-argparse (>=0.4)", "sphinxcontrib-towncrier (>=0.2.1a0)", "towncrier 
(>=23.6)"]
-test = ["covdefaults (>=2.3)", "coverage (>=7.2.7)", 
"coverage-enable-subprocess (>=1)", "flaky (>=3.7)", "packaging (>=23.1)", 
"pytest (>=7.4)", "pytest-env (>=0.8.2)", "pytest-freezer (>=0.4.8) ; 
platform_python_implementation == \"PyPy\" or platform_python_implementation == 
\"CPython\" and sys_platform == \"win32\" and python_version >= \"3.13\"", 
"pytest-mock (>=3.11.1)", "pytest-randomly (>=3.12)", "pytest-timeout (>=2.1)", 
"setuptools (>=68)", "time-machine (>=2.10) ; platform_pyth [...]
+test = ["covdefaults (>=2.3)", "coverage (>=7.2.7)", 
"coverage-enable-subprocess (>=1)", "flaky (>=3.7)", "packaging (>=23.1)", 
"pytest (>=7.4)", "pytest-env (>=0.8.2)", "pytest-freezer (>=0.4.8)", 
"pytest-mock (>=3.11.1)", "pytest-randomly (>=3.12)", "pytest-timeout (>=2.1)", 
"setuptools (>=68)", "time-machine (>=2.10)"]
 
 [[package]]
 name = "watchfiles"
@@ -2623,4 +2623,4 @@ propcache = ">=0.2.0"
 [metadata]
 lock-version = "2.1"
 python-versions = "~=3.13"
-content-hash = 
"21ebba9a2dccfea54a36dc086b548fcfbbc0a33834efaeb7853bac36e1e79930"
+content-hash = 
"0f21c2914ae6a0d5a7f28f1dcad5bf58610469c705ace76f0d68d0af13da1e27"
diff --git a/pyproject.toml b/pyproject.toml
index 83825c1..d5218b0 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -15,6 +15,7 @@ dependencies = [
   "asfquart", # TODO: convert asfquart from a source dependency to pypi or git 
dependency
   "blockbuster>=1.5.23,<2.0.0",
   "cryptography~=44.0",
+  "dunamai>=1.23.0",
   "greenlet>=3.1.1,<4.0.0",
   "httpx~=0.27",
   "hypercorn~=0.17",
@@ -32,7 +33,6 @@ dev = [
   "pyright>=1.1.393",
   "ruff>=0.9.4",
   "types-aiofiles>=24.1.0.20241221,<25.0.0.0",
-  "dunamai>=1.23.0"
 ]
 test = [
   "pytest>=8.0",


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to