Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
150 changes: 29 additions & 121 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,22 @@ on:
- '**'
pull_request: {}

permissions:
contents: read

jobs:
lints:
name: Code lints
runs-on: ubuntu-latest
steps:
#----------------------------------------------
# check-out repo and set-up python
#----------------------------------------------
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: 3.8
#----------------------------------------------
# load pip cache if cache exists
#----------------------------------------------
- uses: actions/cache@v2
- uses: actions/checkout@v7
- uses: astral-sh/setup-uv@v7
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip
restore-keys: ${{ runner.os }}-pip
#----------------------------------------------
# install and run linters
#----------------------------------------------
- run: python -m pip install black flake8 isort mypy pytest
- run: |
flake8 mediator/ example/
black mediator/ example/ --check
isort mediator/ example/ --check
mypy mediator/ example/
enable-cache: true
- run: uv sync --locked
- run: uv run ruff check .
- run: uv run ruff format --check .
- run: uv run mypy

tests:
needs: [lints]
Expand All @@ -45,113 +32,34 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10', 'pypy-3.7']
env:
PYTHONPATH: .
PYTHON: ${{ matrix.python-version }}

python-version: ['3.11', '3.12', '3.13', '3.14', 'pypy3.11']
steps:
#----------------------------------------------
# check-out repo and set-up environment
#----------------------------------------------
- uses: actions/checkout@v2
- name: Set up python ${{ matrix.python-version }}
uses: actions/setup-python@v2
- uses: actions/checkout@v7
- uses: astral-sh/setup-uv@v7
with:
enable-cache: true
python-version: ${{ matrix.python-version }}
- uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
#----------------------------------------------
# setup only test dependencies
#----------------------------------------------
- name: Remove lint dependencies
run: |
mv pyproject.toml ~pyproject.toml
cat ~pyproject.toml | sed '/^mypy =/d' | sed '/^black =/d' | sed '/^isort =/d' | sed '/^flake8[a-zA-Z-]* =/d' > pyproject.toml
- name: Install dependencies
run: poetry install --no-interaction --no-root
#----------------------------------------------
# run tests with code coverage
#----------------------------------------------
- name: Run tests
run: |
source .venv/bin/activate
pytest mediator/ example/ --cov
env:
COVERAGE_FILE: coverage/.coverage.py${{ matrix.python-version }}
#----------------------------------------------
# store code coverage
#----------------------------------------------
- name: Store coverage files
uses: actions/upload-artifact@v2
with:
name: coverage
path: coverage

coverage-upload:
needs: [tests]
name: Coverage upload
runs-on: ubuntu-latest
steps:
#----------------------------------------------
# setup environment
#----------------------------------------------
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Setup depdendencies
run: pip install coverage
#----------------------------------------------
# prepare coverage data
#----------------------------------------------
- name: Get coverage files
uses: actions/download-artifact@v2
with:
name: coverage
path: coverage
- name: Combine coverage files
run: |
coverage combine coverage
coverage report
coverage xml
#----------------------------------------------
# upload code coverage
#----------------------------------------------
- run: uv sync --locked --no-dev --group test
- run: uv run --no-sync pytest --cov --cov-report=xml
- name: Upload coverage
uses: codecov/codecov-action@v1
uses: codecov/codecov-action@v7
with:
file: ./coverage.xml
fail_ci_if_error: true
files: coverage.xml
flags: py${{ matrix.python-version }}
token: ${{ secrets.CODECOV_TOKEN }}

build-deploy:
name: Build & deploy
needs: [lints, tests]
if: "success() && startsWith(github.ref, 'refs/tags/')"
env:
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}

runs-on: ubuntu-latest
environment: pypi
permissions:
contents: read
# required for PyPI trusted publishing
id-token: write
steps:
#----------------------------------------------
# check-out repo and set-up python
#----------------------------------------------
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: 3.8
- uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
- name: Configure poetry credentials
run: |
poetry config pypi-token.pypi "${PYPI_TOKEN}"
#----------------------------------------------
# build and deploy with poetry
#----------------------------------------------
- name: Build & deploy
run: |
poetry publish --build
- uses: actions/checkout@v7
- uses: astral-sh/setup-uv@v7
- run: uv build
- run: uv publish
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
**/__pycache__
.idea/**
.pytest_cache/**
.venv/
dist/
.coverage*
coverage.xml
.mypy_cache/
.ruff_cache/
44 changes: 44 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Changelog

## 0.8.0

Requires Python 3.11 or newer.

### Added
- Type information is shipped with the package (`py.typed`), checked with strict mypy.
- `Request[R]` optional base class - `execute` returns precise result type for it.
- Event dispatchers: `BackgroundEventDispatcher` (default) and `AwaitingEventDispatcher`,
custom ones can be provided by `LocalEventBus(dispatcher=...)`.
- `LocalEventBus.drain()` waits until background event handlers are finished.
- Handler annotated with union of types (`A | B`) is registered for all of them.
- Main names can be imported directly from `mediator` package.

### Changed
- `LocalEventBus(sync_mode=True)` is replaced by
`LocalEventBus(dispatcher=AwaitingEventDispatcher())`.
Handler errors are raised from `publish` as `ExceptionGroup`.
- Background event handler errors are logged (or passed to `on_error` callable)
instead of being lost.
- Interfaces (`Handler`, `HandlerStore`, `HandlerFactory`, `ModifierFactory`,
`EventPublish`, `EventPublisher`, `EventSubscriber`, `RequestExecutor`)
are `typing.Protocol` classes. Inheriting from them still works.
- `ModifierFactory.create(call, *, target)` - target is explicit keyword argument
instead of being part of `**kwargs`.
- `HandlerFactory.create` and `HandlerFactoryCascade.__call__` return
sequence of handlers instead of single one.
- `ActionSubject`, `ActionResult`, `HandlerEntry`, policies and inspection records
are immutable.
- Helper classes of `mediator.common.factory.utils` are replaced by functions.
- `LocalRequestBus.execute` raises `TypeError` instead of `AssertionError`
when modifier does not return `ActionResult`.
- `mediator.utils.context.AsyncNullContextManager` is removed,
use `contextlib.nullcontext`.

### Fixed
- Publishing event without handlers failed with `ValueError` in sync mode.
- Background event handler task could be garbage collected before it finished.
- `include()` given one-shot iterator stored handlers but never called them.
- Handler taking subject as keyword argument leaked it
into extra arguments of other handlers of the same event.
- Annotation that cannot be resolved (i.e. `TYPE_CHECKING` only import)
on argument other than subject failed handler registration.
Loading
Loading