I.e. dependencies needed for testing, building documentation, linting, etc. not needed to run the package.
pyproject.toml
[dependency-groups]dev=["pytest>=8.4.1",]
Dependency management using uv
Add a dependency:
$ uv add matplotlib
Remove a dependency:
$ uv remove seaborn
Add development dependency:
$ uv add --dev pytest
Creating an installable package
Create a new library project:
$ uv init --lib
Start a Python session:
$ uv run python
>>>import mini>>> mini.foo()42
Run tests:
$ uv run pytest...tests/test_foo.py . [100%]=============== 1 passed in 0.01s ===============
Virtual environments
Creates a clean environment for each project
Allows different versions of a package to coexist on your machine
Can be used to create a reproducible environment for a project
Virtual environments are managed by uv
Continuous Integration (CI)
Running tests on every commit in a well defined environment ensures that the code is working as expected.
It solves the βit works on my machineβ problem.
Executing code on a remote server is a good way to ensure that the code is working as expected.
Example of CI services:
GitHub Actions
Azure Pipelines
Travis CI
GitHub Actions
Workflow are stored in the .github/workflows folder.
Workflow is described in a YAML file.
YAML is whitespace sensitive (like Python).
YAML can contain lists, dictionaries and strings, and can be nested.
$ tree mikeio/.github/mikeio/.github/βββ workflowsβββ docs.ymlβββ full_test.ymlβββ notebooks_test.ymlβββ perf_test.ymlβββ python-publish.yml
Workflow example
name: Quick teston: # when to run the workflowpush:branches:[ main]pull_request:branches:[ main ]jobs: # which jobs to runbuild: # descriptive name πruns-on: ubuntu-latest # on what operating systemsteps:-uses: actions/checkout@v3-name: Set up uvuses: astral-sh/setup-uv@v6with:python-version:"3.13"-name: Install dependencies run: | uv sync-name: Test with pytest run: | uv run pytest
ππ
βΉοΈ
Benefits of CI
Run tests on every commit
Test on different operating systems
Test on different Python versions
Create API documentation
Publish package to PyPI or similar package repository
Triggers
push and pull_request are the most common triggers
schedule can be used to run the workflow on a schedule
workflow_dispatch can be used to trigger the workflow manually
on:push:branches:[ main ]pull_request:branches:[ main ]schedule:-cron:'0 0 * * 0'workflow_dispatch: