From 2f31b42cb2a852aab8e14c222cc296d79fc23a36 Mon Sep 17 00:00:00 2001 From: Bas Nijholt Date: Sat, 6 Apr 2024 11:25:47 +0200 Subject: [PATCH] Fix `devcontainer` and testing `Dockerfile` (#962) * Fix permissions for `scripts/setup` * Add new script * Use script * Update Dockerfile * Rename and clone * Perms * Fix * fi --- .devcontainer.json | 2 +- .../workflows/install_dependencies/action.yml | 9 +-------- Dockerfile | 13 ++++--------- scripts/install_ha | 16 ++++++++++++++++ scripts/setup | 8 -------- scripts/setup-devcontainer | 11 +++++++++++ 6 files changed, 33 insertions(+), 26 deletions(-) create mode 100755 scripts/install_ha delete mode 100644 scripts/setup create mode 100755 scripts/setup-devcontainer diff --git a/.devcontainer.json b/.devcontainer.json index d842d1dd..14778469 100644 --- a/.devcontainer.json +++ b/.devcontainer.json @@ -1,7 +1,7 @@ { "name": "basnijholt/adaptive_lighting", "image": "mcr.microsoft.com/vscode/devcontainers/python:0-3.11-bullseye", - "postCreateCommand": "scripts/setup", + "postCreateCommand": "scripts/setup-devcontainer", "forwardPorts": [ 8123 ], diff --git a/.github/workflows/install_dependencies/action.yml b/.github/workflows/install_dependencies/action.yml index 3041698b..16c0a6ec 100644 --- a/.github/workflows/install_dependencies/action.yml +++ b/.github/workflows/install_dependencies/action.yml @@ -34,11 +34,4 @@ runs: - name: Install dependencies shell: bash run: | - echo "::warning::### WARNING! Deprecation warnings muted with option '--use-pep517' please address this at some point in pytest.yaml. ###" - pip install -r core/requirements.txt --use-pep517 - # because they decided to pull codecov the package from PyPI... - sed -i '/codecov/d' core/requirements_test.txt - pip install -r core/requirements_test.txt --use-pep517 - pip install -e core/ --use-pep517 - pip install ulid-transform # this is in Adaptive-lighting's manifest.json - pip install $(python test_dependencies.py) --use-pep517 + ./scripts/install_ha diff --git a/Dockerfile b/Dockerfile index 916d1021..d3c5c79b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,7 +7,7 @@ # Optionally build the image yourself with: # docker build -t basnijholt/adaptive-lighting:latest . -FROM python:3.11-buster +FROM python:3.12-bookworm RUN apt-get update && \ DEBIAN_FRONTEND=noninteractive apt-get install -y \ @@ -16,12 +16,7 @@ RUN apt-get update && \ && rm -rf /var/lib/apt/lists/* # Clone home-assistant/core -RUN git clone --depth 1 https://github.com/home-assistant/core.git /core - -# Install home-assistant/core dependencies -RUN pip3 install -r /core/requirements.txt --use-pep517 && \ - pip3 install -r /core/requirements_test.txt --use-pep517 && \ - pip3 install -e /core/ --use-pep517 +RUN git clone --depth 1 --branch dev https://github.com/home-assistant/core.git /core # Copy the Adaptive Lighting repository COPY . /app/ @@ -32,8 +27,8 @@ RUN ln -s /app/custom_components/adaptive_lighting /core/homeassistant/component # For test_dependencies.py ln -s /core /app/core -# Install dependencies of components that Adaptive Lighting depends on -RUN pip3 install $(python3 /app/test_dependencies.py) --use-pep517 +# Install home-assistant/core dependencies +RUN /app/scripts/install_ha WORKDIR /core diff --git a/scripts/install_ha b/scripts/install_ha new file mode 100755 index 00000000..c38fe351 --- /dev/null +++ b/scripts/install_ha @@ -0,0 +1,16 @@ +#!/usr/bin/env bash +set -ex +cd "$(dirname "$0")/.." + +pip install -r core/requirements.txt --use-pep517 + +if grep -q 'codecov' core/requirements_test.txt; then + # Older HA versions still have `codecov` in `requirements_test.txt` + # however it is removed from PyPI, so we cannot install it + sed -i '/codecov/d' core/requirements_test.txt +fi +pip install -r core/requirements_test.txt --use-pep517 + +pip install -e core/ --use-pep517 +pip install ulid-transform # this is in Adaptive-lighting's manifest.json +pip install $(python test_dependencies.py) --use-pep517 diff --git a/scripts/setup b/scripts/setup deleted file mode 100644 index 0688d70d..00000000 --- a/scripts/setup +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env bash - -set -e - -cd "$(dirname "$0")/.." - -python3 -m pip install --requirement requirements.txt -pre-commit install-hooks diff --git a/scripts/setup-devcontainer b/scripts/setup-devcontainer new file mode 100755 index 00000000..9571972b --- /dev/null +++ b/scripts/setup-devcontainer @@ -0,0 +1,11 @@ +#!/usr/bin/env bash +set -e +cd "$(dirname "$0")/.." + +# Clone only if the folder doesn't exist +if [[ ! -d "core" ]]; then + git clone --depth 1 --branch dev https://github.com/home-assistant/core.git +fi + +./scripts/install_ha +pre-commit install-hooks