Skip to content

Commit

Permalink
Use uv as pm
Browse files Browse the repository at this point in the history
  • Loading branch information
LeoColomb authored Oct 8, 2024
1 parent a1796fe commit 7afd357
Show file tree
Hide file tree
Showing 15 changed files with 468 additions and 480 deletions.
4 changes: 0 additions & 4 deletions .fly/start.sh

This file was deleted.

15 changes: 9 additions & 6 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@ jobs:
- name: Install Python
uses: actions/setup-python@v5
with:
python-version-file: ".python-version"
cache: pipenv

- name: Install pipenv
run: pip install --user pipenv
- name: Install uv
uses: astral-sh/setup-uv@v3
with:
enable-cache: true

- name: Install dependencies
run: pipenv install --dev
- name: Install the project
run: uv sync --all-extras --dev

- name: Lint
run: pipenv run lint --output-format=github
- name: Run tests
run: ruff check . --output-format=github
35 changes: 24 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
FROM docker.io/python:3 AS builder
WORKDIR /usr/src
ENV PIPENV_VENV_IN_PROJECT=1
RUN pip install --user pipenv
ADD Pipfile.lock Pipfile /usr/src/
RUN /root/.local/bin/pipenv sync
# Install uv
FROM docker.io/python:3.12-slim AS builder
COPY --from=ghcr.io/astral-sh/uv:latest /uv /bin/uv

FROM docker.io/python:3
WORKDIR /usr/src/app
# Change the working directory to the `app` directory
WORKDIR /app

COPY --from=builder /usr/src/.venv /usr/src/app/.venv
COPY . .
# Install dependencies
RUN --mount=type=cache,target=/root/.cache/uv \
--mount=type=bind,source=uv.lock,target=uv.lock \
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
uv sync --frozen --no-install-project --no-editable

CMD [".fly/start.sh"]
# Copy the project into the intermediate image
ADD . /app

# Sync the project
RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --frozen --no-editable

FROM docker.io/python:3.12-slim

# Copy the environment, but not the source code
COPY --from=builder --chown=app:app /app/.venv /app/.venv

# Run the application
CMD ["/app/.venv/bin/home-exporter"]
23 changes: 0 additions & 23 deletions Pipfile

This file was deleted.

433 changes: 0 additions & 433 deletions Pipfile.lock

This file was deleted.

26 changes: 26 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[project]
name = "home-exporter"
version = "0.1.0"
description = "🏠 Home InfluxDB Exporter"
readme = "README.md"
requires-python = ">=3.12"
dependencies = [
"evohomeclient>=0.3.7",
"influxdb3-python>=0.9.0",
"lowatt-grdf>=2.3.0",
"python-dotenv>=1.0.1",
"requests>=2.32.3",
"schedule>=1.2.2",
"sentry-sdk>=2.16.0",
]

[project.scripts]
home-exporter = "home_exporter:main"
# lint = "ruff check ."
# format = "ruff check . --fix"

[tool.uv]
package = true
dev-dependencies = [
"ruff>=0.6.9",
]
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
10 changes: 7 additions & 3 deletions main.py → src/home_exporter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
def write_db():
influxdb_exporter.InfluxDB().write()

while True:
run_pending()
sleep(1)
def main():
while True:
run_pending()
sleep(1)

if __name__ == "__main__":
main()
File renamed without changes.
File renamed without changes.
402 changes: 402 additions & 0 deletions uv.lock

Large diffs are not rendered by default.

0 comments on commit 7afd357

Please sign in to comment.