|
| 1 | +Contributing to sigstore |
| 2 | +======================== |
| 3 | + |
| 4 | +Thank you for your interest in contributing to `sigstore`! |
| 5 | + |
| 6 | +The information below will help you set up a local development environment, |
| 7 | +as well as performing common development tasks. |
| 8 | + |
| 9 | +## Requirements |
| 10 | + |
| 11 | +`sigstore`'s only development environment requirement *should* be Python 3.7 |
| 12 | +or newer. Development and testing is actively performed on macOS and Linux, |
| 13 | +but Windows and other supported platforms that are supported by Python |
| 14 | +should also work. |
| 15 | + |
| 16 | +If you're on a system that has GNU Make, you can use the convenience targets |
| 17 | +included in the `Makefile` that comes in the `sigstore` repository detailed |
| 18 | +below. But this isn't required; all steps can be done without Make. |
| 19 | + |
| 20 | +## Development steps |
| 21 | + |
| 22 | +First, clone this repository: |
| 23 | + |
| 24 | +```bash |
| 25 | +git clone https://github.com/trailofbits/sigstore |
| 26 | +cd sigstore |
| 27 | +``` |
| 28 | + |
| 29 | +Then, use one of the `Makefile` targets to run a task. The first time this is |
| 30 | +run, this will also set up the local development virtual environment, and will |
| 31 | +install `sigstore` as an editable package into this environment. |
| 32 | + |
| 33 | +Any changes you make to the `sigstore` source tree will take effect |
| 34 | +immediately in the virtual environment. |
| 35 | + |
| 36 | +### Linting |
| 37 | + |
| 38 | +You can lint locally with: |
| 39 | + |
| 40 | +```bash |
| 41 | +make lint |
| 42 | +``` |
| 43 | + |
| 44 | +`sigstore` is automatically linted and formatted with a collection of tools: |
| 45 | + |
| 46 | +* [`black`](https://github.com/psf/black): Code formatting |
| 47 | +* [`isort`](https://github.com/PyCQA/isort): Import sorting, ordering |
| 48 | +* [`flake8`](https://flake8.pycqa.org/en/latest/): PEP-8 linting, style enforcement |
| 49 | +* [`mypy`](https://mypy.readthedocs.io/en/stable/): Static type checking |
| 50 | +* [`interrogate`](https://interrogate.readthedocs.io/en/latest/): Documentation coverage |
| 51 | + |
| 52 | + |
| 53 | +### Testing |
| 54 | + |
| 55 | +You can run the tests locally with: |
| 56 | + |
| 57 | +```bash |
| 58 | +make test |
| 59 | +``` |
| 60 | + |
| 61 | +You can also filter by a pattern (uses `pytest -k`): |
| 62 | + |
| 63 | +```bash |
| 64 | +make test TESTS=test_version |
| 65 | +``` |
| 66 | + |
| 67 | +To test a specific file: |
| 68 | + |
| 69 | +```bash |
| 70 | +make test T=path/to/file.py |
| 71 | +``` |
| 72 | + |
| 73 | +`sigstore` has a [`pytest`](https://docs.pytest.org/)-based unit test suite, |
| 74 | +including code coverage with [`coverage.py`](https://coverage.readthedocs.io/). |
| 75 | + |
| 76 | +### Documentation |
| 77 | + |
| 78 | +If you're running Python 3.7 or newer, you can run the documentation build locally: |
| 79 | + |
| 80 | +```bash |
| 81 | +make doc |
| 82 | +``` |
| 83 | + |
| 84 | +`sigstore` uses [`pdoc3`](https://github.com/pdoc3/pdoc) to generate HTML documentation for |
| 85 | +the public Python APIs. |
| 86 | + |
| 87 | +Live documentation for the `main` branch is hosted |
| 88 | +[here](https://trailofbits.github.io/sigstore/). Only the public APIs are |
| 89 | +documented, all undocumented APIs are **intentionally private and unstable.** |
| 90 | + |
| 91 | +### Releasing |
| 92 | + |
| 93 | +**NOTE**: If you're a non-maintaining contributor, you don't need the steps |
| 94 | +here! They're documented for completeness and for onboarding future maintainers. |
| 95 | + |
| 96 | +Releases of `sigstore` are managed with [`bump`](https://github.com/di/bump) |
| 97 | +and GitHub Actions. |
| 98 | + |
| 99 | +```bash |
| 100 | +# default release (patch bump) |
| 101 | +make release |
| 102 | + |
| 103 | +# override the default |
| 104 | +# vX.Y.Z -> vX.Y.Z-rc.0 |
| 105 | +make release BUMP_ARGS="--pre rc.0" |
| 106 | + |
| 107 | +# vX.Y.Z -> vN.0.0 |
| 108 | +make release BUMP_ARGS="--major" |
| 109 | +``` |
| 110 | + |
| 111 | +`make release` will fail if there are any untracked changes in the source tree. |
| 112 | + |
| 113 | +If `make release` succeeds, you'll see an output like this: |
| 114 | + |
| 115 | +``` |
| 116 | +RUN ME MANUALLY: git push origin main && git push origin vX.Y.Z |
| 117 | +``` |
| 118 | + |
| 119 | +Run that last command sequence to complete the release. |
| 120 | + |
| 121 | +## Development practices |
| 122 | + |
| 123 | +Here are some guidelines to follow if you're working on a new feature or changes to |
| 124 | +`sigstore`'s internal APIs: |
| 125 | + |
| 126 | +* *Keep the `sigstore` APIs as private as possible*. Nearly all of `sigstore`'s |
| 127 | +APIs should be private and treated as unstable and unsuitable for public use. |
| 128 | +If you're adding a new module to the source tree, prefix the filename with an underscore to |
| 129 | +emphasize that it's an internal (e.g., `sigstore/_foo.py` instead of `sigstore/foo.py`). |
| 130 | + |
| 131 | +* *Perform judicious debug logging.* `sigstore` uses the standard Python |
| 132 | +[`logging`](https://docs.python.org/3/library/logging.html) module. Use |
| 133 | +`logger.debug` early and often -- users who experience errors can submit better |
| 134 | +bug reports when their debug logs include helpful context! |
| 135 | + |
| 136 | +* *Update the [CHANGELOG](./CHANGELOG.md)*. If your changes are public or result |
| 137 | +in changes to `sigstore`'s CLI, please record them under the "Unreleased" section, |
| 138 | +with an entry in an appropriate subsection ("Added", "Changed", "Removed", or "Fixed"). |
0 commit comments