Skip to content

Commit

Permalink
Update to Atoti Python API 0.8.9 (#264)
Browse files Browse the repository at this point in the history
  • Loading branch information
tibdex authored Feb 14, 2024
1 parent a93757a commit b774b7b
Show file tree
Hide file tree
Showing 20 changed files with 359 additions and 604 deletions.
4 changes: 2 additions & 2 deletions .github/actions/setup/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ description: Set up Python, install Poetry and the dependencies
runs:
using: "composite"
steps:
- run: pipx install poetry==1.7.0
- run: pipx install poetry==1.7.1
shell: bash
- uses: actions/setup-python@v5
with:
cache: poetry
python-version: "3.9"
python-version: "3.9.18"
- run: poetry install
shell: bash
9 changes: 5 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup
- run: poetry run app format --check
- run: poetry run app lint --check
- run: poetry run app typecheck
- run: poetry run app test
- run: poetry check --lock
- run: poetry run ruff format --check
- run: poetry run ruff check
- run: poetry run mypy
- run: poetry run pytest
4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
__pycache__/
.docker/
.mypy_cache/
.pytest_cache/
.venv/
content/
7 changes: 3 additions & 4 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@
"editor.defaultFormatter": "charliermarsh.ruff",
"editor.formatOnType": true
},
"[toml]": {
"editor.defaultFormatter": "tamasfe.even-better-toml"
},
"files.insertFinalNewline": true,
"files.trimFinalNewlines": true,
"files.trimTrailingWhitespace": true,
"python.analysis.autoImportCompletions": true,
"python.languageServer": "Pylance",
"python.testing.pytestArgs": [
"--capture=no",
"--verbose"
],
"python.testing.pytestEnabled": true,
"python.testing.unittestEnabled": false
}
11 changes: 6 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
# syntax=docker/dockerfile:1.2
FROM python:3.9.12-slim AS builder

RUN --mount=type=cache,target=/root/.cache pip install poetry==1.7.0
RUN poetry config virtualenvs.create false
# `--platform=linux/am64` is required to build this image on macOS with Apple Silicon until https://github.com/activeviam/jdk4py/issues/73 is done.

This comment has been minimized.

Copy link
@tibdex

tibdex Jun 5, 2024

Author Member
FROM --platform=linux/amd64 python:3.9.18-slim AS builder

RUN pip install poetry==1.7.1

COPY poetry.lock pyproject.toml ./

RUN --mount=type=cache,target=/root/.cache poetry install --no-root --only main --sync
RUN POETRY_VIRTUALENVS_CREATE=false poetry install --no-cache --no-root --only main --sync

FROM python:3.9.12-slim AS runner
FROM --platform=linux/amd64 python:3.9.18-slim AS runner

ENV ATOTI_HIDE_EULA_MESSAGE=true
ENV PORT=80
Expand Down
28 changes: 5 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ This template can be used to start Atoti projects where the goal is to [go into
On top of the `atoti` package, it comes with:

- Dependency management with [Poetry](https://python-poetry.org)
- Settings management with [Pydantic](https://docs.pydantic.dev/2.5/concepts/pydantic_settings)
- Config management with [Pydantic Settings](https://docs.pydantic.dev/2.6/concepts/pydantic_settings)
- Testing with [pytest](https://docs.pytest.org)
- Type checking with [mypy](http://mypy-lang.org)
- Formatting and linting with [Ruff](https://beta.ruff.rs)
- Formatting and linting with [Ruff](https://docs.astral.sh/ruff)
- Continuous testing with [GitHub Actions](https://github.com/features/actions)

## Usage
Expand All @@ -24,31 +24,13 @@ On top of the `atoti` package, it comes with:

### Commands

To get a list of the commands that can be executed to interact with the project, run:
To start the app:

```bash
poetry run app --help
poetry run python -m main
```

A few examples:

- Start the app:

```bash
poetry run app start
```

- Launch the tests:

```bash
poetry run app test
```

- Reformat the code:

```bash
poetry run app format
```
Other useful commands can be found in [`test.yml`](.github/workflows/test.yml).

## Variants

Expand Down
2 changes: 1 addition & 1 deletion app/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from __future__ import annotations

from .app import *
from .config import *
from .constants import *
from .start_app import *
10 changes: 4 additions & 6 deletions app/__main__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
from __future__ import annotations

from . import App, Config
from . import Config, start_app

config = Config()

with App(config=config) as app:
print(f"Session listening on port {app.session.port}") # noqa: T201
app.session.wait()
with start_app(config=Config()) as session:
print(f"Session listening on port {session.port}") # noqa: T201
session.wait()
47 changes: 0 additions & 47 deletions app/app.py

This file was deleted.

20 changes: 20 additions & 0 deletions app/start_app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from __future__ import annotations

from collections.abc import Generator
from contextlib import contextmanager, nullcontext

import atoti as tt

from .config import Config
from .load_tables import load_tables
from .start_session import start_session
from .util import run_periodically


@contextmanager
def start_app(*, config: Config) -> Generator[tt.Session, None, None]:
with start_session(config=config) as session, run_periodically(
lambda: load_tables(session, config=config),
period=config.data_refresh_period,
) if config.data_refresh_period else nullcontext():
yield session
10 changes: 7 additions & 3 deletions app/util/run_periodically.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
from __future__ import annotations

from collections.abc import Callable
from collections.abc import Callable, Generator
from contextlib import contextmanager
from datetime import timedelta
from threading import Event, Thread


@contextmanager
def run_periodically(
callback: Callable[[], None], /, *, daemon: bool | None = None, period: timedelta
) -> Callable[[], None]:
) -> Generator[None, None, None]:
period_in_seconds = period.total_seconds()
stopped = Event()

Expand All @@ -17,4 +19,6 @@ def loop() -> None:

Thread(target=loop, daemon=daemon).start()

return stopped.set
yield

stopped.set()
6 changes: 0 additions & 6 deletions cli/__init__.py

This file was deleted.

12 changes: 0 additions & 12 deletions cli/_get_executable_path.py

This file was deleted.

23 changes: 0 additions & 23 deletions cli/_run_command.py

This file was deleted.

58 changes: 0 additions & 58 deletions cli/app.py

This file was deleted.

Loading

0 comments on commit b774b7b

Please sign in to comment.