|
| 1 | +# Contributing to {{cookiecutter.title}} |
| 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 | +{%- if cookiecutter.type == "api" %} |
| 14 | + |
| 15 | +You need to make sure you have the `git submodules` updated: |
| 16 | + |
| 17 | +```sh |
| 18 | +git submodule update --init |
| 19 | +``` |
| 20 | + |
| 21 | +### Running protolint |
| 22 | + |
| 23 | +To make sure some common mistakes are avoided and to ensure a consistent style |
| 24 | +it is recommended to run `protolint`. After you [installed |
| 25 | +`protolint`](https://github.com/yoheimuta/protolint#installation), just run: |
| 26 | + |
| 27 | +```sh |
| 28 | +protolint lint proto |
| 29 | +``` |
| 30 | + |
| 31 | +### Python setup |
| 32 | +{%- endif %} |
| 33 | + |
| 34 | +You can use editable installs to develop the project locally (it will install |
| 35 | +all the dependencies too): |
| 36 | + |
| 37 | +```sh |
| 38 | +python -m pip install -e . |
| 39 | +``` |
| 40 | +{%- if cookiecutter.type == "api" %} |
| 41 | + |
| 42 | +This will also generate the Python files from the `proto/` files and leave them |
| 43 | +in `py/`, so you can inspect them. |
| 44 | +{%- endif %} |
| 45 | + |
| 46 | +Or you can install all development dependencies (`mypy`, `pylint`, `pytest`, |
| 47 | +etc.) in one go too: |
| 48 | +```sh |
| 49 | +python -m pip install -e .[dev] |
| 50 | +``` |
| 51 | + |
| 52 | +If you don't want to install all the dependencies, you can also use `nox` to |
| 53 | +run the tests and other checks creating its own virtual environments: |
| 54 | + |
| 55 | +```sh |
| 56 | +python -m pip install .[dev-noxfile] |
| 57 | +nox |
| 58 | +``` |
| 59 | + |
| 60 | +You can also use `nox -R` to reuse the current testing environment to speed up |
| 61 | +test at the expense of a higher chance to end up with a dirty test environment. |
| 62 | +{%- if cookiecutter.type == "api" %} |
| 63 | + |
| 64 | +### Upgrading dependencies |
| 65 | + |
| 66 | +If you want to update the dependency `frequenz-api-common`, then you need to: |
| 67 | + |
| 68 | +1. Update the submodule `frequenz-api-common` |
| 69 | +2. Update the version of the `frequenz-api-common` package in `pyproject.toml` |
| 70 | + |
| 71 | +The version of `frequenz-api-common` used in both places mentioned above should |
| 72 | +be the same. |
| 73 | + |
| 74 | +Here is an example of upgrading the `frequenz-api-common` dependency to version |
| 75 | +`v0.2.0`: |
| 76 | +```sh |
| 77 | +ver="0.2.0" |
| 78 | + |
| 79 | +cd submodules/frequenz-api-common |
| 80 | +git remote update |
| 81 | +git checkout v${ver} |
| 82 | +cd - |
| 83 | + |
| 84 | +sed s/"frequenz-api-common == [0-9]\.[0-9]\.[0-9]"/"frequenz-api-common == ${ver}"/g -i pyproject.toml |
| 85 | +``` |
| 86 | +{%- endif %} |
| 87 | + |
| 88 | +### Running tests / checks individually |
| 89 | + |
| 90 | +For a better development test cycle you can install the runtime and test |
| 91 | +dependencies and run `pytest` manually. |
| 92 | + |
| 93 | +```sh |
| 94 | +python -m pip install .[dev-pytest] # included in .[dev] too |
| 95 | + |
| 96 | +# And for example |
| 97 | +pytest tests/test_*.py |
| 98 | +``` |
| 99 | + |
| 100 | +Or you can use `nox`: |
| 101 | + |
| 102 | +```sh |
| 103 | +nox -R -s pytest -- test/test_*.py |
| 104 | +``` |
| 105 | + |
| 106 | +The same appliest to `pylint` or `mypy` for example: |
| 107 | + |
| 108 | +```sh |
| 109 | +nox -R -s pylint -- test/test_*.py |
| 110 | +nox -R -s mypy -- test/test_*.py |
| 111 | +``` |
| 112 | + |
| 113 | +## Releasing |
| 114 | + |
| 115 | +These are the steps to create a new release: |
| 116 | + |
| 117 | +1. Get the latest head you want to create a release from. |
| 118 | + |
| 119 | +2. Update the `RELEASE_NOTES.md` file if it is not complete, up to date, and |
| 120 | + remove template comments (`<!-- ... ->`) and empty sections. Submit a pull |
| 121 | + request if an update is needed, wait until it is merged, and update the |
| 122 | + latest head you want to create a release from to get the new merged pull |
| 123 | + request. |
| 124 | + |
| 125 | +3. Create a new signed tag using the release notes and |
| 126 | + a [semver](https://semver.org/) compatible version number with a `v` prefix, |
| 127 | + for example: |
| 128 | + |
| 129 | + ```sh |
| 130 | + git tag -s --cleanup=whitespace -F RELEASE_NOTES.md v0.0.1 |
| 131 | + ``` |
| 132 | + |
| 133 | +4. Push the new tag. |
| 134 | + |
| 135 | +5. A GitHub action will test the tag and if all goes well it will create |
| 136 | + a [GitHub |
| 137 | + Release](https://github.com/{{cookiecutter.github_org}}/{{cookiecutter.github_repo_name}}/releases), |
| 138 | + and upload a new package to |
| 139 | + [PyPI](https://pypi.org/project/{{cookiecutter.pypi_package_name}}/) |
| 140 | + automatically. |
| 141 | + |
| 142 | +6. Once this is done, reset the `RELEASE_NOTES.md` with the template: |
| 143 | + |
| 144 | + ```sh |
| 145 | + cp .github/RELEASE_NOTES.template.md RELEASE_NOTES.md |
| 146 | + ``` |
| 147 | + |
| 148 | + Commit the new release notes and create a PR (this step should be automated |
| 149 | + eventually too). |
| 150 | + |
| 151 | +7. Celebrate! |
0 commit comments