|
| 1 | +See the [Scientific Python Developer Guide][spc-dev-intro] for a detailed |
| 2 | +description of best practices for developing scientific packages. |
| 3 | + |
| 4 | +[spc-dev-intro]: https://learn.scientific-python.org/development/ |
| 5 | + |
| 6 | +# Quick development |
| 7 | + |
| 8 | +The fastest way to start with development is to use nox. If you don't have nox, |
| 9 | +you can use `pipx run nox` to run it without installing, or `pipx install nox`. |
| 10 | +If you don't have pipx (pip for applications), then you can install with |
| 11 | +`pip install pipx` (the only case were installing an application with regular |
| 12 | +pip is reasonable). If you use macOS, then pipx and nox are both in brew, use |
| 13 | +`brew install pipx nox`. |
| 14 | + |
| 15 | +To use, run `nox`. This will lint and test using every installed version of |
| 16 | +Python on your system, skipping ones that are not installed. You can also run |
| 17 | +specific jobs: |
| 18 | + |
| 19 | +```console |
| 20 | +$ nox -s lint # Lint only |
| 21 | +$ nox -s tests # Python tests |
| 22 | +$ nox -s build # Make an SDist and wheel |
| 23 | +``` |
| 24 | + |
| 25 | +Nox handles everything for you, including setting up an temporary virtual |
| 26 | +environment for each run. |
| 27 | + |
| 28 | +# Setting up a development environment manually |
| 29 | + |
| 30 | +You can set up a development environment by running: |
| 31 | + |
| 32 | +```bash |
| 33 | +python3 -m venv .venv |
| 34 | +source ./.venv/bin/activate |
| 35 | +pip install -v -e .[dev] |
| 36 | +``` |
| 37 | + |
| 38 | +If you have the |
| 39 | +[Python Launcher for Unix](https://github.com/brettcannon/python-launcher), you |
| 40 | +can instead do: |
| 41 | + |
| 42 | +```bash |
| 43 | +py -m venv .venv |
| 44 | +py -m install -v -e .[dev] |
| 45 | +``` |
| 46 | + |
| 47 | +# Pre-commit |
| 48 | + |
| 49 | +You should prepare pre-commit, which will help you by checking that commits pass |
| 50 | +required checks: |
| 51 | + |
| 52 | +```bash |
| 53 | +pip install pre-commit # or brew install pre-commit on macOS |
| 54 | +pre-commit install # Will install a pre-commit hook into the git repo |
| 55 | +``` |
| 56 | + |
| 57 | +You can also/alternatively run `pre-commit run` (changes only) or |
| 58 | +`pre-commit run --all-files` to check even without installing the hook. |
| 59 | + |
| 60 | +# Testing |
| 61 | + |
| 62 | +Use pytest to run the unit checks: |
| 63 | + |
| 64 | +```bash |
| 65 | +pytest |
| 66 | +``` |
| 67 | + |
| 68 | +# Coverage |
| 69 | + |
| 70 | +Use pytest-cov to generate coverage reports: |
| 71 | + |
| 72 | +```bash |
| 73 | +pytest --cov=is_annotated |
| 74 | +``` |
0 commit comments