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 50 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
e1530dd
Use of pkg_resources is deprecated in favor of importlib.resources, i…
stynoo Nov 13, 2024
9c5ac51
The recommended way of using Setuptools has shifted in the direction …
stynoo Nov 13, 2024
0e920f4
Update Dockerfile to use poetry & run as a non-priviledged user.
stynoo Nov 13, 2024
63920bb
up to new major version - https://packaging.python.org/en/latest/spec…
stynoo Nov 13, 2024
09edea9
migrate release script from setup.py/twine to pyproject.toml/poetry
stynoo Nov 13, 2024
131195d
do_release.sh: user versions & tags from pyproject.toml
stynoo Nov 13, 2024
69cff35
sync.py: minimal requirement python 3.12
stynoo Nov 13, 2024
c166add
build-publish.yml: update to use poetry
stynoo Nov 13, 2024
c351a31
update version in pyproject.toml from the git tags
stynoo Dec 7, 2024
9896a15
check if we are good to run on ubuntu-24.04 (latest will upgrade soon…
stynoo Dec 7, 2024
43951b5
test run on ubuntu-24.04 successfull, reverting to latest, we are goo…
stynoo Dec 7, 2024
ac480e9
remove .VERSION from Dockerfile
stynoo Dec 7, 2024
192a6f7
test package building to test-pypi
stynoo Dec 11, 2024
6d99ecb
build-publish.yml: allow trusted package publishing
stynoo Dec 11, 2024
75b598a
build-publish.yml: remove secrets
stynoo Dec 11, 2024
53827f8
build-publish.yml: split build & push
stynoo Dec 11, 2024
dd3055d
build-publish.yml: Store the distribution packages
stynoo Dec 11, 2024
c8de115
build-publish.yml: match versions
stynoo Dec 11, 2024
49a1afe
build-publish.yml: publish always to testpypi but only to pypi on re…
stynoo Dec 11, 2024
ebb3a10
build-publish.yml: add skip-existing to testpypi
stynoo Dec 11, 2024
5a3c36a
build-publish.yml: enrich github release with package
stynoo Dec 11, 2024
30247bc
sync.py: add version parameter && black code formatting
stynoo Dec 14, 2024
5f30683
Dockerfile: best practices & prep for supercronic usage
stynoo Dec 15, 2024
569d443
docker-image.yml: prevent unknown/unknown - OS/Arch - images pushed t…
stynoo Dec 15, 2024
2fd7c1c
streamline actions / only prod push on releases
stynoo Dec 15, 2024
2995e46
docker-image.yml: case
stynoo Dec 15, 2024
745ea1e
docker-image.yml: streamline action filters
stynoo Dec 15, 2024
b90cdcd
build-publish.yml: remove double condition
stynoo Dec 15, 2024
32adfd3
Update README.md
stynoo Dec 15, 2024
016a6aa
Merge branch 'master' of github.com:stynoo/withings-sync
stynoo Dec 15, 2024
64ba9c3
README.md: updates
stynoo Dec 15, 2024
1052bdf
README.md: more updates
stynoo Dec 15, 2024
458b786
README.md: cleanup
stynoo Dec 15, 2024
64b3adc
README.md: more cleanup
stynoo Dec 15, 2024
cb17773
README.md: expand docker-compose commands
stynoo Dec 17, 2024
e158679
README.md: work on expanding the pip installation & running methods
stynoo Dec 18, 2024
028045f
README.md: more improvements to the installation section
stynoo Dec 18, 2024
7b13b81
README.md: expand docker instructions
stynoo Dec 18, 2024
1b48102
README.md: expand even more on docker compose install & execution met…
stynoo Dec 18, 2024
b1cc2e3
README.md: formatting
stynoo Dec 18, 2024
316c944
README.md: add normal docker instructions
stynoo Dec 18, 2024
bc90031
README.md: moved Obtaining Authorization to the relevant install sect…
stynoo Dec 18, 2024
71bbb59
README.md: add .withings_user.json to docker-compose section
stynoo Dec 18, 2024
b9343ec
update to latest packages
stynoo Dec 20, 2024
1d174b1
README.md: fix some issues in the readme that prevent proper auth
stynoo Dec 20, 2024
198591c
pyproject.toml: make sure we sync and fill all entries with the old s…
stynoo Dec 20, 2024
ac82ad3
Dockerfile: optimize layers
stynoo Dec 20, 2024
7e4944c
README.md: add logging to the docker compose method
stynoo Dec 22, 2024
f124b7e
README.md: more formatting
stynoo Dec 22, 2024
db3a1c2
README.md: even more formatting
stynoo Dec 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]
longstone marked this conversation as resolved.
Show resolved Hide resolved
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')
stynoo marked this conversation as resolved.
Show resolved Hide resolved
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
stynoo marked this conversation as resolved.
Show resolved Hide resolved

ENTRYPOINT ["poetry", "run", "withings-sync"]
13 changes: 5 additions & 8 deletions contrib/do_release.sh
stynoo marked this conversation as resolved.
Show resolved Hide resolved
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