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

✨ Refactor CI workflow to run unit and integration tests #2

Merged
merged 16 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
9710d85
✨ Refactor CI workflow to run unit and integration tests, and remove …
grelinfo Nov 27, 2024
6a1b141
✨ Update README and documentation to replace TaskManager with sync_ba…
grelinfo Nov 27, 2024
7d20492
✨ Update pre-commit configuration to set default Python version to 3.…
grelinfo Nov 27, 2024
4ea4e13
✨ Refactor CI workflow to rename pre-commit job to lint, run mypy che…
grelinfo Nov 27, 2024
2126360
✨ Update CI workflow to run mypy checks on the current directory and …
grelinfo Nov 27, 2024
1400906
✨ Update CI workflow and pre-commit configuration to include uv-lock …
grelinfo Nov 27, 2024
4d9d6c8
✨ Update CI workflow to improve linting process and adjust pre-commit…
grelinfo Nov 27, 2024
612aceb
✨ Update CI workflow to enable fail-fast strategy and modify pytest c…
grelinfo Nov 27, 2024
62c6156
✨ Update CI workflow to set UV_LOCKED environment variable and remove…
grelinfo Nov 27, 2024
c2560b5
✨ Update CI workflow to include uv lockfile check and adjust dependen…
grelinfo Nov 27, 2024
755371f
✨ Remove uv lockfile check from CI workflow
grelinfo Nov 27, 2024
3b9ae26
✨ Update CI workflow with lint job name and add docker as a dev depen…
grelinfo Nov 27, 2024
000f609
✨ Refactor backend tests to use Docker containers for Redis and Postg…
grelinfo Nov 27, 2024
6d5ad86
✨ Refactor backend test container setup to remove hardcoded environme…
grelinfo Nov 27, 2024
938fdd4
✨ Adjust timeout for tests and correct port assignments for Redis and…
grelinfo Nov 27, 2024
d6e58fb
✨ Update pytest configuration to enforce coverage threshold and fix s…
grelinfo Nov 27, 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
19 changes: 10 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ on:
pull_request:
branches: ["main"]

env:
UV_SYSTEM_PYTHON: 1

jobs:
pre-commit:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand All @@ -24,14 +22,14 @@ jobs:
- name: Install dependencies
run: uv sync --all-extras

- name: Run pre-commit
run: uv run pre-commit run --all-files
- name: Run Mypy
run: uv run mypy .

test:
name: Test Python ${{ matrix.python }}
runs-on: "ubuntu-latest"
strategy:
fail-fast: false
fail-fast: true
matrix:
python: ["3.11", "3.12", "3.13"]
steps:
Expand All @@ -46,8 +44,11 @@ jobs:
- name: Install dependencies
run: uv sync --all-extras --python ${{ matrix.python }}

- name: Test with pytest
run: uv run pytest
- name: Run unit tests
run: uv run pytest -x

- name: Run integration tests
run: uv run pytest -x -m integration --cov-append

- name: Rename coverage report
run: mv .coverage .coverage.py${{ matrix.python }}
Expand Down
33 changes: 24 additions & 9 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
default_language_version:
python: python3.11

repos:

- repo: https://github.com/pre-commit/pre-commit-hooks
Expand All @@ -9,11 +12,6 @@ repos:
- id: check-added-large-files
- id: trailing-whitespace

- repo: https://github.com/astral-sh/uv-pre-commit
rev: 0.5.4
hooks:
- id: uv-lock

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.8.0
hooks:
Expand All @@ -28,6 +26,22 @@ repos:

- repo: local
hooks:

- id: readme-to-docs
name: readme-to-docs
description: "Copy README.md to docs/index.md"
entry: cp README.md docs/index.md
language: system
pass_filenames: false

# --- Local development hooks ---
- id: uv-lock
name: uv-lock
description: "Lock dependencies with 'uv lock'"
entry: uv lock
language: system
pass_filenames: false

- id: mypy
name: mypy
description: "Run 'mypy' for static type checking"
Expand All @@ -36,13 +50,14 @@ repos:
types: [python]
require_serial: true

- id: readme-to-docs
name: readme-to-docs
description: "Copy README.md to docs/index.md"
entry: cp README.md docs/index.md
- id: pytest
name: pytest
description: "Run 'pytest' for unit testing"
entry: uv run pytest --cov-fail-under=90
language: system
pass_filenames: false

ci:
autofix_commit_msg: 🎨 [pre-commit.ci] Auto format from pre-commit.com hooks
autoupdate_commit_msg: ⬆ [pre-commit.ci] pre-commit autoupdate
skip: [uv-lock, mypy, pytest]
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ from grelmicro.task import TaskManager
async def lifespan(app):
configure_logging()
# Start the lock backend and task manager
async with lock_backend, task:
async with sync_backend, task:
yield


Expand All @@ -104,7 +104,7 @@ def read_root():

# === Grelmicro ===
task = TaskManager()
lock_backend = RedisSyncBackend("redis://localhost:6379/0")
sync_backend = RedisSyncBackend("redis://localhost:6379/0")

