Skip to content

Commit 96a3064

Browse files
add basic contribution guideline, see #67
1 parent 9217dae commit 96a3064

File tree

1 file changed

+205
-1
lines changed

1 file changed

+205
-1
lines changed

docs/CONTRIBUTING.md

+205-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,208 @@ Guideline to contribute to this package
44

55
---------------
66

7-
## TBD
7+
## General
8+
9+
You're always welcome to contribute to this package with or without raising an
10+
issue before creating a PR.
11+
12+
Please follow this guideline covering all necessary steps and hints to ensure
13+
a smooth review and contribution process.
14+
15+
## Code
16+
17+
To test and verify your changes it is recommended to run all checks locally in
18+
a virtual environment. Use the following commands to setup and install all
19+
tools.
20+
21+
```bash
22+
python3 -m venv .venv
23+
source .venv/bin/activate
24+
25+
pip install -r requirements-test.txt
26+
```
27+
28+
For very old systems it might be necessary to use an older version of
29+
`pre-commit`, an "always" working version is `1.18.3` with the drawback of not
30+
having `flake8` and maybe other checks in place.
31+
32+
### Format
33+
34+
The Python code format is checked by `flake8` with the default line length
35+
limit of 79. Further configuration can be found in the `.flake8` file in the
36+
repo root.
37+
38+
The YAML code format is checked by `yamllint` with some small adjustments as
39+
defined in the `.yamllint` file in the repo root.
40+
41+
Use the following commands (inside the virtual environment) to run the Python
42+
and YAML checks
43+
44+
```bash
45+
# check Python
46+
flake8 .
47+
48+
# check YAML
49+
yamllint .
50+
```
51+
52+
### Tests
53+
54+
Every code should be covered by a unittest. This can be achieved for
55+
MicroPython up to some degree, as hardware specific stuff can't be always
56+
tested by a unittest.
57+
58+
For now `mpy_unittest` is used as tool of choice and runs directly on the
59+
divice. For ease of use a Docker container is used as not always a device is
60+
at hand or connected to the CI.
61+
62+
The hardware UART connection is faked by a TCP connection providing the same
63+
interface and basic functions as a real hardware interface.
64+
65+
The tests are defined, as usual, in the `tests` folder. The `mpy_unittest`
66+
takes and runs all tests defined and imported there by the `__init__.py` file.
67+
68+
Further tests, which could be called Integration tests, are defined in this
69+
folder as well. To be usable they may require a counterpart e.g. a client
70+
communicating with a host, which is simply achieved by two Docker containers,
71+
defined in the `docker-compose-tcp-test.yaml` or `docker-compose-rtu-test.yaml`
72+
file, located in the repo root. The examples for TCP or RTU client usage are
73+
used to provide a static setup.
74+
75+
Incontrast to Python, no individual test results will be reported as parsable
76+
XML or similar, the container will exit with either `1` in case of an error or
77+
with `0` on success.
78+
79+
```bash
80+
# build and run the "native" unittests
81+
docker build --tag micropython-test --file Dockerfile.tests .
82+
83+
# Execute client/host TCP examples
84+
docker compose up --build --exit-code-from micropython-host
85+
86+
# Run client/host TCP tests
87+
docker compose -f docker-compose-tcp-test.yaml up --build --exit-code-from micropython-host
88+
89+
# Run client/host RTU examples with faked RTU via TCP
90+
docker compose -f docker-compose-rtu.yaml up --build --exit-code-from micropython-host
91+
92+
# Run client/host RTU tests
93+
docker compose -f docker-compose-rtu-test.yaml up --build --exit-code-from micropython-host
94+
```
95+
96+
### Precommit hooks
97+
98+
This repo is equipped with a `.pre-commit-config.yaml` file to combine most of
99+
the previously mentioned checks plus the changelog validation, see next
100+
section, into one handy command. It additionally allows to automatically run
101+
the checks on every commit.
102+
103+
In order to run this repo's pre commit hooks, perform the following steps
104+
105+
```bash
106+
# install pre-commit to run before each commit, optionally
107+
pre-commit install
108+
109+
pre-commit run --all-files
110+
```
111+
112+
## Changelog
113+
114+
The changelog format is based on [Keep a Changelog][ref-keep-a-changelog], and
115+
this project adheres to [Semantic Versioning][ref-semantic-versioning].
116+
117+
Please add a changelog entry for every PR you contribute. The versions are
118+
seperated into `MAJOR.MINOR.PATCH`:
119+
120+
- Increment the major version by 1 in case you created a breaking, non
121+
backwards compatible change which requires the user to perform additional
122+
tasks, adopt his currently running code or in general can't be used as is anymore.
123+
- Increment the minor version by 1 on new "features" which can be used or are
124+
optional, but in either case do not require any changes by the user to keep
125+
the system running after upgrading.
126+
- Increment the patch version by 1 on bugfixes which fix an issue but can be
127+
used out of the box, like features, without any changes by the user. In some
128+
cases bugfixes can be breaking changes of course.
129+
130+
Please add the date the change has been made as well to the changelog
131+
following the format `## [MAJOR.MINOR.PATCH] - YYYY-MM-DD`. It is not
132+
necessary to keep this date up to date, it is just used as meta data.
133+
134+
The changelog entry shall be short but meaningful and can of course contain
135+
links and references to other issues or PRs. New lines are only allowed for a
136+
new bulletpoint entry. Usage examples or other code snippets should be placed
137+
in the code documentation, README or the docs folder.
138+
139+
### General
140+
141+
The package version file, located at `umodbus/version.py` contains the latest
142+
changelog version.
143+
144+
To avoid a manual sync of the changelog version and the package version file
145+
content, the `changelog2version` package is used. It parses the changelog,
146+
extracts the latest version and updates the version file.
147+
148+
The package version file can be generated with the following command consuming
149+
the latest changelog entry
150+
151+
```bash
152+
changelog2version \
153+
--changelog_file changelog.md \
154+
--version_file umodbus/version.py \
155+
--version_file_type py \
156+
--debug
157+
```
158+
159+
To validate the existing package version file against the latest changelog
160+
entry use this command
161+
162+
```bash
163+
changelog2version \
164+
--changelog_file=changelog.md \
165+
--version_file=umodbus/version.py \
166+
--validate
167+
```
168+
169+
### MicroPython
170+
171+
On MicroPython the `mip` package is used to install packages instead of `pip`
172+
at MicroPython version 1.20.0 and newer. This utilizes a `package.json` file
173+
in the repo root to define all files and dependencies of a package to be
174+
downloaded by [`mip`][ref-mip-docs].
175+
176+
To avoid a manual sync of the changelog version and the MicroPython package
177+
file content, the `setup2upypackage` package is used. It parses the changelog,
178+
extracts the latest version and updates the package file version entry. It
179+
additionally parses the `setup.py` file and adds entries for all files
180+
contained in the package to the `urls` section and all other external
181+
dependencies to the `deps` section.
182+
183+
The MicroPython package file can be generated with the following command based
184+
on the latest changelog entry and `setup` file.
185+
186+
```bash
187+
upy-package \
188+
--setup_file setup.py \
189+
--package_changelog_file changelog.md \
190+
--package_file package.json
191+
```
192+
193+
To validate the existing package file against the latest changelog entry and
194+
setup file content use this command
195+
196+
```bash
197+
upy-package \
198+
--setup_file setup.py \
199+
--package_changelog_file changelog.md \
200+
--package_file package.json \
201+
--validate
202+
```
203+
204+
## Documentation
205+
206+
Please check the `docs/DOCUMENTATION.md` file for further details.
207+
208+
<!-- Links -->
209+
[ref-keep-a-changelog]: https://keepachangelog.com/en/1.0.0/
210+
[ref-semantic-versioning]: https://semver.org/spec/v2.0.0.html
211+
[ref-mip-docs]: https://docs.micropython.org/en/v1.20.0/reference/packages.html

0 commit comments

Comments
 (0)