-
Notifications
You must be signed in to change notification settings - Fork 85
Expand file tree
/
Copy path{% if AddDevDoc %}README.dev.md{% endif %}.jinja
More file actions
223 lines (157 loc) · 5.98 KB
/
{% if AddDevDoc %}README.dev.md{% endif %}.jinja
File metadata and controls
223 lines (157 loc) · 5.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
# `{{ package_name }}` developer documentation
If you're looking for user documentation, go [here](README.md).
## Development install
```shell
# Create a virtual environment, e.g. with
python -m venv env
# activate virtual environment
source env/bin/activate
# make sure to have a recent version of pip and setuptools
python -m pip install --upgrade pip setuptools
# (from the project root directory)
# install {{ package_name }} as an editable package
python -m pip install --no-cache-dir --editable .
# install development dependencies
python -m pip install --no-cache-dir --editable .[dev]
# install documentation dependencies only
python -m pip install --no-cache-dir --editable .[docs]
```
Afterwards check that the install directory is present in the `PATH` environment variable.
## Running the tests
There are two ways to run tests.
The first way requires an activated virtual environment with the development tools installed:
```shell
pytest -v
```
The second is to use `tox`, which can be installed separately (e.g. with `pip install tox`), i.e. not necessarily inside the virtual environment you use for installing `{{ package_name }}`, but then builds the necessary virtual environments itself by simply running:
```shell
tox
```
Testing with `tox` allows for keeping the testing environment separate from your development environment.
The development environment will typically accumulate (old) packages during development that interfere with testing; this problem is avoided by testing with `tox`.
### Test coverage
In addition to just running the tests to see if they pass, they can be used for coverage statistics, i.e. to determine how much of the package's code is actually executed during tests.
In an activated virtual environment with the development tools installed, inside the package directory, run:
```shell
coverage run
```
This runs tests and stores the result in a `.coverage` file.
To see the results on the command line, run
```shell
coverage report
```
`coverage` can also generate output in HTML and other formats; see `coverage help` for more information.
{%- if AddLinting -%}
## Running linters locally
For linting and sorting imports we will use [ruff](https://beta.ruff.rs/docs/). Running the linters requires an
activated virtual environment with the development tools installed.
```shell
# linter
ruff check .
# linter with automatic fixing
ruff check . --fix
```
To fix readability of your code style you can use [yapf](https://github.com/google/yapf).
{%- endif -%}
{%- if AddPreCommit -%}
You can enable automatic linting with `ruff` on commit by enabling the git hook from `.githooks/pre-commit`, like so:
```shell
git config --local core.hooksPath .githooks
```
{%- endif -%}
{% if AddTyping %}
## Type checking
{% if SelectTypeChecker == 'pyright' -%}
We use [pyright](https://microsoft.github.io/pyright/) for type checking.
```shell
pyright
```
{% endif -%}
{% if SelectTypeChecker == 'mypy' -%}
We use [mypy](http://mypy-lang.org/) for type checking.
```shell
mypy
```
{% endif -%}
{% endif -%}
## Generating the API docs
```shell
cd docs
make html
```
The documentation will be in `docs/_build/html`
If you do not have `make` use
```shell
sphinx-build -b html docs docs/_build/html
```
To find undocumented Python objects run
```shell
cd docs
make coverage
cat _build/coverage/python.txt
```
To [test snippets](https://www.sphinx-doc.org/en/master/usage/extensions/doctest.html) in documentation run
```shell
cd docs
make doctest
```
## Versioning
Bumping the version across all files is done with [bump-my-version](https://github.com/callowayproject/bump-my-version), e.g.
```shell
bump-my-version bump major # bumps from e.g. 0.3.2 to 1.0.0
bump-my-version bump minor # bumps from e.g. 0.3.2 to 0.4.0
bump-my-version bump patch # bumps from e.g. 0.3.2 to 0.3.3
```
## Making a release
This section describes how to make a release in 3 parts:
1. preparation
1. making a release on PyPI
1. making a release on GitHub
### (1/3) Preparation
{% if AddChangeLog -%}1. Update the <CHANGELOG.md> (don't forget to update links at bottom of page).{%- endif %}
{% if AddCitation -%}1. Verify that the information in [`CITATION.cff`](CITATION.cff) is correct.{%- endif %}
1. Make sure the [version has been updated](#versioning).
1. Run the unit tests with `pytest -v`
### (2/3) PyPI
In a new terminal:
```shell
# OPTIONAL: prepare a new directory with fresh git clone to ensure the release
# has the state of origin/main branch
cd $(mktemp -d {{ package_name }}.XXXXXX)
git clone {{ repository }} .
# make sure to have a recent version of pip and the publishing dependencies
python -m pip install --upgrade pip
python -m pip install .[publishing]
# create the source distribution and the wheel
python -m build
# upload to test pypi instance (requires credentials)
python -m twine upload --repository testpypi dist/*
```
Visit
[https://test.pypi.org/project/{{package_name}}](https://test.pypi.org/project/{{package_name}})
and verify that your package was uploaded successfully. Keep the terminal open, we'll need it later.
In a new terminal, without an activated virtual environment or an env directory:
```shell
cd $(mktemp -d {{ package_name }}-test.XXXXXX)
# prepare a clean virtual environment and activate it
python -m venv env
source env/bin/activate
# make sure to have a recent version of pip and setuptools
python -m pip install --upgrade pip
# install from test pypi instance:
python -m pip -v install --no-cache-dir \
--index-url https://test.pypi.org/simple/ \
--extra-index-url https://pypi.org/simple {{ package_name }}
```
Check that the package works as it should when installed from pypitest.
Then upload to pypi.org with:
```shell
# Back to the first terminal,
# FINAL STEP: upload to PyPI (requires credentials)
python -m twine upload dist/*
```
### (3/3) GitHub
Don't forget to also make a [release on GitHub]({{repository_url}}/releases/new).
{%- if AddZenodo -%}
GitHub-Zenodo integration will also trigger Zenodo into making a snapshot of your repository and sticking a DOI on it.
{%- endif -%}