Skip to content

Commit

Permalink
Update docs for typing, etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
jwhitlock committed Jun 24, 2024
1 parent 333a7ec commit 86b8341
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 2 deletions.
66 changes: 64 additions & 2 deletions docs/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,22 @@ Patches are more than welcome! You can find the issue tracker `on GitHub
<https://github.com/mozilla/django-csp/issues>`_ and we'd love pull
requests.

Setup
=====
To install all the requirements (probably into a virtualenv_):

.. code-block:: bash
pip install -e .
pip install -e ".[dev]"
This installs:

* All the text requirements
* All the typing requirements
* pre-commit_, for checking styles
* tox_, for running tests against multiple environments
* Sphinx_ and document building requirements

Style
=====
Expand Down Expand Up @@ -44,9 +60,55 @@ To run the tests with coverage and get a report, use the following command:
pytest --cov=csp --cov-config=.coveragerc
To run the tests like Github Actions does, you'll need pyenv_:

.. code-block:: bash
pyenv install 3.8 3.9 3.10 3.11 3.12 pypy3.8 pypy3.9 pypy3.10
pyenv local 3.8 3.9 3.10. 3.11 3.12 pypy3.8 pypy3.9 pypy3.10
pip install -e ".[dev]" # installs tox
tox # run sequentially
tox run-parallel # run in parallel, may cause issues on coverage step
tox -e 3.12-4.2.x # run tests on Python 3.12 and Django 4.x
tox --listenvs # list all the environments
Type Checking
=============

New code should have type annotations and pass mypy_ in strict mode. Use the
typing syntax available in the earliest supported Python version 3.8.

To check types:

.. code-block:: bash
pip install -e ".[typing]"
mypy .
If you make a lot of changes, it can help to clear the mypy cache:

.. code-block:: bash
mypy --no-incremental .
Updating Documentation
======================

To rebuild documentation locally:

.. code-block:: bash
pip install -e ".[dev]"
cd docs
make html
open _build/html/index.html # On macOS
.. _PEP8: http://www.python.org/dev/peps/pep-0008/
.. _Sphinx: https://www.sphinx-doc.org/en/master/index.html
.. _mypy: https://mypy.readthedocs.io/en/stable/
.. _pre-commit: https://pre-commit.com/#install
.. _pyenv: https://github.com/pyenv/pyenv
.. _pytest: https://pytest.org/latest/usage.html
.. _ruff: https://pypi.org/project/ruff/
.. _tox: https://tox.wiki/en/stable/
.. _virtualenv: http://www.virtualenv.org/
.. _pytest: https://pytest.org/latest/usage.html
.. _pre-commit: https://pre-commit.com/#install
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ optional-dependencies.dev = [
"Sphinx",
"sphinx_rtd_theme",
"tox",
"tox-gh-actions",
"types-setuptools",
]
optional-dependencies.jinja2 = [
Expand Down

0 comments on commit 86b8341

Please sign in to comment.