| 1 |
############## |
| 2 |
Contributing |
| 3 |
############## |
| 4 |
|
| 5 |
build welcomes contributions from the community. This guide explains how to contribute to the project. |
| 6 |
|
| 7 |
******************* |
| 8 |
Development Setup |
| 9 |
******************* |
| 10 |
|
| 11 |
To contribute to build, you need a development environment set up on your local machine. Start by forking the |
| 12 |
`repository on GitHub <https://github.com/pypa/build>`_ and cloning your fork to your local machine. Once cloned, |
| 13 |
navigate to the project directory and install build in development mode along with all development dependencies. |
| 14 |
|
| 15 |
The project uses `tox <https://tox.wiki/>`_ for managing development environments and running tests. Install tox |
| 16 |
globally or in a virtual environment, then use it to run tests and other development tasks. The tox configuration |
| 17 |
includes environments for testing across multiple Python versions, running linters, building documentation, and more. |
| 18 |
|
| 19 |
********************** |
| 20 |
Development Workflow |
| 21 |
********************** |
| 22 |
|
| 23 |
The typical development workflow begins with creating a new branch for your changes. Branch names should be descriptive |
| 24 |
of the feature or fix you're implementing. Make your changes in this branch, ensuring you add or update tests to cover |
| 25 |
your modifications. |
| 26 |
|
| 27 |
Before committing, run the test suite locally to verify your changes don't break existing functionality. The project |
| 28 |
uses `pytest <https://docs.pytest.org/>`_ for testing, and you can run tests using tox. After ensuring tests pass, |
| 29 |
commit your changes with a clear, descriptive commit message following the project's commit conventions. |
| 30 |
|
| 31 |
Each pull request should include a changelog fragment. Create a file in ``docs/changelog/`` named |
| 32 |
``<pr_number>.<type>.rst`` where type is ``feature``, ``bugfix``, ``doc``, ``removal``, or ``misc``. The file should |
| 33 |
contain a single line describing the change. For example, ``123.feature.rst`` might contain ``Add support for custom |
| 34 |
backends - by :user:`contributor```. See ``docs/changelog/README.rst`` for complete details. |
| 35 |
|
| 36 |
When your changes are ready, push your branch to your fork on GitHub and open a pull request against the main build |
| 37 |
repository. The pull request description should clearly explain what changes you've made and why. Reference any related |
| 38 |
issues using GitHub's issue linking syntax. |
| 39 |
|
| 40 |
*************** |
| 41 |
Running Tests |
| 42 |
*************** |
| 43 |
|
| 44 |
Due to its nature, ``build`` has a somewhat complex test suite with two sets of tests: unit tests and integration tests. |
| 45 |
Unit tests verify the actual code implementation, while integration tests run build on real world projects as a sanity |
| 46 |
check. To run tests we use ``tox``. |
| 47 |
|
| 48 |
Some example commands for this project include running type checking with ``tox -e type``, running only unit tests |
| 49 |
against Python 3.14 with ``tox run -e 3.14``, running both unit and integration tests with ``tox run -- |
| 50 |
--run-integration``, running only integration tests with ``tox run -- --only-integration``, or running only integration |
| 51 |
tests with parallel tasks using ``tox run -- -n auto --only-integration``. |
| 52 |
|
| 53 |
Tests run in parallel by default, but if you pass any arguments, you need to include ``-n auto`` if you want to keep |
| 54 |
parallel runs. |
| 55 |
|
| 56 |
Integration tests take a long time to run, so they are disabled by default. Passing either ``--run-integration`` or |
| 57 |
``--only-integration`` arguments through ``tox`` to ``pytest`` will run them, where the latter will disable unit tests |
| 58 |
and only run integration tests. CI still runs both test suites. |
| 59 |
|
| 60 |
.. code-block:: console |
| 61 |
|
| 62 |
tox -- -n auto --only-integration |
| 63 |
|
| 64 |
The project has a fairly large environment matrix, running tests for all supported Python versions and implementations, |
| 65 |
and with the module being invoked directly from path, sdist install, or wheel install. To run tests only for Python |
| 66 |
3.14: |
| 67 |
|
| 68 |
.. code-block:: console |
| 69 |
|
| 70 |
tox -e 3.14 |
| 71 |
|
| 72 |
and with the module being invoked directly from path, sdist install, or wheel install. |
| 73 |
|
| 74 |
Additionally, there are environments for type checking and documentation building, plus extras like checking code with |
| 75 |
minimum versions of dependencies. For type checking, |
| 76 |
|
| 77 |
.. code-block:: console |
| 78 |
|
| 79 |
tox -e type |
| 80 |
|
| 81 |
Code coverage is tracked to ensure all code paths are tested. Aim for complete coverage of any new code you add. The CI |
| 82 |
system will report coverage metrics on your pull request and runs the test suite across all supported operating systems. |
| 83 |
|
| 84 |
************************ |
| 85 |
Code Style and Linting |
| 86 |
************************ |
| 87 |
|
| 88 |
build follows modern Python code style conventions enforced by `ruff <https://docs.astral.sh/ruff/>`_. Before submitting |
| 89 |
a pull request, run the linter to ensure your code meets the project's style guidelines. The ruff configuration is |
| 90 |
defined in the pyproject.toml file and includes both formatting and linting rules. |
| 91 |
|
| 92 |
The project also uses type annotations throughout the codebase. All new code should include appropriate type hints, and |
| 93 |
changes to existing code should preserve or improve type annotations. Use `pyright |
| 94 |
<https://microsoft.github.io/pyright/>`_ for type checking to verify your type annotations are correct. |
| 95 |
|
| 96 |
*************** |
| 97 |
Documentation |
| 98 |
*************** |
| 99 |
|
| 100 |
Good documentation is essential for build's users and contributors. If your contribution adds new features or changes |
| 101 |
existing behavior, update the relevant documentation files. The documentation is written in `reStructuredText |
| 102 |
<https://docutils.sourceforge.io/rst.html>`_ and built using `Sphinx <https://www.sphinx-doc.org/>`_. |
| 103 |
|
| 104 |
The documentation follows the `Diataxis framework <https://diataxis.fr/>`_, organizing content into tutorials, how-to |
| 105 |
guides, technical reference, and explanations. Place your documentation in the appropriate section based on its purpose. |
| 106 |
Tutorial content teaches beginners, how-to guides solve specific problems, reference sections document details, and |
| 107 |
explanations provide context and design rationale. |
| 108 |
|
| 109 |
Build the documentation locally to verify your changes render correctly. The tox configuration includes an environment |
| 110 |
for building docs. Review the rendered output to ensure formatting, links, and code examples appear as intended. |
| 111 |
|
| 112 |
********************** |
| 113 |
Pull Request Process |
| 114 |
********************** |
| 115 |
|
| 116 |
When you open a pull request, maintainers will review your changes and may request modifications. Be responsive to |
| 117 |
feedback and make requested changes in additional commits on your branch. The pull request will be merged once approved |
| 118 |
by a maintainer and all CI checks pass. |
| 119 |
|
| 120 |
The CI system runs the full test suite across all supported Python versions, verifies code style compliance, builds the |
| 121 |
documentation, and performs other checks. All CI checks must pass before a pull request can be merged. If CI fails, |
| 122 |
review the output to understand what went wrong and push fixes to your branch. |
| 123 |
|
| 124 |
***************************** |
| 125 |
Workflow Security Practices |
| 126 |
***************************** |
| 127 |
|
| 128 |
If your contribution involves modifying GitHub Actions workflows in the ``.github/workflows/`` directory, additional |
| 129 |
security considerations apply. The project follows modern security best practices to protect the release process and |
| 130 |
prevent supply chain attacks. All workflow modifications must maintain these security properties. |
| 131 |
|
| 132 |
Actions must be pinned to specific commit SHAs rather than tags or branch names. This prevents attacks where an attacker |
| 133 |
gains control of an action repository and moves a tag to point to malicious code. When adding or updating an action |
| 134 |
reference, use the full commit SHA as a comment alongside the action version for maintainability. For example, ``uses: |
| 135 |
actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6`` pins to a specific commit while documenting the version |
| 136 |
for future reference. |
| 137 |
|
| 138 |
Workflows must follow the principle of least privilege by setting ``permissions: {}`` at the workflow level and granting |
| 139 |
only the minimal necessary permissions to individual jobs. Each job should explicitly declare the permissions it |
| 140 |
requires, such as ``contents: read`` for jobs that only need to read repository contents or ``id-token: write`` for jobs |
| 141 |
that need to authenticate with external services using OIDC. Never grant broader permissions than necessary, as |
| 142 |
excessive permissions increase the impact of potential vulnerabilities. |
| 143 |
|
| 144 |
Checkout actions must include ``persist-credentials: false`` to prevent GitHub tokens from being persisted in the |
| 145 |
working directory where they could be leaked through artifacts or caches. This protection is particularly important for |
| 146 |
workflows that upload artifacts or create caches that might be accessible to others. The only exception is the |
| 147 |
pre-release workflow which needs persistent credentials to push commits and tags, and this exception is acceptable |
| 148 |
because the workflow runs in a protected environment requiring manual approval. |
| 149 |
|
| 150 |
When proposing workflow changes, consider the security implications of each modification. Adding new permissions, |
| 151 |
introducing new actions, or changing environment configurations all affect the project's security posture. If you're |
| 152 |
unsure whether a workflow change has security implications, ask a maintainer for guidance. The project uses automated |
| 153 |
security scanning with tools like zizmor to catch common workflow vulnerabilities, but manual review remains essential |
| 154 |
for maintaining security. |
| 155 |
|
| 156 |
**************** |
| 157 |
Issue Tracking |
| 158 |
**************** |
| 159 |
|
| 160 |
Before starting work on a significant feature or change, check the issue tracker to see if it's already been discussed. |
| 161 |
If not, consider opening an issue to discuss your proposed changes with maintainers. This helps ensure your contribution |
| 162 |
aligns with the project's direction and avoids duplicate effort. |
| 163 |
|
| 164 |
When reporting bugs, include detailed information about the issue. Provide the full error message and traceback, |
| 165 |
describe what you expected to happen versus what actually happened, list the steps to reproduce the problem, and include |
| 166 |
information about your environment such as Python version and operating system. |
| 167 |
|
| 168 |
For feature requests, explain the use case and why the feature would benefit build's users. Include examples of how the |
| 169 |
feature would be used if implemented. |
| 170 |
|
| 171 |
********************** |
| 172 |
Community Guidelines |
| 173 |
********************** |
| 174 |
|
| 175 |
build is part of the `PyPA (Python Packaging Authority) <https://www.pypa.io/>`_ ecosystem and follows the PyPA Code of |
| 176 |
Conduct. Be respectful and constructive in all interactions with other contributors. Focus feedback on the code and |
| 177 |
ideas, not on individuals. |
| 178 |
|
| 179 |
The project values clear communication, thorough testing, and well-documented code. Take time to explain your changes |
| 180 |
clearly in commit messages and pull requests. Write tests that future contributors can understand. Document not just |
| 181 |
what your code does, but why you made particular design choices. |
| 182 |
|
| 183 |
************** |
| 184 |
Getting Help |
| 185 |
************** |
| 186 |
|
| 187 |
If you have questions about contributing, several resources are available. The issue tracker can be used for questions, |
| 188 |
though complex discussions may be better suited to other venues. The project's documentation includes extensive |
| 189 |
information about build's design and implementation. |
| 190 |
|
| 191 |
For real-time discussion, consider joining the `PyPA Discord server <https://discord.gg/pypa>`_ where many packaging |
| 192 |
tool maintainers and contributors participate. You can also ask questions on the `Python Packaging Discourse forum |
| 193 |
<https://discuss.python.org/c/packaging/14>`_. |
| 194 |
|
| 195 |
********** |
| 196 |
See also |
| 197 |
********** |
| 198 |
|
| 199 |
- `PyPA Code of Conduct <https://www.pypa.io/en/latest/code-of-conduct/>`_ |
| 200 |
- `Issue Tracker <https://github.com/pypa/build/issues>`_ |
| 201 |
- `tox documentation <https://tox.wiki/>`_ |
| 202 |
- `pytest documentation <https://docs.pytest.org/>`_ |
| 203 |
- `ruff documentation <https://docs.astral.sh/ruff/>`_ |
| 204 |
- `Sphinx documentation <https://www.sphinx-doc.org/>`_ |
| 205 |
- `PyPA Discord <https://discord.gg/pypa>`_ |
| 206 |
- `Python Packaging Discourse <https://discuss.python.org/c/packaging/14>`_ |