Application
A program that is run by a user
Pin versions to ensure reproducibility, e.g. numpy==1.11.0
Library
A program that is used by another program
Make the requirements as loose as possible, e.g. numpy>=1.11.0
Example of pinning versions:
Or using a range of versions:
setup.py
vs pyproject.toml
setup.py
setuptools
to generate packages and install the package.pyproject.toml
poetry
or hatchling
to generate packages and install the package.pyproject.toml
Install package in editable mode:
$ which python /usr/bin/python $ python -m venv venv $ source venv/bin/activate # for π§ or venv\Scripts\activate.bat πͺ (venv)$ which python /home/user/src/myproj/venv/bin/python (venv)$ pip install -r requirements.txt
$ which python /usr/bin/python $ python -m venv venv $ source venv/bin/activate # for π§ or venv\Scripts\activate.bat πͺ (venv)$ which python /home/user/src/myproj/venv/bin/python (venv)$ pip install -r requirements.txt
$ which python /usr/bin/python $ python -m venv venv $ source venv/bin/activate # for π§ or venv\Scripts\activate.bat πͺ (venv)$ which python /home/user/src/myproj/venv/bin/python (venv)$ pip install -r requirements.txt
$ which python /usr/bin/python $ python -m venv venv $ source venv/bin/activate # for π§ or venv\Scripts\activate.bat πͺ (venv)$ which python /home/user/src/myproj/venv/bin/python (venv)$ pip install -r requirements.txt
Conda/mamba is a package manager that can be used to create virtual environments.
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.
There are many CI services available, e.g.:
.github/workflows
folder.name: Quick test
on: # when to run the workflow
push:
branches: [ main]
pull_request:
branches: [ main ]
jobs: # what to run
build:
runs-on: ubuntu-latest # on what operating system
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.9
- name: Install dependencies
run: |
python -m pip install --upgrade pip
- name: Install mikeio
run: |
pip install .[test]
- name: Test with pytest
run: |
pytest
ππ
βΉοΈ
push
and pull_request
are the most common triggersschedule
can be used to run the workflow on a scheduleworkflow_dispatch
can be used to trigger the workflow manuallyon: push: branches: [ main ] pull_request: branches: [ main ] schedule: - cron: '0 0 * * 0' workflow_dispatch:
on: push: branches: [ main ] pull_request: branches: [ main ] schedule: - cron: '0 0 * * 0' workflow_dispatch:
on: push: branches: [ main ] pull_request: branches: [ main ] schedule: - cron: '0 0 * * 0' workflow_dispatch:
on: push: branches: [ main ] pull_request: branches: [ main ] schedule: - cron: '0 0 * * 0' workflow_dispatch:
GitHub releases are a way to publish software releases.
You can upload files, write release notes and tag the release.
As a minimum, the release will contain the source code at the time of the release.
Creating a release can trigger other workflows, e.g. publishing a package to PyPI.
pyproject.toml
over setup.py
Python package development