Skip to content

Commit 4704462

Browse files
committed
docs: move and update the new dependency section of the contribution guide
1 parent 93f2ca1 commit 4704462

1 file changed

Lines changed: 23 additions & 7 deletions

File tree

docs/contributions/how_to_contribute.rst

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ You can then also install the pre-commit hooks with
8989
9090
pre-commit install
9191
92-
1. Develop your contribution
92+
93+
3. Develop your contribution
9394
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9495

9596
You are now ready to work on your contribution. Check out a branch on your forked repository and start coding!
@@ -111,6 +112,27 @@ Tensor Annotations with jaxtyping
111112
We use `jaxtyping <https://github.com/google/jaxtyping>`_ to annotate PyTorch tensors with both shape and dtype information, mainly in collate functions, dataloaders, and model interfaces. This improves readability, helps catch shape/type mismatches early, and makes functions more self-documenting. Contributors are encouraged to follow this style when defining tensor inputs or outputs—for details and examples, see the official jaxtyping documentation.
112113

113114

115+
**How to add a new dependency**
116+
117+
Your contribution may require packages that |pruna| does list as a dependency yet. Declare them in ``pyproject.toml`` and mention them in your pull request so reviewers can weigh impact and versioning.
118+
119+
Use the ``dependencies`` section when the library is generally required for |pruna| to work as intended across typical usage.
120+
121+
If it should not be installed for every |pruna| user, put it under ``optional-dependencies``. This often applies when a dependency is too heavy or platform-specific, or only needed for one backend. Then follow **these steps to add a new optional extra**:
122+
123+
1. Define the dependency group in ``pyproject.toml`` under ``[project.optional-dependencies]``.
124+
2. If this extra is required for an algorithm, set the ``required_install`` attribute on the algorithm class, for example ``required_install = "uv pip install 'pruna[my-extra]'"``.
125+
3. Register a matching ``requires_my_extra`` marker in ``tests/conftest.py`` and mark tests that need the extra.
126+
4. Finally, if CPU tests rely on that extra, update ``.github/workflows/tests.yaml``: in the ``test`` job, find ``strategy`` → ``matrix`` → ``include`` and append your extra:
127+
128+
.. code-block:: yaml
129+
include:
130+
... # existing include rows
131+
- name: my-extra
132+
extras: "--extra my-extra"
133+
mark_filter: "requires_my_extra"
134+
135+
114136
4. Run the tests
115137
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
116138

@@ -131,12 +153,6 @@ For specific test markers:
131153
132154
uv run pytest -m "cpu and not slow"
133155
134-
**How and when to add a new optional extra**
135-
136-
Add a new extra when a feature or algorithm needs dependencies that should not be installed for every |pruna| user, for example because they are heavy, platform-specific, or only needed for one backend.
137-
Define the dependency group in ``pyproject.toml`` under ``[project.optional-dependencies]``.
138-
For algorithms, set ``required_install`` on the algorithm class, for example ``required_install = "uv pip install 'pruna[my-extra]'"``; this is used in the import error shown when the extra is missing.
139-
Finally, register a matching ``requires_<extra>`` marker in ``tests/conftest.py``, mark tests that need the extra, and add the extra to the CI matrix with its install option and marker filter, for example ``extras: "--extra my-extra"`` and ``mark_filter: "requires_my_extra"``.
140156
141157
**If you used Option B (pip/conda):**
142158

0 commit comments

Comments
 (0)