|
| 1 | +# Contributing to `testcontainers-python` |
| 2 | + |
| 3 | +Welcome to the `testcontainers-python` community! |
| 4 | +This should give you an idea about how we build, test and release `testcontainers-python`! |
| 5 | + |
| 6 | +Highly recommended to read this document thoroughly to understand what we're working on right now |
| 7 | +and what our priorities are before you are trying to contribute something. |
| 8 | + |
| 9 | +This will greatly increase your chances of getting prompt replies as the maintainers are volunteers themselves. |
| 10 | + |
| 11 | +## Before you begin |
| 12 | + |
| 13 | +We recommend following these steps: |
| 14 | + |
| 15 | +1. Finish reading this document. |
| 16 | +2. Read the [recently updated issues](https://github.com/testcontainers/testcontainers-python/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc){:target="\_blank"} |
| 17 | +3. Look for existing issues on the subject you are interested in - we do our best to label everything correctly |
| 18 | + |
| 19 | +## Local development |
| 20 | + |
| 21 | +### Pre-Requisites |
| 22 | + |
| 23 | +You need to have the following tools available to you: |
| 24 | + |
| 25 | +- `make` - You'll need a GNU Make for common developer activities |
| 26 | +- `poetry` - This is the primary package manager for the project |
| 27 | +- `pyenv` **Recommended**: For installing python versions for your system. |
| 28 | + Poetry infers the current latest version from what it can find on the `PATH` so you are still fine if you don't use `pyenv`. |
| 29 | + |
| 30 | +### Build and test |
| 31 | + |
| 32 | +- Run `make install` to get `poetry` to install all dependencies and set up `pre-commit` |
| 33 | + - **Recommended**: Run `make` or `make help` to see other commands available to you. |
| 34 | +- After this, you should have a working virtual environment and proceed with writing code with your favorite IDE |
| 35 | +- **TIP**: You can run `make core/tests` or `make modules/<my-module>/tests` to run the tests specifically for that to speed up feedback cycles |
| 36 | +- You can also run `make lint` to run the `pre-commit` for the entire codebase. |
| 37 | + |
| 38 | +## Adding new modules |
| 39 | + |
| 40 | +We have an [issue template](https://github.com/testcontainers/testcontainers-python/blob/main/.github/ISSUE_TEMPLATE/new-container.md){:target="\_blank"} for adding new module containers, please refer to that for more information. |
| 41 | +Once you've talked to the maintainers (we do our best to reply!) then you can proceed with contributing the new container. |
| 42 | + |
| 43 | +!!!WARNING |
| 44 | + |
| 45 | + Please raise an issue before you try to contribute a new container! It helps maintainersunderstand your use-case and motivation. |
| 46 | + This way we can keep pull requests forced on the "how", not the "why"! :pray: |
| 47 | + It also gives maintainers a chance to give you last-minute guidance on caveats orexpectations, particularly with |
| 48 | + new extra dependencies and how to manage them. |
| 49 | + |
| 50 | +### Module documentation |
| 51 | + |
| 52 | +Leave examples for others with your mew module such as `modules/<new_module>/basic_example.py`. You can create as many examples as you want. |
| 53 | + |
| 54 | +Create a new `docs/modules/<new_module>.md` describing the basic use of the new container. There is a [starter template provided here](https://raw.githubusercontent.com/testcontainers/testcontainers-python/blob/main/docs/modules/template.md){:target="\_blank"}. |
| 55 | + |
| 56 | +!!! important |
| 57 | + |
| 58 | + Make sure to add your new module to the sidebar nav in the `mkdocs.yml` |
| 59 | + |
| 60 | +## Raising issues |
| 61 | + |
| 62 | +We have [Issue Templates](https://raw.githubusercontent.com/testcontainers/testcontainers-python/refs/heads/main/.github/ISSUE_TEMPLATE/new-container.md){:target="\_blank"} to cover most cases, please try to adhere to them, they will guide you through the process. |
| 63 | +Try to look through the existing issues before you raise a new one. |
| 64 | + |
| 65 | +## Releasing versions |
| 66 | + |
| 67 | +We have automated Semantic Versioning and release via [release-please](https://github.com/testcontainers/testcontainers-python/blob/main/.github/workflows/release-please.yml){:target="\_blank"}. |
| 68 | +This takes care of: |
| 69 | + |
| 70 | +- Detecting the next version, based on the commits that landed on `main` |
| 71 | +- When a Release PR has been merged |
| 72 | + - Create a GitHub Release with the CHANGELOG included |
| 73 | + - Update the [CHANGELOG](https://github.com/testcontainers/testcontainers-python/blob/main/CHANGELOG.md){:target="\_blank"}, similar to the GitHub Release |
| 74 | + - Release to PyPI via a [trusted publisher](https://docs.pypi.org/trusted-publishers/using-a-publisher/){:target="\_blank"} |
| 75 | + - Automatically script updates in files where it's needed instead of hand-crafting it (i.e. in `pyproject.toml`) |
| 76 | + |
| 77 | +!!!DANGER |
| 78 | + |
| 79 | + Community modules are supported on a best-effort basis and for maintenance reasons, any change to them |
| 80 | + is only covered under minor and patch changes. |
| 81 | + Community modules changes DO NOT contribute to major version changes! |
| 82 | + If your community module container was broken by a minor or patch version change, check out the change logs! |
| 83 | + |
| 84 | +## Documentation contributions |
| 85 | + |
| 86 | +The _Testcontainers for Go_ documentation is a static site built with [MkDocs](https://www.mkdocs.org/){:target="\_blank"}. |
| 87 | +We use the [Material for MkDocs](https://squidfunk.github.io/mkdocs-material/){:target="\_blank"} theme, which offers a number of useful extensions to MkDocs. |
| 88 | + |
| 89 | +We publish our documentation using Netlify. |
| 90 | + |
| 91 | +### Adding code snippets |
| 92 | + |
| 93 | +To include code snippets in the documentation, we use the [codeinclude plugin](https://github.com/rnorth/mkdocs-codeinclude-plugin){:target="\_blank"}, which uses the following syntax: |
| 94 | + |
| 95 | +> <!--codeinclude--><br/> > [Human readable title for snippet](./relative_path_to_example_code.go) targeting_expression<br/> > [Human readable title for snippet](./relative_path_to_example_code.go) targeting_expression<br/> > <!--/codeinclude--><br/> |
| 96 | +
|
| 97 | +Where each title snippet in the same `codeinclude` block would represent a new tab |
| 98 | +in the snippet, and each `targeting_expression` would be: |
| 99 | + |
| 100 | +- `block:someString` or |
| 101 | +- `inside_block:someString` |
| 102 | + |
| 103 | +Please refer to the [codeinclude plugin documentation](https://github.com/rnorth/mkdocs-codeinclude-plugin){:target="\_blank"} for more information. |
| 104 | + |
| 105 | +### Previewing rendered content |
| 106 | + |
| 107 | +From the root directory of the repository, you can use the following command to build and serve the documentation locally: |
| 108 | + |
| 109 | +```shell |
| 110 | +make serve-docs |
| 111 | +``` |
| 112 | + |
| 113 | +It will use a Docker container to install the required dependencies and start a local server at `http://localhost:8000`. |
| 114 | + |
| 115 | +Once finished, you can destroy the container with the following command: |
| 116 | + |
| 117 | +```shell |
| 118 | +make clean-docs |
| 119 | +``` |
| 120 | + |
| 121 | +### PR preview deployments |
| 122 | + |
| 123 | +Note that documentation for pull requests will automatically be published by Netlify as 'deploy previews'. |
| 124 | +These deployment previews can be accessed via the `deploy/netlify` check that appears for each pull request. |
| 125 | + |
| 126 | +Please check the GitHub comment Netlify posts on the PR for the URL to the deployment preview. |
0 commit comments