Skip to content

Commit b24e7c5

Browse files
llucaxstefan-brus-frequenz
authored andcommitted
Add contributing guide
Signed-off-by: Leandro Lucarella <[email protected]>
1 parent 0346a25 commit b24e7c5

File tree

1 file changed

+200
-0
lines changed

1 file changed

+200
-0
lines changed

CONTRIBUTING.md

Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
# Contributing to Frequenz Dispatch API
2+
3+
## Build
4+
5+
You can use `build` to simply build the source and binary distribution:
6+
7+
```sh
8+
python -m pip install build
9+
python -m build
10+
```
11+
12+
## Local development
13+
14+
You need to make sure you have the `git submodules` updated:
15+
16+
```sh
17+
git submodule update --init
18+
```
19+
20+
### Running protolint
21+
22+
To make sure some common mistakes are avoided and to ensure a consistent style
23+
it is recommended to run `protolint`. After you [installed
24+
`protolint`](https://github.com/yoheimuta/protolint#installation), just run:
25+
26+
```sh
27+
protolint lint proto
28+
```
29+
30+
### Python setup
31+
32+
You can use editable installs to develop the project locally (it will install
33+
all the dependencies too):
34+
35+
```sh
36+
python -m pip install -e .
37+
```
38+
39+
This will also generate the Python files from the `proto/` files and leave them
40+
in `py/`, so you can inspect them.
41+
42+
Or you can install all development dependencies (`mypy`, `pylint`, `pytest`,
43+
etc.) in one go too:
44+
```sh
45+
python -m pip install -e .[dev]
46+
```
47+
48+
If you don't want to install all the dependencies, you can also use `nox` to
49+
run the tests and other checks creating its own virtual environments:
50+
51+
```sh
52+
python -m pip install .[dev-noxfile]
53+
nox
54+
```
55+
56+
You can also use `nox -R` to reuse the current testing environment to speed up
57+
test at the expense of a higher chance to end up with a dirty test environment.
58+
59+
### Upgrading dependencies
60+
61+
If you want to update the dependency `frequenz-api-common`, then you need to:
62+
63+
1. Update the submodule `frequenz-api-common`
64+
2. Update the version of the `frequenz-api-common` package in `pyproject.toml`
65+
66+
The version of `frequenz-api-common` used in both places mentioned above should
67+
be the same.
68+
69+
Here is an example of upgrading the `frequenz-api-common` dependency to version
70+
`v0.2.0`:
71+
```sh
72+
ver="0.2.0"
73+
74+
cd submodules/frequenz-api-common
75+
git remote update
76+
git checkout v${ver}
77+
cd -
78+
79+
sed s/"frequenz-api-common == [0-9]\.[0-9]\.[0-9]"/"frequenz-api-common == ${ver}"/g -i pyproject.toml
80+
```
81+
82+
### Running tests / checks individually
83+
84+
For a better development test cycle you can install the runtime and test
85+
dependencies and run `pytest` manually.
86+
87+
```sh
88+
python -m pip install .[dev-pytest] # included in .[dev] too
89+
90+
# And for example
91+
pytest tests/test_*.py
92+
```
93+
94+
Or you can use `nox`:
95+
96+
```sh
97+
nox -R -s pytest -- test/test_*.py
98+
```
99+
100+
The same appliest to `pylint` or `mypy` for example:
101+
102+
```sh
103+
nox -R -s pylint -- test/test_*.py
104+
nox -R -s mypy -- test/test_*.py
105+
```
106+
107+
### Building the documentation
108+
109+
To build the documentation, first install the dependencies (if you didn't
110+
install all `dev` dependencies):
111+
112+
```sh
113+
python -m pip install -e .[dev-mkdocs]
114+
```
115+
116+
Then you can build the documentation (it will be written in the `site/`
117+
directory):
118+
119+
```sh
120+
mkdocs build
121+
```
122+
123+
Or you can just serve the documentation without building it using:
124+
125+
```sh
126+
mkdocs serve
127+
```
128+
129+
Your site will be updated **live** when you change your files (provided that
130+
you used `pip install -e .`, beware of a common pitfall of using `pip install`
131+
without `-e`, in that case the API reference won't change unless you do a new
132+
`pip install`).
133+
134+
To build multi-version documentation, we use
135+
[mike](https://github.com/jimporter/mike). If you want to see how the
136+
multi-version sites looks like locally, you can use:
137+
138+
```sh
139+
mike deploy my-version
140+
mike set-default my-version
141+
mike serve
142+
```
143+
144+
`mike` works in mysterious ways. Some basic information:
145+
146+
* `mike deploy` will do a `mike build` and write the results to your **local**
147+
`gh-pages` branch. `my-version` is an arbitrary name for the local version
148+
you want to preview.
149+
* `mike set-default` is needed so when you serve the documentation, it goes to
150+
your newly produced documentation by default.
151+
* `mike serve` will serve the contents of your **local** `gh-pages` branch. Be
152+
aware that, unlike `mkdocs serve`, changes to the sources won't be shown
153+
live, as the `mike deploy` step is needed to refresh them.
154+
155+
Be careful not to use `--push` with `mike deploy`, otherwise it will push your
156+
local `gh-pages` branch to the `origin` remote.
157+
158+
That said, if you want to test the actual website in **your fork**, you can
159+
always use `mike deploy --push --remote your-fork-remote`, and then access the
160+
GitHub pages produced for your fork.
161+
162+
## Releasing
163+
164+
These are the steps to create a new release:
165+
166+
1. Get the latest head you want to create a release from.
167+
168+
2. Update the `RELEASE_NOTES.md` file if it is not complete, up to date, and
169+
remove template comments (`<!-- ... ->`) and empty sections. Submit a pull
170+
request if an update is needed, wait until it is merged, and update the
171+
latest head you want to create a release from to get the new merged pull
172+
request.
173+
174+
3. Create a new signed tag using the release notes and
175+
a [semver](https://semver.org/) compatible version number with a `v` prefix,
176+
for example:
177+
178+
```sh
179+
git tag -s --cleanup=whitespace -F RELEASE_NOTES.md v0.0.1
180+
```
181+
182+
4. Push the new tag.
183+
184+
5. A GitHub action will test the tag and if all goes well it will create
185+
a [GitHub
186+
Release](https://github.com/frequenz-floss/frequenz-api-dispatch/releases),
187+
and upload a new package to
188+
[PyPI](https://pypi.org/project/frequenz-api-dispatch/)
189+
automatically.
190+
191+
6. Once this is done, reset the `RELEASE_NOTES.md` with the template:
192+
193+
```sh
194+
cp .github/RELEASE_NOTES.template.md RELEASE_NOTES.md
195+
```
196+
197+
Commit the new release notes and create a PR (this step should be automated
198+
eventually too).
199+
200+
7. Celebrate!

0 commit comments

Comments
 (0)