# --- Ensure that only one say hello world at the same time ---
lock = Lock("say_hello_world")
Expand Down
4 changes: 2 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ from grelmicro.task import TaskManager
async def lifespan(app):
configure_logging()
# Start the lock backend and task manager
async with lock_backend, task:
async with sync_backend, task:
yield


Expand All @@ -104,7 +104,7 @@ def read_root():

# === Grelmicro ===
task = TaskManager()
lock_backend = RedisSyncBackend("redis://localhost:6379/0")
sync_backend = RedisSyncBackend("redis://localhost:6379/0")

# --- Ensure that only one say hello world at the same time ---
lock = Lock("say_hello_world")
Expand Down
4 changes: 2 additions & 2 deletions examples/simple_fastapi_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
async def lifespan(app):
configure_logging()
# Start the lock backend and task manager
async with lock_backend, task:
async with sync_backend, task:
yield


Expand All @@ -28,7 +28,7 @@ def read_root():

# === Grelmicro ===
task = TaskManager()
lock_backend = RedisSyncBackend("redis://localhost:6379/0")
sync_backend = RedisSyncBackend("redis://localhost:6379/0")

# --- Ensure that only one say hello world at the same time ---
lock = Lock("say_hello_world")
Expand Down
2 changes: 1 addition & 1 deletion grelmicro/sync/_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class LoadedBackendsDict(TypedDict):
loaded_backends: LoadedBackendsDict = {}


def get_lock_backend() -> SyncBackend:
def get_sync_backend() -> SyncBackend:
"""Get the lock backend."""
backend: Literal["lock"] = "lock"
try:
Expand Down
4 changes: 2 additions & 2 deletions grelmicro/sync/leaderelection.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from pydantic import BaseModel, model_validator
from typing_extensions import Doc

from grelmicro.sync._backends import get_lock_backend
from grelmicro.sync._backends import get_sync_backend
from grelmicro.sync.abc import Seconds, SyncBackend, Synchronization
from grelmicro.task.abc import Task

Expand Down Expand Up @@ -218,7 +218,7 @@ def __init__(
backend_timeout=backend_timeout,
error_interval=error_interval,
)
self.backend = backend or get_lock_backend()
self.backend = backend or get_sync_backend()

self._service_running = False
self._state_change_condition: Condition = Condition()
Expand Down
4 changes: 2 additions & 2 deletions grelmicro/sync/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from anyio import WouldBlock, from_thread, sleep
from typing_extensions import Doc

from grelmicro.sync._backends import get_lock_backend
from grelmicro.sync._backends import get_sync_backend
from grelmicro.sync._base import BaseLock, BaseLockConfig
from grelmicro.sync._utils import generate_task_token, generate_thread_token
from grelmicro.sync.abc import Seconds, SyncBackend
Expand Down Expand Up @@ -106,7 +106,7 @@ def __init__(
lease_duration=lease_duration,
retry_interval=retry_interval,
)
self.backend = backend or get_lock_backend()
self.backend = backend or get_sync_backend()
self._from_thread: ThreadLockAdapter | None = None

async def __aenter__(self) -> Self:
Expand Down
89 changes: 0 additions & 89 deletions manager.py

This file was deleted.

13 changes: 5 additions & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ requires-python = ">=3.11"

dependencies = [
"anyio>=4.0.0",
"pydantic>=2.0.0",
"pydantic>=2.5.0",
"fast-depends>=2.0.0",
"pydantic-settings>=2.6.1",
"pydantic-settings>=2.5.0",
]

[project.urls]
Expand All @@ -64,20 +64,18 @@ dev = [
"pytest>=8.0.0",
"mypy>=1.12.0",
"ruff>=0.7.4",
"testcontainers[postgres,redis]>=4.8.0",
"testcontainers[postgres,redis]>=4.8.2",
"pytest-timeout>=2.3.1",
"pytest-mock>=3.14.0",
"pytest-randomly>=3.16.0",
"pre-commit>=4.0.1",
"fastapi>=0.115.5",
"fastapi-cli>=0.0.5",
"mdformat-ruff>=0.1.3",
"mdx-include>=1.4.2",
"faststream>=0.5.30",
"hatch>=1.13.0",
]
docs = [
"mike>=2.1.3",
"mkdocs-material>=9.5.44",
"pygments>=2.18.0",
"pymdown-extensions>=10.12",
Expand Down Expand Up @@ -154,15 +152,14 @@ disallow_untyped_defs = false
[tool.pytest.ini_options]
addopts = """
--cov=grelmicro
--cov-fail-under=90
--cov-report term:skip-covered
--cov-report xml:cov.xml
--strict-config
--strict-markers
-m "not testcontainers"
-m "not integration"
"""
markers = """
testcontainers: mark a test that requires testcontainers
integration: mark a test as an integration test (disabled by default).
"""

testpaths = "tests"
Expand Down
Loading