Skip to content

Commit d74e5aa

Browse files
committed
Migrate to poetry build system
1 parent e6d5981 commit d74e5aa

37 files changed

+877
-27
lines changed

.dockerignore

Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
# Created by .ignore support plugin (hsz.mobi)
2+
### Python template
3+
# Byte-compiled / optimized / DLL files
4+
__pycache__/
5+
*.py[cod]
6+
*$py.class
7+
8+
# C extensions
9+
*.so
10+
11+
# Distribution / packaging
12+
.Python
13+
env/
14+
build/
15+
develop-eggs/
16+
dist/
17+
downloads/
18+
eggs/
19+
.eggs/
20+
lib/
21+
lib64/
22+
parts/
23+
sdist/
24+
var/
25+
*.egg-info/
26+
.installed.cfg
27+
*.egg
28+
29+
# PyInstaller
30+
# Usually these files are written by a python script from a template
31+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
32+
*.manifest
33+
*.spec
34+
35+
# Installer logs
36+
pip-log.txt
37+
pip-delete-this-directory.txt
38+
39+
# Unit test / coverage reports
40+
htmlcov/
41+
.tox/
42+
.coverage
43+
.coverage.*
44+
.cache
45+
nosetests.xml
46+
coverage.xml
47+
*,cover
48+
.hypothesis/
49+
50+
# Translations
51+
*.mo
52+
*.pot
53+
54+
# Django stuff:
55+
*.log
56+
local_settings.py
57+
58+
# Flask stuff:
59+
instance/
60+
.webassets-cache
61+
62+
# Scrapy stuff:
63+
.scrapy
64+
65+
# Sphinx documentation
66+
docs/_build/
67+
68+
# PyBuilder
69+
target/
70+
71+
# IPython Notebook
72+
.ipynb_checkpoints
73+
74+
# pyenv
75+
.python-version
76+
77+
# celery beat schedule file
78+
celerybeat-schedule
79+
80+
# dotenv
81+
.env
82+
83+
# virtualenv
84+
venv/
85+
ENV/
86+
87+
# Spyder project settings
88+
.spyderproject
89+
90+
# Rope project settings
91+
.ropeproject
92+
### VirtualEnv template
93+
# Virtualenv
94+
# http://iamzed.com/2009/05/07/a-primer-on-virtualenv/
95+
[Bb]in
96+
[Ii]nclude
97+
[Ll]ib
98+
[Ll]ib64
99+
[Ll]ocal
100+
[Ss]cripts
101+
pyvenv.cfg
102+
.venv
103+
pip-selfcheck.json
104+
105+
### JetBrains template
106+
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
107+
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
108+
109+
# User-specific stuff
110+
.idea/**/workspace.xml
111+
.idea/**/tasks.xml
112+
.idea/**/usage.statistics.xml
113+
.idea/**/dictionaries
114+
.idea/**/shelf
115+
116+
# AWS User-specific
117+
.idea/**/aws.xml
118+
119+
# Generated files
120+
.idea/**/contentModel.xml
121+
122+
# Sensitive or high-churn files
123+
.idea/**/dataSources/
124+
.idea/**/dataSources.ids
125+
.idea/**/dataSources.local.xml
126+
.idea/**/sqlDataSources.xml
127+
.idea/**/dynamic.xml
128+
.idea/**/uiDesigner.xml
129+
.idea/**/dbnavigator.xml
130+
131+
# Gradle
132+
.idea/**/gradle.xml
133+
.idea/**/libraries
134+
135+
# Gradle and Maven with auto-import
136+
# When using Gradle or Maven with auto-import, you should exclude module files,
137+
# since they will be recreated, and may cause churn. Uncomment if using
138+
# auto-import.
139+
# .idea/artifacts
140+
# .idea/compiler.xml
141+
# .idea/jarRepositories.xml
142+
# .idea/modules.xml
143+
# .idea/*.iml
144+
# .idea/modules
145+
# *.iml
146+
# *.ipr
147+
148+
# CMake
149+
cmake-build-*/
150+
151+
# Mongo Explorer plugin
152+
.idea/**/mongoSettings.xml
153+
154+
# File-based project format
155+
*.iws
156+
157+
# IntelliJ
158+
out/
159+
160+
# mpeltonen/sbt-idea plugin
161+
.idea_modules/
162+
163+
# JIRA plugin
164+
atlassian-ide-plugin.xml
165+
166+
# Cursive Clojure plugin
167+
.idea/replstate.xml
168+
169+
# SonarLint plugin
170+
.idea/sonarlint/
171+
172+
# Crashlytics plugin (for Android Studio and IntelliJ)
173+
com_crashlytics_export_strings.xml
174+
crashlytics.properties
175+
crashlytics-build.properties
176+
fabric.properties
177+
178+
# Editor-based Rest Client
179+
.idea/httpRequests
180+
181+
# Android studio 3.1+ serialized cache file
182+
.idea/caches/build_file_checksums.ser
183+
184+
# idea folder, uncomment if you don't need it
185+
.idea
186+
187+
# Test results
188+
junit/
189+
190+
.github/

