xref: /petsc/src/binding/petsc4py/docs/source/contributing.rst (revision 6f33641175f69f1db294cc9ba81c3f4ad4f81d49)
1*6f336411SStefano ZampiniContributing
2*6f336411SStefano Zampini============
3*6f336411SStefano Zampini
4*6f336411SStefano ZampiniContributions from the user community are welcome. See
5*6f336411SStefano Zampinithe `PETSc developers <petsc:ind_developers>` documentation for general
6*6f336411SStefano Zampiniinformation on contributions.
7*6f336411SStefano Zampini
8*6f336411SStefano ZampiniNew contributions to petsc4py **must** adhere with the coding standards.
9*6f336411SStefano ZampiniWe use cython-lint_ for Cython and ruff_ for Python source codes.
10*6f336411SStefano ZampiniThese can be installed using::
11*6f336411SStefano Zampini
12*6f336411SStefano Zampini  $ python -m pip install -r src/binding/petsc4py/conf/requirements-lint.txt
13*6f336411SStefano Zampini
14*6f336411SStefano ZampiniIf you are contributing Cython code, you can check compliance with::
15*6f336411SStefano Zampini
16*6f336411SStefano Zampini  $ make cython-lint -C src/binding/petsc4py
17*6f336411SStefano Zampini
18*6f336411SStefano ZampiniFor Python code, run::
19*6f336411SStefano Zampini
20*6f336411SStefano Zampini  $ make ruff-lint -C src/binding/petsc4py
21*6f336411SStefano Zampini
22*6f336411SStefano ZampiniPython code can be auto-formatted using::
23*6f336411SStefano Zampini
24*6f336411SStefano Zampini  $ make ruff-lint RUFF_OPTS='format' -C src/binding/petsc4py
25*6f336411SStefano Zampini
26*6f336411SStefano ZampiniNew contributions to petsc4py must be tested.
27*6f336411SStefano ZampiniTests are located in the :file:`src/binding/petsc4py/test` folder.
28*6f336411SStefano ZampiniTo add a new test, either add a new :file:`test_xxx.py` or modify a
29*6f336411SStefano Zampinipre-existing file according to the
30*6f336411SStefano Zampini`unittest <https://docs.python.org/3/library/unittest.html>`_
31*6f336411SStefano Zampinispecifications.
32*6f336411SStefano Zampini
33*6f336411SStefano ZampiniIf you add a new :file:`test_xxx.py`, you can run the tests using::
34*6f336411SStefano Zampini
35*6f336411SStefano Zampini  $ cd src/binding/petsc4py
36*6f336411SStefano Zampini  $ python test/runtests.py -k test_xxx
37*6f336411SStefano Zampini
38*6f336411SStefano ZampiniIf instead you are modifying an existing :file:`test_xxx.py`,
39*6f336411SStefano Zampiniyou can test your additions by using the fully qualified name of the Python
40*6f336411SStefano Zampiniclass or method you are modifying, e.g.::
41*6f336411SStefano Zampini
42*6f336411SStefano Zampini  $ python test/runtests.py -k test_xxx.class_name.method_name
43*6f336411SStefano Zampini
44*6f336411SStefano ZampiniAll new code must include documentation in accordance with the `documentation
45*6f336411SStefano Zampinistandard <documentation_standards>`. To check for compliance, run::
46*6f336411SStefano Zampini
47*6f336411SStefano Zampini  $ make html SPHINXOPTS='-W' -C src/binding/petsc4py/docs/source
48*6f336411SStefano Zampini
49*6f336411SStefano Zampini.. warning::
50*6f336411SStefano Zampini
51*6f336411SStefano Zampini    The docstrings must not cause Sphinx warnings.
52*6f336411SStefano Zampini
53*6f336411SStefano Zampini.. _cython-lint: https://github.com/MarcoGorelli/cython-lint
54*6f336411SStefano Zampini.. _ruff: https://docs.astral.sh/ruff
55