Skip to content

Commit 4290e8c

Browse files
authored
Merge pull request #217 from NLeSC/214-how-to-make-a-release-notes
how to make a release notes
2 parents 263d62e + 1155d6a commit 4290e8c

File tree

5 files changed

+275
-217
lines changed

5 files changed

+275
-217
lines changed

README.dev.md

Lines changed: 97 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,110 @@
1-
The file structure of the generated package looks like:
1+
# Developer documentation
2+
3+
If you're looking for user documentation, go [here](README.md).
4+
5+
## Development install
6+
7+
### Install `cookiecutter` in user space
8+
9+
We recommend installing `cookiecutter` in user space as per `cookiecutter`'s instructions. This way, you don't have to
10+
install `cookiecutter` for every new project.
11+
12+
```shell
13+
python3 -m pip install --user --upgrade cookiecutter
14+
```
15+
16+
### Get your own copy of the repository
17+
18+
Before you can do development work on the template, you'll need to check out a local copy of the repository:
219

320
```shell
4-
path/to/package/
5-
├── .editorconfig
6-
└── .github/
7-
└── workflows
8-
├── build.yml
9-
└── pypi_deploy.yml
10-
├── .gitignore
11-
├── pyproject.toml
12-
├── .prospector.yml
13-
├── CHANGELOG.md
14-
├── CODE_OF_CONDUCT.md
15-
├── CONTRIBUTING.md
16-
├── docs
17-
│   ├── conf.py
18-
│   ├── index.rst
19-
│   └── ...
20-
├── LICENSE
21-
├── MANIFEST.in
22-
├── NOTICE
23-
├── package
24-
│   ├── __init__.py
25-
│   ├── __version__.py
26-
│   └── package.py
27-
├── README.md
28-
├── project_setup.md
29-
├── requirements.txt
30-
├── setup.cfg
31-
├── setup.py
32-
└── tests
33-
├── __init__.py
34-
├── test_lint.py
35-
└── test_package.py
21+
cd <where you keep your GitHub repositories>
22+
git clone https://github.com/NLeSC/python-template.git
23+
cd python-template
3624
```
3725

38-
* Code (existing or new) should be placed in `path/to/package/package/` (please choose a better name for your software!).
39-
* Add documentation by editing `path/to/package/docs/index.rst`
40-
* Tests go in the `path/to/package/tests/` directory
41-
* The generated [project setup document]({{cookiecutter.project_name}}/project_setup.md) contains extensive documentation about the project setup and provides further instructions on what to do.
26+
### Create a virtual environment
27+
28+
Next, make a virtual environment, activate it, and install the development dependencies in it. This will enable you to
29+
run the tests later.
30+
31+
```shell
32+
# Create a virtual environment, e.g. with
33+
python3 -m venv env
34+
35+
# activate virtual environment
36+
source env/bin/activate
37+
38+
# make sure to have a recent version of pip and setuptools
39+
python3 -m pip install --upgrade pip setuptools
40+
41+
# (from the project root directory)
42+
# install development dependencies
43+
python3 -m pip install --no-cache-dir .[dev]
44+
```
45+
46+
## Running the tests
47+
48+
Running the tests requires an activated virtual environment with the development tools installed.
49+
50+
```shell
51+
# unit tests
52+
pytest
53+
pytest tests/
54+
```
55+
56+
## Using `cookiecutter` to generate a new package from the command line
57+
58+
While making changes to the template, you'll regularly want to verify that the packages generated with the template
59+
still work. Any easy way to do this is to generate new packages in a temporary directory (which will get removed
60+
everytime you reboot), for example like so:
61+
62+
```shell
63+
# change directory to a new temporary directory
64+
cd $(mktemp -d --tmpdir cookiecutter-generated.XXXXXX)
65+
66+
# run cookiecutter with the template to generate a new package
67+
cookiecutter <path to where your template is>
68+
69+
# when it asks you for the GitHub organization, put in your own name;
70+
# for the other questions, just accept the default
71+
72+
# 'ls' should return just the one directory called 'my-python-project'
73+
ls
74+
```
75+
76+
If your Python package was created successfully, `cookiecutter` will point you to a file
77+
(`my-python-project/project_setup.md`) that contains information on next steps such as:
78+
79+
1. making `my-python-project` a local git repository
80+
1. connecting the local repository to a new repository on GitHub
81+
1. pushing the freshly generated content to GitHub
82+
1. discovering what GitHub Actions there are, what they do, and how to inspect their results
4283

