Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Future code base components? (python 3.12 / pyproject.toml vs setup.py / poetry vs pip-pipenv-twine-... / docker improvements) #181

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
26 changes: 11 additions & 15 deletions .github/workflows/build-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,27 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@master
- name: Checkout code 🛒
uses: actions/checkout@v4

- name: Update version file ⬆️
uses: brettdorrans/[email protected]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we can use the git tag as a source of version, we can get rid of this step and the .VERSION file.

with:
filename: '.VERSION'
placeholder: '${VERSION}'

- name: Set up Python 3.12
- name: Set up Python 3.12 🐍
uses: actions/setup-python@v5
with:
python-version: "3.12"

- name: Install pypa/build
run: >-
python -m
pip install
build
--user

- name: Build a source tarball
run: >-
python -m
build
--sdist
--outdir dist/ .
- name: Install and configure Poetry 📜
uses: snok/install-poetry@v1
with:
virtualenvs-create: false

- name: Build & Package project 👷
run: poetry build

- name: Publish distribution 📦 to PyPI
if: startsWith(github.ref, 'refs/tags')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need poetry publish here?
Also do wee need to set new environent variables in github action?

Expand Down
33 changes: 21 additions & 12 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
FROM python:3.12-alpine

# Install python-lxml
RUN apk add --no-cache --virtual .build-deps \
gcc musl-dev \
libxslt-dev libxml2-dev && \
pip install lxml setuptools && \
apk del .build-deps && \
apk add --no-cache libxslt libxml2
RUN adduser -D withings-sync

RUN mkdir -p /src
COPY . /src
USER withings-sync
WORKDIR /home/withings-sync

RUN cd /src && \
pip install .
ENV PATH="/home/withings-sync/.poetry/bin:${PATH}" \
PATH="/home/withings-sync/.local/bin:${PATH}" \
PIP_ROOT_USER_ACTION=ignore \
PIP_DISABLE_PIP_VERSION_CHECK=on \
POETRY_HOME=/home/withings-sync/.poetry \
POETRY_NO_INTERACTION=1 \
POETRY_VIRTUALENVS_IN_PROJECT=1 \
POETRY_VIRTUALENVS_CREATE=1 \
POETRY_CACHE_DIR=/tmp/poetry_cache

ENTRYPOINT ["withings-sync"]
RUN pip install poetry

COPY --chown=withings-sync:withings-sync pyproject.toml poetry.lock README.md .VERSION ./
RUN poetry install --without dev --no-root && rm -rf $POETRY_CACHE_DIR

COPY --chown=withings-sync:withings-sync withings_sync ./withings_sync/
RUN poetry install --without dev
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

without a deeper understanding of poetry, can we compbine lines 20 -24 into two lines (copy all the required files and then install it)?


ENTRYPOINT ["poetry", "run", "withings-sync"]
13 changes: 5 additions & 8 deletions contrib/do_release.sh
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file was not used anymore. We used release in GitHub actions with the help of the .VERSION file.
IMHO we can delete this file and see how we can get the version from a git tag with petry/toml?

Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
# (username=__token__, password=pypi-***)

set -e
# extract the version="x.y.z" from setup.py
VER=$(sed -n -e 's/.*version="\(.*\)".*/\1/p' < setup.py)
# extract the version="x.y.z" from pyproject.toml
VER=$(sed -n -e 's/.*version = "\(.*\)".*/\1/p' < pyproject.toml)

function tag_if_not_tagged {
TAG=v$1
TAG=v$VER
if git rev-parse --verify --quiet "refs/tags/$TAG" >/dev/null; then
echo "tag ${TAG} already exists"
else
Expand All @@ -19,13 +19,10 @@ function tag_if_not_tagged {
}

function publish_to_pypi() {
VERSION=$1
echo "creating sdist.."
python3 setup.py sdist > /dev/null
ARTIFACT="dist/withings-sync-${VERSION}.tar.gz"
poetry build
# Publish to pypi.org
twine check $ARTIFACT
twine upload $ARTIFACT
poetry publish
}

tag_if_not_tagged $VER
Expand Down
770 changes: 770 additions & 0 deletions poetry.lock

Large diffs are not rendered by default.

29 changes: 29 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[tool.poetry]
name = "withings-sync"
version = "5.0.0a1"
description = "A tool for synchronisation of Withings (ex. Nokia Health Body) to Garmin Connect and Trainer Road."
authors = ["Steffen Vogel <[email protected]>",
"Masayuki Hamasaki",
]
license = "MIT"
readme = "README.md"
packages = [{include = "withings_sync"}]

[tool.poetry.dependencies]
python = "^3.12"
garth = "^0.4.46"
requests = "^2.32.3"
lxml = "^5.3.0"
python-dotenv = "^1.0.1"
importlib-resources = "^6.4.5"

[tool.poetry.group.dev.dependencies]
black = "^24.10.0"
pylint = "^3.3.1"

[tool.poetry.scripts]
withings-sync = "withings_sync.sync:main"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
4 changes: 0 additions & 4 deletions requirements.txt

This file was deleted.

35 changes: 0 additions & 35 deletions setup.py

This file was deleted.

4 changes: 2 additions & 2 deletions withings_sync/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,8 +503,8 @@ def main():
logging.debug("withings-sync script version %s", version("withings-sync"))
logging.debug("Script invoked with the following arguments: %s", ARGS)

if sys.version_info < (3, 7):
print("Sorry, requires at least Python3.7 to avoid issues with SSL.")
if sys.version_info < (3, 12):
print("Sorry, requires at least Python3.12.")
sys.exit(1)

sync()
Expand Down
5 changes: 3 additions & 2 deletions withings_sync/withings2.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import json
import os
import time
import pkg_resources
import importlib_resources
import requests

log = logging.getLogger("withings")
Expand All @@ -14,9 +14,10 @@
TOKEN_URL = "https://wbsapi.withings.net/v2/oauth2"
GETMEAS_URL = "https://wbsapi.withings.net/measure?action=getmeas"


APP_CONFIG = os.environ.get(
"WITHINGS_APP",
pkg_resources.resource_filename(__name__, "config/withings_app.json"),
importlib_resources.files(__name__) / "config/withings_app.json",
)
USER_CONFIG = os.environ.get("WITHINGS_USER", HOME + "/.withings_user.json")

Expand Down