.github/workflows/build_and_test_python.yml

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,47 @@ jobs:
1515
runs-on: ubuntu-latest
1616
strategy:
1717
matrix:
18-
python-version: [ "3.12" ]
18+
python-version: [ "3.12", "3.13" ]
1919

2020
steps:
21-
- uses: actions/checkout@v4
21+
- name: Checkout code
22+
uses: actions/checkout@v4
23+
2224
- name: Set up Python ${{ matrix.python-version }}
2325
uses: actions/setup-python@v5
2426
with:
2527
python-version: ${{ matrix.python-version }}
2628
cache: 'pip'
29+
30+
- name: Install Poetry
31+
uses: snok/install-poetry@v1
32+
with:
33+
virtualenvs-in-project: true
34+
35+
- name: Load cached venv
36+
id: cached-poetry-dependencies
37+
uses: actions/cache@v4
38+
with:
39+
path: .venv
40+
key: venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}
41+
2742
- name: Install dependencies
43+
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
2844
run: |
29-
python -m pip install --upgrade pip
30-
python -m pip install -r requirements.txt
31-
- name: Test with pytest
45+
poetry install --no-interaction --no-root
46+
47+
- name: Install library
48+
run: poetry install --no-interaction
49+
50+
- name: Run tests with coverage
3251
run: |
33-
python -m pip install pytest pytest-cov
34-
python -m pytest --doctest-modules --junitxml=junit/test-results-${{ matrix.python-version }}.xml
52+
poetry run pytest tests --cov --junit-xml=junit/test-results-${{ matrix.python-version }}.xml
53+
3554
- name: Lint with Ruff
3655
run: |
37-
python -m pip install ruff
38-
ruff check --output-format=github .
56+
poetry run ruff check .
3957
continue-on-error: true
58+
4059
- name: Surface failing tests
4160
uses: pmeier/pytest-results-action@main
4261
with:

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,4 +185,5 @@ fabric.properties
185185
.idea
186186

187187
# Test results
188-
junit/
188+
junit/
189+
.run/

Dockerfile

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,41 @@
1-
FROM python:3.12-slim
1+
FROM python:3.12-slim AS builder
2+
3+
# --- Install Poetry ---
4+
ARG POETRY_VERSION=1.8
5+
6+
ENV POETRY_HOME=/opt/poetry
7+
ENV POETRY_NO_INTERACTION=1
8+
ENV POETRY_VIRTUALENVS_IN_PROJECT=1
9+
ENV POETRY_VIRTUALENVS_CREATE=1
10+
ENV PYTHONDONTWRITEBYTECODE=1
11+
ENV PYTHONUNBUFFERED=1
12+
# Tell Poetry where to place its cache and virtual environment
13+
ENV POETRY_CACHE_DIR=/opt/.cache
14+
15+
RUN pip install "poetry==${POETRY_VERSION}"
16+
17+
WORKDIR /usr/src/app
18+
19+
# --- Reproduce the environment ---
20+
# You can comment the following two lines if you prefer to manually install
21+
# the dependencies from inside the container.
22+
COPY pyproject.toml poetry.lock /usr/src/app/
23+
24+
# Install the dependencies and clear the cache afterwards.
25+
# This may save some MBs.
26+
RUN poetry install --no-root && rm -rf $POETRY_CACHE_DIR
27+
28+
# Now let's build the runtime image from the builder.
29+
# We'll just copy the env and the PATH reference.
30+
FROM python:3.12-slim AS runtime
231

332
WORKDIR /usr/src/app
433

5-
COPY requirements.txt ./
6-
RUN apt-get update \
7-
&& apt-get install -y --no-install-recommends gcc python3-dev \
8-
&& rm -rf /var/lib/apt/lists/* \
9-
&& pip install --no-cache-dir -r requirements.txt \
10-
&& apt-get purge -y --auto-remove gcc python3-dev
11-
# the --no-install-recommends helps limit some of the install so that you can be more explicit about what gets installed
34+
ENV VIRTUAL_ENV=/usr/src/app/.venv
35+
ENV PATH="/usr/src/app/.venv/bin:$PATH"
1236

13-
COPY . .
37+
COPY --from=builder ${VIRTUAL_ENV} ${VIRTUAL_ENV}
38+
COPY src/ .
39+
COPY examples/ .
1440

15-
CMD [ "python", "./mqtt_gateway.py"]
41+
CMD [ "python", "./mqtt_gateway.py"]

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ An [openWB](https://openwb.de) charging station is capable of providing informat
103103
need to provide the configuration in the file charging-stations.json. A sample configuration for two cars connected to
104104
an openWB charging station would be the following.
105105

106-
Check-out the [sample file](charging-stations.json.sample)
106+
Check-out the [sample file](examples\charging-stations.json.sample)
107107

108108
The key-value pairs in the JSON express the following:
109109

File renamed without changes.

0 commit comments

Comments
 (0)