Skip to content

Commit

Permalink
Make Dockerfile handle caching better and fix 1 trivial test issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreasBackx committed Oct 19, 2024
1 parent 2bb5ea0 commit 4dfed2d
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 23 deletions.
24 changes: 13 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,30 @@

FROM python:3.12-bookworm

# Make 'custom_components/adaptive_lighting' imports available to tests
ENV PYTHONPATH="${PYTHONPATH}:/app"

RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -y \
git \
build-essential libssl-dev libffi-dev python3-dev \
&& rm -rf /var/lib/apt/lists/*

# Clone home-assistant/core
RUN git clone --depth 1 --branch dev https://github.com/home-assistant/core.git /core

# Copy the Adaptive Lighting repository
COPY . /app/
WORKDIR /core

# Setup symlinks in core
# Clone home-assistant/core and setup symlinks
RUN git clone --depth 1 --branch dev https://github.com/home-assistant/core.git /core
RUN mkdir /app
COPY ./scripts /app/scripts
RUN ln -s /core /app/core && /app/scripts/setup-symlinks

# Install home-assistant/core dependencies
COPY ./test_dependencies.py /app/test_dependencies.py
RUN /app/scripts/setup-dependencies

WORKDIR /core

# Make 'custom_components/adaptive_lighting' imports available to tests
ENV PYTHONPATH="${PYTHONPATH}:/app"
# Copy the remaining Adaptive Lighting repository, do this last so most changes
# won't require rebuilding the entire image.
COPY . /app/

ENTRYPOINT ["python3", \
# Enable Python development mode
Expand All @@ -57,4 +59,4 @@ ENTRYPOINT ["python3", \
"-o", "console_output_style=count"]

# Run tests in the 'tests/components/adaptive_lighting' directory
CMD ["tests/components/adaptive_lighting"]
CMD ["/core/tests/components/adaptive_lighting"]
24 changes: 24 additions & 0 deletions custom_components/adaptive_lighting/color_and_brightness.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,30 @@ def noon_and_midnight(
sunrise: datetime.datetime | None = None,
) -> tuple[datetime.datetime, datetime.datetime]:
"""Return the (adjusted) noon and midnight times for the given datetime."""
# if (
# self.sunrise_time is None
# and self.sunset_time is None
# and self.min_sunrise_time is None
# and self.max_sunrise_time is None
# and self.min_sunset_time is None
# and self.max_sunset_time is None
# ):
# solar_noon = self.astral_location.noon(dt, local=False)
# solar_midnight = self.astral_location.midnight(dt, local=False)
# return solar_noon, solar_midnight

# if sunset is None:
# sunset = self.sunset(dt)
# if sunrise is None:
# sunrise = self.sunrise(dt)

# middle = abs(sunset - sunrise) / 2
# if sunset > sunrise:
# noon = sunrise + middle
# midnight = noon + timedelta(hours=12) * (1 if noon.hour < 12 else -1)
# else:
# midnight = sunset + middle
# noon = midnight + timedelta(hours=12) * (1 if midnight.hour < 12 else -1)
sunrise = sunrise or self.sunrise(dt)
sunset = sunset or self.sunset(dt)

Expand Down
8 changes: 4 additions & 4 deletions scripts/setup-dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
set -ex
cd "$(dirname "$0")/.."

pip install -r core/requirements.txt
pip install -r core/requirements.txt --root-user-action

if grep -q 'codecov' core/requirements_test.txt; then
# Older HA versions still have `codecov` in `requirements_test.txt`
Expand All @@ -14,8 +14,8 @@ if grep -q 'mypy-dev==1.10.0a3' core/requirements_test.txt; then
# mypy-dev==1.10.0a3 seems to not be available anymore, HA 2024.4 and 2024.5 are affected
sed -i 's/mypy-dev==1.10.0a3/mypy-dev==1.10.0b1/' core/requirements_test.txt
fi
pip install -r core/requirements_test.txt
pip install -r core/requirements_test.txt --root-user-action

pip install -e core/
pip install -e core/ --root-user-action
pip install ulid-transform # this is in Adaptive-lighting's manifest.json
pip install $(python test_dependencies.py)
pip install $(python test_dependencies.py) --root-user-action
9 changes: 2 additions & 7 deletions scripts/setup-symlinks
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
#!/usr/bin/env bash
set -ex
cd "$(dirname "$0")/.."

# Link custom components
cd core/homeassistant/components/
ln -fs ../../../custom_components/adaptive_lighting adaptive_lighting
cd -
ln -fs /app/custom_components/adaptive_lighting /core/homeassistant/components/adaptive_lighting

# Link tests
cd core/tests/components/
ln -fs ../../../tests/ adaptive_lighting
cd -
ln -fs /app/tests /core/tests/components/adaptive_lighting
1 change: 0 additions & 1 deletion tests/test_switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -1347,7 +1347,6 @@ def mock_area_registry(
registry._area_data = {}
area_kwargs = {
"name": "Test Area",
"normalized_name": "test-area",
"id": "test-area",
"picture": None,
}
Expand Down

0 comments on commit 4dfed2d

Please sign in to comment.