43-
### Step 3: Create and activate a Python environment
84+
Follow the instructions from `my-python-project/project_setup.md` and make sure that everything works.
4485

45-
* If you are using **virtualenv + pip3**, do:
46-
```bash
47-
$ virtualenv -p python3 env
48-
$ . env/bin/activate
49-
```
50-
* If you are using **conda**, type:
51-
```bash
52-
$ conda create -n env python=3
53-
$ source activate env
54-
```
55-
(On windows use `activate env` to activate the conda environment.)
86+
In addition to the information in `my-python-project/project_setup.md`, the developer documentation
87+
`my-python-project/README.dev.md` contains information on a few more things to check, for example:
5688

57-
## Continuous integration with Github Actions
89+
1. generating `my-python-project`'s documentation locally
90+
1. running `my-python-project`'s tests locally
91+
1. running `my-python-project`'s linters locally
92+
1. verifying that the `my-python-project`'s version can be updated using `bumpversion`
93+
1. making a release of `my-python-project` on https://test.pypi.org/
5894

59-
The template has two Ci workflows. They can be found in **.github/workflows** folder.
95+
Follow the instructions from `my-python-project/README.dev.md` and make sure that everything works.
6096

61-
1. **build.yml**
97+
## Making a release
6298

63-
This workflow install the dependencies, builds the package and runs tests.
99+
### Preparation
64100

