|
1 | | -# Contributing |
| 1 | +# Contributing to NATS.py |
2 | 2 |
|
3 | | -Thanks for your interest in contributing! This document contains `nats-io/nats.py` specific contributing details. If you are a first-time contributor, please refer to the general [NATS Contributor Guide](https://nats.io/contributing/) to get a comprehensive overview of contributing to the NATS project. |
| 3 | +Thank you for your interest in contributing to NATS.py! |
4 | 4 |
|
5 | | -## Getting started |
| 5 | +## Development Setup |
6 | 6 |
|
7 | | -There are three general ways you can contribute to this repo: |
| 7 | +This is a [uv workspace](https://docs.astral.sh/uv/concepts/workspaces/) containing multiple packages. |
8 | 8 |
|
9 | | -- Proposing an enhancement or new feature |
10 | | -- Reporting a bug or regression |
11 | | -- Contributing changes to the source code |
| 9 | +### Prerequisites |
12 | 10 |
|
13 | | -For the first two, refer to the [GitHub Issues](https://github.com/nats-io/nats.py/issues/new/choose) which guides you through the available options along with the needed information to collect. |
| 11 | +1. [Install uv](https://docs.astral.sh/uv/getting-started/installation/) |
| 12 | +2. [Install nats-server](https://docs.nats.io/running-a-nats-service/introduction/installation) and ensure it's in your PATH: `nats-server -v` |
14 | 13 |
|
15 | | -## Contributing changes |
| 14 | +### Installation |
16 | 15 |
|
17 | | -_Prior to opening a pull request, it is recommended to open an issue first to ensure the maintainers can review intended changes. Exceptions to this rule include fixing non-functional source such as code comments, documentation or other supporting files._ |
| 16 | +```bash |
| 17 | +# Clone the repository |
| 18 | +git clone https://github.com/nats-io/nats.py |
| 19 | +cd nats.py |
18 | 20 |
|
19 | | -Proposing source code changes is done through GitHub's standard pull request workflow. |
| 21 | +# Install dependencies |
| 22 | +uv sync |
| 23 | +``` |
20 | 24 |
|
21 | | -If your branch is a work-in-progress then please start by creating your pull requests as draft, by clicking the down-arrow next to the `Create pull request` button and instead selecting `Create draft pull request`. |
| 25 | +## Running Tests |
22 | 26 |
|
23 | | -This will defer the automatic process of requesting a review from the NATS team and significantly reduces noise until you are ready. Once you are happy, you can click the `Ready for review` button. |
| 27 | +```bash |
| 28 | +# Run all tests |
| 29 | +uv run pytest |
24 | 30 |
|
25 | | -### Guidelines |
| 31 | +# Run tests for specific package |
| 32 | +uv run pytest nats/tests |
| 33 | +uv run pytest nats-server/tests |
26 | 34 |
|
27 | | -A good pull request includes: |
| 35 | +# Run tests in parallel |
| 36 | +uv run pytest -n auto |
28 | 37 |
|
29 | | -- A high-level description of the changes, including links to any issues that are related by adding comments like `Resolves #NNN` to your description. See [Linking a Pull Request to an Issue](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue) for more information. |
30 | | -- An up-to-date parent commit. Please make sure you are pulling in the latest `main` branch and rebasing your work on top of it, i.e. `git rebase main`. |
31 | | -- Unit tests where appropriate. Bug fixes will benefit from the addition of regression tests. New features will not be accepted without suitable test coverage! |
32 | | -- No more commits than necessary. Sometimes having multiple commits is useful for telling a story or isolating changes from one another, but please squash down any unnecessary commits that may just be for clean-up, comments or small changes. |
33 | | -- No additional external dependencies that aren't absolutely essential. Please do everything you can to avoid pulling in additional libraries/dependencies into `go.mod` as we will be very critical of these. |
| 38 | +# Run with coverage |
| 39 | +uv run pytest --cov |
| 40 | +``` |
34 | 41 |
|
35 | | -### Sign-off |
| 42 | +## Code Quality |
36 | 43 |
|
37 | | -In order to accept a contribution, you will first need to certify that the contribution is your original work and that you license the work to the project under the [Apache-2.0 license](https://github.com/nats-io/nats.py/blob/main/LICENSE). |
| 44 | +### Type Checking |
38 | 45 |
|
39 | | -This is done by using `Signed-off-by` statements, which should appear in **both** your commit messages and your PR description. Please note that we can only accept sign-offs under a legal name. Nicknames and aliases are not permitted. |
| 46 | +```bash |
| 47 | +uv run mypy nats/src |
| 48 | +``` |
40 | 49 |
|
41 | | -To perform a sign-off with `git`, use `git commit -s` (or `--signoff`). |
| 50 | +### Formatting |
42 | 51 |
|
43 | | -## Get help |
| 52 | +```bash |
| 53 | +# Format code |
| 54 | +uv run yapf -i -r nats/src nats-server/src |
44 | 55 |
|
45 | | -If you have questions about the contribution process, please start a [GitHub discussion](https://github.com/nats-io/nats.py/discussions), join the [NATS Slack](https://slack.nats.io/), or send your question to the [NATS Google Group](https://groups.google.com/forum/#!forum/natsio). |
| 56 | +# Check formatting |
| 57 | +uv run yapf -d -r nats/src nats-server/src |
| 58 | +``` |
| 59 | + |
| 60 | +### Linting |
| 61 | + |
| 62 | +```bash |
| 63 | +# Run ruff |
| 64 | +uv run ruff check nats/src nats-server/src |
| 65 | + |
| 66 | +# Run flake8 (for nats-py) |
| 67 | +uv run flake8 nats/src/nats/js/ |
| 68 | + |
| 69 | +# Run isort |
| 70 | +uv run isort nats/src nats-server/src |
| 71 | +``` |
| 72 | + |
| 73 | +## Updating Documentation |
| 74 | + |
| 75 | +To update the docs, first checkout the `docs` branch under a local copy of the `nats.py` repo: |
| 76 | + |
| 77 | +```sh |
| 78 | +git clone https://github.com/nats-io/nats.py |
| 79 | +cd nats.py |
| 80 | +git clone https://github.com/nats-io/nats.py --branch docs --single-branch docs |
| 81 | +cd docs |
| 82 | +uv venv |
| 83 | +source .venv/bin/activate # or `.venv\Scripts\activate` on Windows |
| 84 | +uv pip install sphinx sphinx_autodoc_typehints myst_parser furo pygments |
| 85 | +make html |
| 86 | +# preview the changes: |
| 87 | +make serve |
| 88 | +``` |
| 89 | + |
| 90 | +If you are happy with the changes, make a PR on the docs branch: |
| 91 | +``` |
| 92 | +make publish |
| 93 | +git add docs |
| 94 | +``` |
| 95 | + |
| 96 | +## Pull Request Guidelines |
| 97 | + |
| 98 | +1. Fork the repository and create your branch from `main` |
| 99 | +2. Make sure all tests pass |
| 100 | +3. Update documentation if needed |
| 101 | +4. Follow the existing code style |
| 102 | +5. Write clear commit messages |
| 103 | +6. Create a pull request with a clear description of the changes |
| 104 | + |
| 105 | +## License |
| 106 | + |
| 107 | +By contributing to NATS.py, you agree that your contributions will be licensed under the Apache License 2.0. |
0 commit comments