Skip to content

Commit

Permalink
Feature/poetry (#156)
Browse files Browse the repository at this point in the history
* migrate to poetry

* update Dockerfile for poetry

* remove version from __init__.py, add "--rm" to docker example, add missing sudo binary

* fix Dockerfile

* update poetry version in Dockerfile

* update workflows
  • Loading branch information
markusressel committed Mar 23, 2023
1 parent 5b3f049 commit a3be1e8
Show file tree
Hide file tree
Showing 11 changed files with 1,170 additions and 1,370 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/python_publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel
pip install setuptools wheel poetry
- name: Build and publish
run: |
python setup.py sdist bdist_wheel
poetry build
- name: Publish a Python distribution to PyPI
uses: pypa/gh-action-pypi-publish@master
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_PASSWORD }}
10 changes: 4 additions & 6 deletions .github/workflows/pythonpackage.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Python package

on: [push]
on: [ push ]

jobs:
build:
Expand All @@ -20,8 +20,8 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pipenv
pipenv install --system --deploy
pip install poetry
poetry install
- name: Lint with flake8
run: |
pip install flake8
Expand All @@ -31,7 +31,5 @@ jobs:
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pipenv install --system --deploy
pip install pytest
cd tests
pytest
poetry run pytest
34 changes: 23 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,22 +1,34 @@
# Docker image for barcode-server

# dont use alpine for python builds: https://pythonspeed.com/articles/alpine-docker-python/
FROM python:3.11-slim-buster

ENV PYTHONUNBUFFERED=1
ENV POETRY_VERSION="1.4.1"
ENV PIP_DISABLE_PIP_VERSION_CHECK=on
ENV VENV_HOME=/opt/poetry
WORKDIR /app

COPY . .

COPY poetry.lock pyproject.toml ./
RUN apt-get update \
&& apt-get -y install sudo python3-pip python3-evdev \
&& apt-get clean && rm -rf /var/lib/apt/lists/*
RUN pip install --upgrade pip;\
pip3 install evdev;\
pip install pipenv;\
PIP_IGNORE_INSTALLED=1 pipenv install --system --deploy;\
pip install .
&& apt-get -y install sudo python3-pip python3-evdev \
&& apt-get clean && rm -rf /var/lib/apt/lists/* \
&& python3 -m venv ${VENV_HOME} \
&& ${VENV_HOME}/bin/pip install --upgrade pip \
&& ${VENV_HOME}/bin/pip install "poetry==${POETRY_VERSION}" \
&& ${VENV_HOME}/bin/poetry check \
&& POETRY_VIRTUALENVS_CREATE=false ${VENV_HOME}/bin/poetry install --no-interaction --no-cache --only main \
&& ${VENV_HOME}/bin/pip uninstall -y poetry

# Add Poetry to PATH
ENV PATH="${VENV_HOME}/bin:${PATH}"

COPY docker docker
COPY barcode_server barcode_server
COPY README.md README.md

RUN ${VENV_HOME}/bin/pip install .

ENV PUID=1000 PGID=1000

ENTRYPOINT [ "docker/entrypoint.sh", "barcode-server" ]
ENTRYPOINT "docker/entrypoint.sh" "${VENV_HOME}/bin/barcode-server" "$0" "$@"
CMD [ "run" ]
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ PROJECT=barcode_server
docker-image:
docker build . --file Dockerfile --tag markusressel/barcode-server:latest --no-cache

docker-latest:
docker build . --file Dockerfile --tag markusressel/barcode-server:latest

current-version:
set -ex
@echo "Current version is `cat ${PROJECT}/__init__.py | grep '__version__' | cut -d ' ' -f3 | sed s/\\\"//g`"
Expand Down
22 changes: 0 additions & 22 deletions Pipfile

This file was deleted.

1,254 changes: 0 additions & 1,254 deletions Pipfile.lock

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ deactivate

When starting the docker container, make sure to pass through input devices:
```
docker run -it \
docker run -it --rm \
--name barcode \
--device=/dev/input \
-v "/home/markus/.config/barcode_server.yaml:/app/barcode_server.yaml" \
Expand Down
1 change: 0 additions & 1 deletion barcode_server/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
__version__ = "2.3.3"
1,079 changes: 1,079 additions & 0 deletions poetry.lock

Large diffs are not rendered by default.

57 changes: 57 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
[tool.poetry]
name = "barcode-server"
version = "2.3.3"
description = "A simple daemon to expose USB Barcode Scanner data to other services using Websockets, Webhooks or MQTT."

license = "AGPL-3.0-or-later"

authors = [
"Markus Ressel <mail@markusressel.de>",
]

readme = 'README.md'

repository = "https://github.com/markusressel/barcode-server"
homepage = "https://github.com/markusressel/barcode-server"

keywords = ['barcode', 'asyncio', 'qrcode', 'http', 'mqtt', 'server', 'websocket', 'websocket']

classifiers = [
"License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)",
"Programming Language :: Python :: 3 :: Only",
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
"Development Status :: 5 - Production/Stable"
]

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

[tool.poetry.dependencies]
python = "^3.10" # Compatible python versions must be declared here

container-app-conf = ">=5.0.0"
evdev = "*"
orjson = ">=3,<4"
aiohttp = "*"
asyncio-mqtt = "*"
prometheus-client = "*"
prometheus_async = "*"
click = "*"


[tool.poetry.dev-dependencies]
pytest = "*"
pytest-aiohttp = "*"
pytest-mock = "*"

[tool.pytest.ini_options]
testpaths = [
"tests",
]

[tool.poetry.scripts]
barcode-server = 'barcode_server.cli:cli'
72 changes: 0 additions & 72 deletions setup.py

This file was deleted.

0 comments on commit a3be1e8

Please sign in to comment.