-
Notifications
You must be signed in to change notification settings - Fork 7
Fix async life cycle management to prevent lost references to tasks. - #157 #158
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b9c38ea
Fix async life cycle management to prevent lost references to tasks.
sebastiaan-la-fleur 12f9300
Simplify some of the life cycle management in send_msg_and_await_rece…
sebastiaan-la-fleur 47a6091
Allow a number of linting and typing violations under tests/
sebastiaan-la-fleur 44d01ec
Unit test tweaks for linter and typechecker.
sebastiaan-la-fleur 3d08ee1
Add an AGENTS.md and change github workflow to fix issue with tox and…
sebastiaan-la-fleur 44d79e2
Update dev-requirements.txt to work with python3.9 instead of 3.11
sebastiaan-la-fleur 52ffaa7
Simplify CI significantly, improve it across python versions and run …
sebastiaan-la-fleur 0f27a8e
Update setuptools.
sebastiaan-la-fleur 7b7fa4e
Add a prepare step to github ci so the pip cache can do its job.
sebastiaan-la-fleur File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| name: Check Python | ||
|
|
||
| on: | ||
| workflow_call: | ||
| inputs: | ||
| python-version: | ||
| required: true | ||
| type: string | ||
|
|
||
| jobs: | ||
| prepare: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - uses: actions/setup-python@v4 | ||
| with: | ||
| python-version: ${{ inputs.python-version }} | ||
| cache: pip | ||
| cache-dependency-path: dev-requirements.txt | ||
| - name: Cache development dependencies | ||
| run: python -m pip install -r dev-requirements.txt | ||
|
|
||
| build: | ||
| needs: prepare | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| with: {fetch-depth: 0} # deep clone for setuptools-scm | ||
| - uses: actions/setup-python@v4 | ||
| with: | ||
| python-version: ${{ inputs.python-version }} | ||
| cache: pip | ||
| cache-dependency-path: dev-requirements.txt | ||
| - name: Install development dependencies | ||
| run: python -m pip install -r dev-requirements.txt | ||
| - name: Check package builds | ||
| run: python -m tox -e build | ||
|
|
||
| test: | ||
| needs: prepare | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - uses: actions/setup-python@v4 | ||
| with: | ||
| python-version: ${{ inputs.python-version }} | ||
| cache: pip | ||
| cache-dependency-path: dev-requirements.txt | ||
| - name: Install development dependencies | ||
| run: python -m pip install -r dev-requirements.txt | ||
| - name: Run tests | ||
| run: python -m tox --develop | ||
|
|
||
| lint: | ||
| needs: prepare | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - uses: actions/setup-python@v4 | ||
| with: | ||
| python-version: ${{ inputs.python-version }} | ||
| cache: pip | ||
| cache-dependency-path: dev-requirements.txt | ||
| - name: Install development dependencies | ||
| run: python -m pip install -r dev-requirements.txt | ||
| - name: Run lint | ||
| run: python -m tox -e lint --develop | ||
|
|
||
| typecheck: | ||
| needs: prepare | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - uses: actions/setup-python@v4 | ||
| with: | ||
| python-version: ${{ inputs.python-version }} | ||
| cache: pip | ||
| cache-dependency-path: dev-requirements.txt | ||
| - name: Install development dependencies | ||
| run: python -m pip install -r dev-requirements.txt | ||
| - name: Run typecheck | ||
| run: python -m tox -e typecheck --develop | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| # Project | ||
| - This project is a library, not an application. It is intended to be used as a dependency in other projects. | ||
| - This project defines a python version for the S2 network protocol. | ||
| - We use semantic versioning for this project. The version number is defined in `pyproject.toml` and should be updated with each release. | ||
| - Our interface to users is: | ||
| - Message definitions for the S2 network protocol that live in `s2python/{common,ddbc,frbc,ombc,pebc,ppbc}/.` | ||
| - We use an openapi specification to generate the message definitions. The generated code is in `s2python/generated`. | ||
| - We do not alter generated code manually. If we need to change the generated code, we change the openapi specification and regenerate the code. | ||
| - The openapi specifications lives in `specification/` and is based on the official `s2-json` repository. | ||
| - Connection classes that run on top of some Medium (e.g. TCP, UDP, WebSocket, etc.) and handle the S2 network protocol that live in `s2python/connection/`. | ||
| - Standard medium definitions for websocket and other connections that live in `s2python/connection/{async_,sync}/medium`. | ||
| - Example scripts under the `examples/` folder. | ||
|
|
||
| # Python | ||
| - We use Python 3.9 as the earliest python to support. | ||
| - We use Python 3.14 as the latest python to support. | ||
|
|
||
| # Poetry | ||
| - This is a library, do not pin any dependencies in pyproject.toml that break dependency management for downstream users. | ||
| - Feel free to use a pin that defines a minimum version of a dependency, but do not pin to a specific version. | ||
| - `poetry.lock` is checked in to the repository to ensure reproducible builds for development and testing but this is NOT the same environment users use. | ||
|
|
||
| # Development | ||
| - You have development tooling available under `ci/` that you can use to run linters, formatters, type checkers, and unit tests: | ||
| - `lint.sh`: Run the linters and formatters. | ||
| - `test_unit.sh`: Run the unit tests. | ||
| - `typecheck.sh`: Run the type checkers. | ||
| - `update_dependencies.sh`: Update dependencies in poetry.lock based on pyproject.toml. | ||
| - `generate_s2.sh`: Generate the S2 message definitions from the openapi specification. | ||
| - `clean.sh`: Remove all generated files and build artifacts that are not in the git tree but locally available. | ||
| - `setup_dev_environment.sh`: Set up the development environment with an initial virtual environment. Dependencies still need to be installed with `install_dependencies.sh`. | ||
| - `install_dependencies.sh`: Install dev dependencies in the virtual environment. | ||
| - Library source lives under `src/s2python`. | ||
|
|
||
| # Unit Testing | ||
| - Use `ci/test_unit.sh` directly for unit testing instead of `python -m pytest`. | ||
| - Use #Arrange, # Act, #Assert comments to separate the three phases of a unit test. | ||
| - Test only one function per test file. If a function has multiple behaviors, create multiple test files for that function. | ||
| - Use `pytest.mark.parametrize` to test multiple inputs and outputs for a single function if it simplifies code and reduces duplication. | ||
| - Do not overcomplicate. If parametrize leads to a test that is hard to read, break it into multiple tests instead. | ||
| - Unit tests live under `tests/unit/`. | ||
| - Mimic the folder structure under `src.` | ||
| - Unit test functions should be named according to `test__<function under test>__<behavior being tested>`. | ||
| - Unit tests should use type hints as well. | ||
|
|
||
| # Typehinting | ||
| - Use `ci/typecheck.sh` for type checking. | ||
| - We want to satisfy both pyright and mypy. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,6 @@ | ||
| #!/usr/bin/env sh | ||
|
|
||
| set -e | ||
| . .venv/bin/activate | ||
| pylint src/ tests/unit/ examples/ | ||
| pylint src/ examples/ | ||
| PYTHONPATH="src:$PYTHONPATH" pylint --disable=protected-access,invalid-overridden-method tests/unit/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| #!/bin/bash | ||
|
|
||
| python3.8 -m venv ./.venv/ | ||
| python3.9 -m venv ./.venv/ | ||
| . ./.venv/bin/activate | ||
| pip install pip-tools |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| #!/usr/bin/env sh | ||
|
|
||
| . .venv/bin/activate | ||
| PYTHONPATH="$PYTHONPATH:src/" pytest --cov=s2python --cov-report=html:./unit_test_coverage/ -v tests/unit/ | ||
| PYTHONPATH="$PYTHONPATH:src/" pytest --cov=s2python --cov-report=html:./unit_test_coverage/ -v tests/unit/ $@ | ||
|
sebastiaan-la-fleur marked this conversation as resolved.
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| #!/usr/bin/env sh | ||
|
|
||
| . .venv/bin/activate | ||
| mypy --config-file mypy.ini src/ ./tests/unit/ examples/ | ||
| pyright | ||
| status=0 | ||
| mypy --config-file mypy.ini src/ ./tests/unit/ examples/ || status=1 | ||
| pyright || status=1 | ||
| exit "$status" |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for also fixing CI in this PR, but we were running into some annoying issues that prevented the actual fix from succeeding in CI.