Skip to content

Commit b06b673

Browse files
authored
refactor: rewrite API models & commit logic (#214)
* deps: modernize dev tooling (#213) * Raise Python version requirement to 3.12 * Raise Python version in CI * Update GitHub actions * Add workflow for linting GitHub CI * Modernize dev tools & update dependencies * Apply Ruff * Replace deque import * Try fix pre-commit * Improve typing for decorator * Replace deprecated utcnow * Update test * Fix errors * Refactor IntEnum * Try out Pydantic * Create separate API object model * Use Annotated * Refactor * Update test * Refactor tests & add additional checks * Use Pydantic for History API models and applying updates * Implement commit * Update example * Replace create & edit with unified commit method * Update usage * Update tests
1 parent 234eacb commit b06b673

File tree

17 files changed

+1648
-1240
lines changed

17 files changed

+1648
-1240
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Lint GitHub CI
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
paths:
8+
- .github/**
9+
- actions/**
10+
11+
jobs:
12+
actionlint:
13+
name: actionlint
14+
runs-on: ubuntu-22.04
15+
steps:
16+
- name: Lint actions and workflows
17+
uses: bakdata/ci-templates/actions/action-lint@1.46.3
18+
with:
19+
action-lint-version: "v1.6.27"

.github/workflows/pre-commit-auto-update.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ jobs:
1010
runs-on: ubuntu-latest
1111

1212
steps:
13-
- uses: actions/checkout@v3
13+
- uses: actions/checkout@v4
1414

1515
- name: Set up Python
16-
uses: actions/setup-python@v4
16+
uses: actions/setup-python@v5
1717
with:
18-
python-version: "3.10"
18+
python-version: "3.12"
1919

2020
- name: Install pre-commit
2121
run: pip install pre-commit

.github/workflows/python-app.yml

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,19 @@ jobs:
1313
fail-fast: false
1414
matrix:
1515
python-version:
16-
- "3.10"
16+
- "3.12"
1717

1818
steps:
19-
- uses: actions/checkout@v3
19+
- uses: actions/checkout@v4
2020

21-
- name: Install poetry
21+
- name: Install Poetry
2222
run: pipx install poetry
2323

24-
- name: Configure poetry virtualenv
24+
- name: Configure Poetry virtualenv
2525
run: poetry config virtualenvs.in-project true
2626

2727
- name: Set up Python ${{ matrix.python-version }}
28-
uses: actions/setup-python@v4
28+
uses: actions/setup-python@v5
2929
with:
3030
python-version: ${{ matrix.python-version }}
3131
cache: poetry
@@ -35,22 +35,17 @@ jobs:
3535
- name: Install dependencies
3636
run: poetry install --no-interaction
3737

38-
- name: Lint flake8
39-
run: |
40-
poetry run pre-commit run --hook-stage manual flake8 --all-files --show-diff-on-failure
38+
- name: Check Poetry config and lockfile
39+
run: poetry run pre-commit run poetry-check --all-files
4140

42-
- name: Check black
43-
run: |
44-
poetry run pre-commit run --hook-stage manual black --all-files --show-diff-on-failure
41+
- name: Lint (ruff)
42+
run: poetry run ruff check . --config pyproject.toml --output-format=github --no-fix
4543

46-
- name: Check mypy
47-
run: |
48-
poetry run pre-commit run --hook-stage manual mypy --all-files
44+
- name: Formatting (ruff)
45+
run: poetry run pre-commit run ruff-format --all-files --show-diff-on-failure
4946

50-
- name: Check syntax update
51-
run: |
52-
poetry run pre-commit run --hook-stage manual pyupgrade --all-files
47+
- name: Typing (pyright)
48+
run: poetry run pre-commit run pyright --all-files
5349

54-
- name: Test pytest
55-
run: |
56-
poetry run pytest
50+
- name: Test
51+
run: poetry run pytest tests

.github/workflows/python-publish.yml

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,27 @@ jobs:
1010
runs-on: ubuntu-latest
1111

1212
steps:
13-
- uses: actions/checkout@v3
13+
- uses: actions/checkout@v4
1414

1515
- name: Set up Python
16-
uses: actions/setup-python@v4
16+
uses: actions/setup-python@v5
1717
with:
18-
python-version: "3.10"
18+
python-version: "3.12"
1919

2020
- name: Get Python version
2121
id: python-version
22-
run: echo ::set-output name=version::"$(python -c "import sys; print('-'.join(str(v) for v in sys.version_info))")"
22+
run: echo version="$(python -c "import sys; print('-'.join(str(v) for v in sys.version_info))")" >> "$GITHUB_OUTPUT"
2323

24-
- name: Run poetry image
25-
uses: abatilo/actions-poetry@v3.0.0
24+
- name: Run Poetry image
25+
uses: abatilo/actions-poetry@v3.0.1
2626
with:
2727
poetry-version: "1.1.12"
2828

29-
- name: Set poetry virtualenv
29+
- name: Set Poetry virtualenv
3030
run: poetry config virtualenvs.in-project true
3131

3232
- name: Set up cache
33-
uses: actions/cache@v3
33+
uses: actions/cache@v4
3434
id: cache
3535
with:
3636
path: .venv
@@ -47,8 +47,7 @@ jobs:
4747
# - name: Bump version
4848
# env:
4949
# VERSION: ${{ github.event.release.tag_name }}
50-
# run: |
51-
# poetry version $(echo $VERSION | sed -e 's/^v//')
50+
# run: poetry version $(echo $VERSION | sed -e 's/^v//')
5251

5352
- name: Build
5453
run: poetry build
@@ -58,11 +57,9 @@ jobs:
5857
POETRY_REPOSITORIES_TESTPYPI_URL: https://test.pypi.org/legacy/
5958
POETRY_HTTP_BASIC_TESTPYPI_USERNAME: __token__
6059
POETRY_HTTP_BASIC_TESTPYPI_PASSWORD: ${{ secrets.TEST_PYPI_API_TOKEN }}
61-
run: |
62-
poetry publish -r testpypi
60+
run: poetry publish -r testpypi
6361

6462
- name: Publish PyPI
6563
env:
6664
POETRY_PYPI_TOKEN_PYPI: ${{ secrets.PYPI_API_TOKEN }}
67-
run: |
68-
poetry publish
65+
run: poetry publish

.pre-commit-config.yaml

Lines changed: 44 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,47 @@
11
---
22
repos:
3-
- repo: https://github.com/pre-commit/pre-commit-hooks
4-
rev: v4.5.0
3+
- repo: local
54
hooks:
6-
- id: debug-statements
7-
- repo: https://github.com/asottile/pyupgrade
8-
rev: v3.15.1
9-
hooks:
10-
- id: pyupgrade
11-
stages: [manual]
12-
args: ["--py310-plus"]
13-
- repo: https://github.com/pycqa/isort
14-
rev: 5.13.2
15-
hooks:
16-
- id: isort
17-
args: ["--settings", "setup.cfg"]
18-
- repo: https://github.com/psf/black
19-
rev: 24.3.0
20-
hooks:
21-
- id: black
22-
language_version: python3
23-
- repo: https://github.com/pre-commit/mirrors-mypy
24-
rev: v1.9.0
25-
hooks:
26-
- id: mypy
27-
args: ["--pretty"]
28-
additional_dependencies: [types-python-dateutil, types-freezegun]
29-
- repo: https://github.com/pycqa/flake8
30-
rev: 7.0.0
31-
hooks:
32-
- id: flake8
33-
args: ["--config", "setup.cfg"]
5+
- id: poetry-install
6+
name: poetry-install
7+
description: install Poetry dependencies from the lock file
8+
entry: poetry install
9+
language: python
10+
pass_filenames: false
11+
stages: [post-checkout, post-merge]
12+
always_run: true
13+
- id: poetry-check
14+
name: poetry-check
15+
description: validate Poetry config and dependency lock file
16+
entry: poetry check
17+
language: python
18+
pass_filenames: false
19+
files: ^(.*/)?(pyproject\.toml|poetry\.lock)$
20+
- id: ruff-lint
21+
name: ruff-lint
22+
entry: poetry run ruff check
23+
args:
24+
[
25+
--force-exclude,
26+
--config,
27+
pyproject.toml,
28+
--fix,
29+
--show-fixes,
30+
--exit-non-zero-on-fix,
31+
]
32+
language: system
33+
types_or: [python]
34+
require_serial: true # run once for all files
35+
- id: ruff-format
36+
name: ruff-format
37+
entry: poetry run ruff format
38+
args: [--force-exclude, --config, pyproject.toml]
39+
language: system
40+
types_or: [python]
41+
require_serial: true # run once for all files
42+
- id: pyright
43+
name: pyright
44+
entry: poetry run pyright
45+
language: system
46+
types: [python]
47+
require_serial: true # run once for all files

README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,23 @@ OFFSET = 1234
2525
OFFSET = None
2626

2727
things = ThingsClient(ACCOUNT, initial_offset=OFFSET)
28-
# create a project
29-
project = TodoItem("Things Cloud Project").as_project()
28+
# create a new project
29+
project = TodoItem(title="Things Cloud Project").as_project()
3030
# push to Things Cloud
31-
things.create(project)
31+
things.commit(project)
3232

3333
# create a todo inside project
34-
todo = TodoItem("Try out Things Cloud")
34+
todo = TodoItem(title="Try out Things Cloud")
3535
todo.project = project
36-
things.create(todo)
36+
things.commit(todo)
3737

3838
# schedule for today
3939
todo.today()
40-
things.edit(todo)
40+
things.commit(todo)
4141
```
4242

43+
See [main.py](main.py).
44+
4345
### Progress
4446

4547
- [x] Todos

main.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,21 @@
1515
def main():
1616
things = ThingsClient(ACCOUNT, initial_offset=OFFSET)
1717

18-
# create a project
19-
project = TodoItem("Things Cloud Project").as_project()
20-
things.create(project)
18+
# create a new project
19+
project = TodoItem(title="Things Cloud Project").as_project()
20+
things.commit(project)
2121
log.debug("created project", uuid=project.uuid)
2222

2323
sleep(10)
2424
# create a todo inside project
25-
todo = TodoItem("Try out Things Cloud")
25+
todo = TodoItem(title="Try out Things Cloud")
2626
todo.project = project
27-
things.create(todo)
27+
things.commit(todo)
2828

2929
sleep(10)
3030
# schedule for today
3131
todo.today()
32-
things.edit(todo)
32+
things.commit(todo)
3333

3434

3535
if __name__ == "__main__":

0 commit comments

Comments
 (0)