65-
2. **pypi.yml**
101+
1. Make sure the `CHANGELOG.md` has been updated
102+
2. Verify that the information in `CITATION.cff` is correct, and that `.zenodo.json` contains equivalent data
103+
3. Make sure that `version` in [setup.cfg](setup.cfg) and `version` in [CITATION.cff](CITATION.cff) have been bumped to the to-be-released version of the template
104+
4. Run the unit tests with `pytest tests/`
105+
5. Go through the steps outlined above for [generating a new package from the command line](#using-cookiecutter-to-generate-a-new-package-from-the-command-line), and verify that the generated package works as it should.
66106

67-
This workflow pushes the package to [PYPI](https://pypi.org/). This action will require PYPI token to be stored as [Github secret](https://help.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets). The workflow uses secret with a name of `PYPI_TOKEN`.
107+
### GitHub
68108

69-
You can learn more about Python packaging at [this link](https://packaging.python.org/tutorials/packaging-projects/).
109+
1. Make sure that the GitHub-Zenodo integration is enabled for https://github.com/NLeSC/python-template
110+
1. Go to https://github.com/NLeSC/python-template/releases and click `Draft a new release`

{{cookiecutter.project_name}}/.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,9 @@ docs/apidocs
2323

2424
# Mac
2525
.DS_Store
26+
27+
# virtual environments
28+
env
29+
env3
30+
venv
31+
venv3
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
# `{{ cookiecutter.package_name }}` developer documentation
2+
3+
If you're looking for user documentation, go [here](README.md).
4+
5+
## Development install
6+
7+
```shell
8+
# Create a virtual environment, e.g. with
9+
python3 -m venv env
10+
11+
# activate virtual environment
12+
source env/bin/activate
13+
14+
# make sure to have a recent version of pip and setuptools
15+
python3 -m pip install --upgrade pip setuptools
16+
17+
# (from the project root directory)
18+
# install {{ cookiecutter.package_name }} as an editable package
19+
python3 -m pip install --no-cache-dir --editable .
20+
# install development dependencies
21+
python3 -m pip install --no-cache-dir --editable .[dev]
22+
```
23+
24+
Afterwards check that the install directory is present in the `PATH` environment variable.
25+
26+
## Running the tests
27+
28+
Running the tests requires an activated virtual environment with the development tools installed.
29+
30+
```shell
31+
# unit tests
32+
pytest
33+
pytest tests/
34+
```
35+
36+
## Running linters locally
37+
38+
For linting we will use [prospector](https://pypi.org/project/prospector/) and to sort imports we will use
39+
[isort](https://pycqa.github.io/isort/). Running the linters requires an activated virtual environment with the
40+
development tools installed.
41+
42+
```shell
43+
# linter
44+
prospector
45+
46+
# recursively check import style for the {{ cookiecutter.package_name }} module only
47+
isort --recursive --check-only {{ cookiecutter.package_name }}
48+
49+
# recursively check import style for the {{ cookiecutter.package_name }} module only and show
50+
# any proposed changes as a diff
51+
isort --recursive --check-only --diff {{ cookiecutter.package_name }}
52+
53+
# recursively fix import style for the {{ cookiecutter.package_name }} module only
54+
isort --recursive {{ cookiecutter.package_name }}
55+
```
56+
57+
You can enable automatic linting with `prospector` and `isort` on commit by enabling the git hook from `.githooks/pre-commit`, like so:
58+
59+
```shell
60+
git config --local core.hooksPath .githooks
61+
```
62+
63+
## Generating the API docs
64+
65+
```shell
66+
cd docs
67+
make html
68+
```
69+
70+
The documentation will be in `docs/_build/`
71+
72+
## Versioning
73+
74+
Bumping the version across all files is done with bumpversion, e.g.
75+
76+
```shell
77+
bumpversion major
78+
bumpversion minor
79+
bumpversion patch
80+
```
81+
82+
## Making a release
83+
84+
This section describes how to make a release in 3 parts:
85+
86+
1. preparation
87+
1. making a release on PyPI
88+
1. making a release on GitHub
89+
90+
### (1/3) Preparation
91+
92+
1. Update the `CHANGELOG.md`
93+
2. Verify that the information in `CITATION.cff` is correct, and that `.zenodo.json` contains equivalent data
94+
3. Make sure the version has been updated.
95+
4. Run the unit tests with `pytest tests/`
96+
97+
### (2/3) PyPI
98+
99+
In a new terminal, without an activated virtual environment or an env directory:
100+
101+
```shell
102+
# prepare a new directory
103+
cd $(mktemp -d --tmpdir {{ cookiecutter.package_name }}.XXXXXX)
104+
105+
# fresh git clone ensures the release has the state of origin/main branch
106+
git clone {{ cookiecutter.repository }} .
107+
108+
# prepare a clean virtual environment and activate it
109+
python3 -m venv env
110+
source env/bin/activate
111+
112+
# make sure to have a recent version of pip and setuptools
113+
python3 -m pip install --upgrade pip setuptools
114+
115+
# install runtime dependencies and publishing dependencies
116+
python3 -m pip install --no-cache-dir .
117+
python3 -m pip install --no-cache-dir .[publishing]
118+
119+
# clean up any previously generated artefacts
120+
rm -rf {{ cookiecutter.package_name }}.egg-info
121+
rm -rf dist
122+
123+
# create the source distribution and the wheel
124+
python3 setup.py sdist bdist_wheel
125+
126+
# upload to test pypi instance (requires credentials)
127+
twine upload --repository-url https://test.pypi.org/legacy/ dist/*
128+
```
129+
130+
Visit
131+
[https://test.pypi.org/project/{{cookiecutter.package_name}}](https://test.pypi.org/project/{{cookiecutter.package_name}})
132+
and verify that your package was uploaded successfully. Keep the terminal open, we'll need it later.
133+
134+
In a new terminal, without an activated virtual environment or an env directory:
135+
136+
```shell
137+
cd $(mktemp -d --tmpdir {{ cookiecutter.package_name }}-test.XXXXXX)
138+
139+
# prepare a clean virtual environment and activate it
140+
python3 -m venv env
141+
source env/bin/activate
142+
143+
# make sure to have a recent version of pip and setuptools
144+
pip install --upgrade pip setuptools
145+
146+
# install from test pypi instance:
147+
python3 -m pip -v install --no-cache-dir \
148+
--index-url https://test.pypi.org/simple/ \
149+
--extra-index-url https://pypi.org/simple {{ cookiecutter.package_name }}
150+
```
151+
152+
Check that the package works as it should when installed from pypitest.
153+
154+
Then upload to pypi.org with:
155+
156+
```shell
157+
# Back to the first terminal,
158+
# FINAL STEP: upload to PyPI (requires credentials)
159+
twine upload dist/*
160+
```
161+
162+
### (3/3) GitHub
163+
164+
Don't forget to also make a release on GitHub. If your repository uses the GitHub-Zenodo integration this will also
165+
trigger Zenodo into making a snapshot of your repository and sticking a DOI on it.

0 commit comments

Comments
 (0)