Diff of /docs/contributing.rst [000000] .. [6ff4a8]

Switch to unified view

a b/docs/contributing.rst
1
Contributing guide
2
~~~~~~~~~~~~~~~~~~
3
4
Table of Contents
5
=================
6
- `Contributing to moscot`_
7
- `Codebase structure`_
8
- `Code style guide`_
9
- `Testing`_
10
- `Writing documentation`_
11
- `Writing tutorials/examples`_
12
- `Submitting a PR`_
13
14
Contributing to moscot
15
-----------------------
16
Clone moscot from source as::
17
18
    git clone https://github.com/theislab/moscot
19
    cd moscot
20
    git checkout main
21
22
Install the test and development mode::
23
24
    pip install -e'.[dev,test]'
25
26
Optionally install pre-commit. This will ensure that the pushed code passes the linting steps::
27
28
    pre-commit install
29
30
Although the last step is not necessary, it is highly recommended, since it will help you to pass the linting step
31
(see `Code style guide`_). If you did install ``pre-commit`` but are unable to decipher some flags, you can
32
still commit using the ``--no-verify``.
33
34
Codebase structure
35
------------------
36
The moscot project:
37
38
- `moscot <../src/moscot>`_: the root of the package.
39
40
  - `moscot/backends <../src/moscot/backends>`_: the OTT backend module, which deals with OTT solvers and output functions.
41
  - `moscot/base <../src/moscot/base>`_: contains base moscot classes.
42
    - `moscot/base/problems <../src/moscot/base/problems>`_: the moscot problems module.
43
  - `moscot/costs <../src/moscot/costs>`_: contains different costs computation functions.
44
  - `moscot/plotting <../src/moscot/plotting>`_: the plotting module.
45
  - `moscot/problems <../src/moscot/problems>`_: the functionality of general problems classes, subdivided into problem types.
46
  - `moscot/utils <../src/moscot/utils>`_: contains various utility functions.
47
  - `moscot/datasets.py <../src/moscot/datasets.py>`_: contains loading and simulating functions for the datasets.
48
49
Tests structure:
50
51
- `tests <../tests>`_: the root of the package
52
53
  - `tests/backends <../tests/backends>`_: tests for the ott backend.
54
  - `tests/costs <../tests/costs>`_ tests for the solving costs.
55
  - `tests/data <../tests/data>`_: tests for the simulated data module.
56
  - `tests/datasets <../tests/datasets>`_: tests for the datasets.
57
  - `tests/plotting <../tests/plotting>`_ tests for the plotting module.
58
  - `tests/problems <../tests/problems>`_ tests for the problem classes, divided by problem type.
59
  - `tests/solvers <../tests/solvers>`_ tests for the solvers.
60
  - `tests/utils <../tests/utils>`_ tests for the utility functions.
61
  - `tests/conftest.py <../tests/conftest.py>`_: ``pytest`` fixtures and utility functions.
62
63
Code style guide
64
----------------
65
We rely on ``black`` and ``isort`` to do the most of the formatting - both of them are integrated as pre-commit hooks.
66
You can use ``tox`` to check the changes::
67
68
    tox -e lint-code
69
70
Furthermore, we also require that:
71
72
- functions are fully type-annotated.
73
- exception messages are capitalized and end with ``.``.
74
- warning messages are capitalized and do not end with ``.``.
75
- when referring to variable inside an error/warning message, enclose its name in \`.
76
- when referring to variable inside a docstrings, enclose its name in \``.
77
78
Testing
79
-------
80
We use ``tox`` to automate our testing, as well as linting and documentation creation. To run the tests, run::
81
82
    tox -e py{310,311}-{linux,macos}
83
84
depending on the Python version(s) in your ``PATH`` and your operating system. We use ``flake8`` and ``mypy`` to further
85
analyze the code. Use ``# noqa: <error1>,<error2>`` to ignore certain ``flake8`` errors and
86
``# type: ignore[error1,error2]`` to ignore specific ``mypy`` errors.
87
88
To run only a subset of tests, run::
89
90
    tox -e <environment> -- <name>
91
92
where ``<name>`` can be a path to a test file/directory or a name of a test function/class.
93
For example, to run only the tests in the ``plotting`` module, use::
94
95
    tox -e py310-linux -- tests/plotting/test_plotting.py
96
97
If needed, a specific ``tox`` environment can be recreated as::
98
99
    tox -e <environment> --recreate
100
101
Writing documentation
102
---------------------
103
We use ``numpy``-style docstrings for the documentation with the following additions and modifications:
104
105
- no type hints in the docstring (applies also for the return statement) are allowed,
106
  since all functions are required to have the type hints in their signatures.
107
- when referring to some argument within the same docstring, enclose that reference in \`\`.
108
- prefer putting references in the ``references.bib`` instead under the ``References`` sections of the docstring.
109
- use ``docrep`` for repeating documentation.
110
111
In order to build the documentation, run::
112
113
    tox -e build-docs
114
115
Since the tutorials are hosted on a separate repository (see `Writing tutorials/examples`_), we download the newest
116
tutorials/examples from there and build the documentation here.
117
118
To validate the links inside the documentation, run::
119
120
    tox -e lint-docs
121
122
If you need to clean the artifacts from previous documentation builds, run::
123
124
    tox -e clean-docs
125
126
Writing tutorials/examples
127
--------------------------
128
Tutorials and examples are hosted on a separate repository called `moscot_notebooks
129
<https://github.com/theislab/moscot_notebooks>`_.
130
Please refer to this `guide <https://github.com/theislab/moscot_notebooks/blob/main/CONTRIBUTING.rst>`_ for more information.
131
132
Submitting a PR
133
---------------
134
Before submitting a new pull request, please make sure you followed these instructions:
135
136
- make sure that you've branched off ``main`` and are merging into ``main``
137
- make sure that your code follows the above specified conventions
138
  (see `Code style guide`_ and `Writing documentation`_).
139
- if applicable, make sure you've added/modified at least 1 test to account for the changes you've made
140
- make sure that all tests pass locally (see `Testing`_).
141
- if there is no issue which this PR solves, create a new `one <https://github.com/theislab/moscot/issues/new>`_
142
  briefly explaining what the problem is.
143
- make sure that the section under ``## Description`` is properly formatted if automatically generating release notes.