From a78f02eed8165bd61bc8e4ea9d11e7e9deb96003 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20=C4=8Cerm=C3=A1k?= Date: Wed, 1 Apr 2026 16:01:46 +0200 Subject: [PATCH] Fix version/requirements parsing in setup.py, set version in Dockerfile (#6692) * Fix version/requirements parsing in setup.py, set version in Dockerfile Remove the step patching const.py with detected version in CI and do this during Dockerfile version from BUILD_VERSION argument instead. Also, fix parsing of the version in `setup.py` - it wasn't working because it was splitting the files on "/n" instead of newlines, resulting in all Python packages installed having version string set to `9999.9.9.dev9999` instead of the expected version. (Note: setuptools are doing a version string normalization, so the installed package has stripped leading zeroes and the second component is `9` instead of the literal `09` used in default string in all places. Fixing this is out of scope of this change as the ideal solution would be to change the versioning schema but it should be noted.) Lastly, clean up builder.yaml environment variables (crane is not used anymore after #6679). * Generate setuptools-compatible version for PR builds For PR builds, we're using plain commit SHA as the version. This is perfectly fine for Docker tags but it's not acceptable for Python package version. By fixing the setup.py bug this error surfaced. Work it around by setting the Package version to the string we used previously suffixed by the commit SHA as build metadata (delimited by `+`). --- .github/workflows/builder.yml | 10 +--------- Dockerfile | 4 +++- setup.py | 10 +++++++--- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/.github/workflows/builder.yml b/.github/workflows/builder.yml index 95a0f2f03..8c8c9978a 100644 --- a/.github/workflows/builder.yml +++ b/.github/workflows/builder.yml @@ -35,8 +35,6 @@ on: env: DEFAULT_PYTHON: "3.14.3" COSIGN_VERSION: "v2.5.3" - CRANE_VERSION: "v0.20.7" - CRANE_SHA256: "8ef3564d264e6b5ca93f7b7f5652704c4dd29d33935aff6947dd5adefd05953e" BUILD_NAME: supervisor BUILD_TYPE: supervisor IMAGE_NAME: hassio-supervisor @@ -161,12 +159,6 @@ jobs: path: wheels retention-days: 1 - - name: Set version - if: needs.init.outputs.publish == 'true' - uses: home-assistant/actions/helpers/version@master - with: - type: ${{ env.BUILD_TYPE }} - - name: Set up Python ${{ env.DEFAULT_PYTHON }} if: needs.init.outputs.publish == 'true' uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0 @@ -276,7 +268,7 @@ jobs: image: ghcr.io/home-assistant/amd64-hassio-supervisor image-tags: runner load: true - version: runner + version: ${{ needs.init.outputs.version }} # Pull the Supervisor for publish runs to test the published image - name: Pull Supervisor diff --git a/Dockerfile b/Dockerfile index 110239e29..b513206f5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -40,9 +40,11 @@ RUN \ ${LOCAL_WHEELS:+--find-links $LOCAL_WHEELS} # Install Home Assistant Supervisor +ARG BUILD_VERSION="9999.09.9.dev9999" COPY . supervisor RUN \ - uv pip install --no-cache -e ./supervisor \ + sed -i "s/^SUPERVISOR_VERSION =.*/SUPERVISOR_VERSION = \"${BUILD_VERSION}\"/g" /usr/src/supervisor/supervisor/const.py \ + && uv pip install --no-cache -e ./supervisor \ && python3 -m compileall ./supervisor/supervisor diff --git a/setup.py b/setup.py index 8e09ae7a5..a1ceb2db3 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,9 @@ import re from setuptools import setup -RE_SUPERVISOR_VERSION = re.compile(r"^SUPERVISOR_VERSION =\s*(.+)$") +RE_SUPERVISOR_VERSION = re.compile( + r'^SUPERVISOR_VERSION =\s*"?((?P[0-9a-f]{40})|[^"]+)"?$' +) SUPERVISOR_DIR = Path(__file__).parent REQUIREMENTS_FILE = SUPERVISOR_DIR / "requirements.txt" @@ -16,13 +18,15 @@ CONSTANTS = CONST_FILE.read_text(encoding="utf-8") def _get_supervisor_version(): - for line in CONSTANTS.split("/n"): + for line in CONSTANTS.split("\n"): if match := RE_SUPERVISOR_VERSION.match(line): + if git_sha := match.group("git_sha"): + return f"9999.09.9.dev9999+{git_sha}" return match.group(1) return "9999.09.9.dev9999" setup( version=_get_supervisor_version(), - dependencies=REQUIREMENTS.split("/n"), + dependencies=REQUIREMENTS.split("\n"), )