2020-05-30 09:08:50 -05:00
|
|
|
======================
|
|
|
|
Contributing to Sphinx
|
|
|
|
======================
|
2016-12-17 09:10:40 -06:00
|
|
|
|
2020-05-30 09:08:50 -05:00
|
|
|
There are many ways you can contribute to Sphinx, be it filing bug reports or
|
|
|
|
feature requests, writing new documentation or submitting patches for new or
|
|
|
|
fixed behavior. This guide serves to illustrate how you can get started with
|
|
|
|
this.
|
2016-12-16 09:52:11 -06:00
|
|
|
|
2022-07-18 16:48:28 -05:00
|
|
|
Get help
|
|
|
|
--------
|
2016-12-16 09:52:11 -06:00
|
|
|
|
2020-05-30 09:08:50 -05:00
|
|
|
The Sphinx community maintains a number of mailing lists and IRC channels.
|
2016-12-16 09:52:11 -06:00
|
|
|
|
2020-08-15 06:22:22 -05:00
|
|
|
Stack Overflow with tag `python-sphinx`_
|
|
|
|
Questions and answers about use and development.
|
|
|
|
|
2016-12-16 09:52:11 -06:00
|
|
|
sphinx-users <sphinx-users@googlegroups.com>
|
|
|
|
Mailing list for user support.
|
|
|
|
|
|
|
|
sphinx-dev <sphinx-dev@googlegroups.com>
|
|
|
|
Mailing list for development related discussions.
|
|
|
|
|
2021-06-01 05:09:19 -05:00
|
|
|
#sphinx-doc on irc.libera.chat
|
2016-12-16 09:52:11 -06:00
|
|
|
IRC channel for development questions and user support.
|
|
|
|
|
2020-08-15 06:22:22 -05:00
|
|
|
.. _python-sphinx: https://stackoverflow.com/questions/tagged/python-sphinx
|
2016-12-16 09:52:11 -06:00
|
|
|
|
|
|
|
Bug Reports and Feature Requests
|
|
|
|
--------------------------------
|
|
|
|
|
|
|
|
If you have encountered a problem with Sphinx or have an idea for a new
|
2017-04-18 23:08:36 -05:00
|
|
|
feature, please submit it to the `issue tracker`_ on GitHub or discuss it
|
2017-10-03 04:00:40 -05:00
|
|
|
on the `sphinx-dev`_ mailing list.
|
2016-12-16 09:52:11 -06:00
|
|
|
|
|
|
|
For bug reports, please include the output produced during the build process
|
2017-10-03 04:00:40 -05:00
|
|
|
and also the log file Sphinx creates after it encounters an unhandled
|
2016-12-16 09:52:11 -06:00
|
|
|
exception. The location of this file should be shown towards the end of the
|
|
|
|
error message.
|
|
|
|
|
|
|
|
Including or providing a link to the source files involved may help us fix the
|
|
|
|
issue. If possible, try to create a minimal project that produces the error
|
|
|
|
and post that instead.
|
|
|
|
|
|
|
|
.. _`issue tracker`: https://github.com/sphinx-doc/sphinx/issues
|
2017-10-03 04:00:40 -05:00
|
|
|
.. _`sphinx-dev`: mailto:sphinx-dev@googlegroups.com
|
2016-12-16 09:52:11 -06:00
|
|
|
|
|
|
|
|
2022-07-18 16:48:28 -05:00
|
|
|
Contribute code
|
|
|
|
---------------
|
2020-05-30 09:08:50 -05:00
|
|
|
|
|
|
|
The Sphinx source code is managed using Git and is hosted on `GitHub`__. The
|
|
|
|
recommended way for new contributors to submit code to Sphinx is to fork this
|
|
|
|
repository and submit a pull request after committing changes to their fork.
|
|
|
|
The pull request will then need to be approved by one of the core developers
|
|
|
|
before it is merged into the main repository.
|
|
|
|
|
|
|
|
.. __: https://github.com/sphinx-doc/sphinx
|
|
|
|
|
2022-07-18 16:48:28 -05:00
|
|
|
.. _contribute-get-started:
|
|
|
|
|
2020-05-30 09:08:50 -05:00
|
|
|
Getting started
|
2016-12-16 09:52:11 -06:00
|
|
|
~~~~~~~~~~~~~~~
|
|
|
|
|
2020-05-30 09:08:50 -05:00
|
|
|
Before starting on a patch, we recommend checking for open issues or open a
|
|
|
|
fresh issue to start a discussion around a feature idea or a bug. If you feel
|
|
|
|
uncomfortable or uncertain about an issue or your changes, feel free to email
|
|
|
|
the *sphinx-dev* mailing list.
|
|
|
|
|
2016-12-16 09:52:11 -06:00
|
|
|
These are the basic steps needed to start developing on Sphinx.
|
|
|
|
|
2017-04-18 23:08:36 -05:00
|
|
|
#. Create an account on GitHub.
|
2016-12-16 09:52:11 -06:00
|
|
|
|
|
|
|
#. Fork the main Sphinx repository (`sphinx-doc/sphinx
|
2017-04-18 23:08:36 -05:00
|
|
|
<https://github.com/sphinx-doc/sphinx>`_) using the GitHub interface.
|
2016-12-16 09:52:11 -06:00
|
|
|
|
|
|
|
#. Clone the forked repository to your machine. ::
|
|
|
|
|
|
|
|
git clone https://github.com/USERNAME/sphinx
|
|
|
|
cd sphinx
|
|
|
|
|
|
|
|
#. Checkout the appropriate branch.
|
|
|
|
|
2019-01-12 23:50:21 -06:00
|
|
|
Sphinx adopts Semantic Versioning 2.0.0 (refs: https://semver.org/ ).
|
2019-01-12 07:22:42 -06:00
|
|
|
|
|
|
|
For changes that preserves backwards-compatibility of API and features,
|
2020-02-09 05:28:23 -06:00
|
|
|
they should be included in the next MINOR release, use the ``A.x`` branch.
|
2019-01-12 23:50:21 -06:00
|
|
|
::
|
2016-12-16 09:52:11 -06:00
|
|
|
|
2020-02-09 05:28:23 -06:00
|
|
|
git checkout A.x
|
2016-12-16 09:52:11 -06:00
|
|
|
|
2019-01-12 07:22:42 -06:00
|
|
|
For incompatible or other substantial changes that should wait until the
|
2019-01-12 23:50:21 -06:00
|
|
|
next MAJOR release, use the ``master`` branch.
|
|
|
|
|
|
|
|
For urgent release, a new PATCH branch must be branched from the newest
|
2020-05-30 09:08:50 -05:00
|
|
|
release tag (see :doc:`release-process` for detail).
|
2016-12-16 09:52:11 -06:00
|
|
|
|
2017-10-03 04:00:40 -05:00
|
|
|
#. Setup a virtual environment.
|
2016-12-16 09:52:11 -06:00
|
|
|
|
2017-10-03 04:00:40 -05:00
|
|
|
This is not necessary for unit testing, thanks to ``tox``, but it is
|
|
|
|
necessary if you wish to run ``sphinx-build`` locally or run unit tests
|
2020-05-30 09:08:50 -05:00
|
|
|
without the help of ``tox``::
|
2017-10-03 04:00:40 -05:00
|
|
|
|
|
|
|
virtualenv ~/.venv
|
|
|
|
. ~/.venv/bin/activate
|
2016-12-16 09:52:11 -06:00
|
|
|
pip install -e .
|
|
|
|
|
2020-05-30 09:08:50 -05:00
|
|
|
#. Create a new working branch. Choose any name you like. ::
|
2016-12-16 09:52:11 -06:00
|
|
|
|
|
|
|
git checkout -b feature-xyz
|
|
|
|
|
|
|
|
#. Hack, hack, hack.
|
|
|
|
|
2020-05-30 09:08:50 -05:00
|
|
|
Write your code along with tests that shows that the bug was fixed or that
|
|
|
|
the feature works as expected.
|
2016-12-16 09:52:11 -06:00
|
|
|
|
2020-05-30 09:08:50 -05:00
|
|
|
#. Add a bullet point to :file:`CHANGES` if the fix or feature is not trivial
|
|
|
|
(small doc updates, typo fixes), then commit::
|
2016-12-16 09:52:11 -06:00
|
|
|
|
|
|
|
git commit -m '#42: Add useful new feature that does this.'
|
|
|
|
|
2017-04-18 23:08:36 -05:00
|
|
|
GitHub recognizes certain phrases that can be used to automatically
|
2020-05-30 09:08:50 -05:00
|
|
|
update the issue tracker. For example::
|
2016-12-16 09:52:11 -06:00
|
|
|
|
|
|
|
git commit -m 'Closes #42: Fix invalid markup in docstring of Foo.bar.'
|
|
|
|
|
|
|
|
would close issue #42.
|
|
|
|
|
2020-05-30 09:08:50 -05:00
|
|
|
#. Push changes in the branch to your forked repository on GitHub::
|
2016-12-16 09:52:11 -06:00
|
|
|
|
|
|
|
git push origin feature-xyz
|
|
|
|
|
|
|
|
#. Submit a pull request from your branch to the respective branch (``master``
|
2020-02-09 05:28:23 -06:00
|
|
|
or ``A.x``).
|
2016-12-16 09:52:11 -06:00
|
|
|
|
|
|
|
#. Wait for a core developer to review your changes.
|
|
|
|
|
2020-05-30 09:08:50 -05:00
|
|
|
Coding style
|
2020-03-28 08:37:22 -05:00
|
|
|
~~~~~~~~~~~~
|
|
|
|
|
2020-05-30 09:08:50 -05:00
|
|
|
Please follow these guidelines when writing code for Sphinx:
|
2016-12-16 09:52:11 -06:00
|
|
|
|
2020-10-05 08:16:56 -05:00
|
|
|
* Try to use the same code style as used in the rest of the project.
|
2016-12-16 09:52:11 -06:00
|
|
|
|
|
|
|
* For non-trivial changes, please update the :file:`CHANGES` file. If your
|
|
|
|
changes alter existing behavior, please document this.
|
|
|
|
|
|
|
|
* New features should be documented. Include examples and use cases where
|
|
|
|
appropriate. If possible, include a sample that is displayed in the
|
|
|
|
generated output.
|
|
|
|
|
|
|
|
* When adding a new configuration variable, be sure to document it and update
|
2019-01-07 01:29:11 -06:00
|
|
|
:file:`sphinx/cmd/quickstart.py` if it's important enough.
|
2016-12-16 09:52:11 -06:00
|
|
|
|
|
|
|
* Add appropriate unit tests.
|
|
|
|
|
2023-02-14 20:10:09 -06:00
|
|
|
Style and type checks can be run as follows::
|
2016-12-16 09:52:11 -06:00
|
|
|
|
2023-02-14 20:10:09 -06:00
|
|
|
ruff .
|
|
|
|
mypy sphinx/
|
2016-12-16 09:52:11 -06:00
|
|
|
|
2020-05-30 09:08:50 -05:00
|
|
|
Unit tests
|
|
|
|
~~~~~~~~~~
|
2016-12-16 09:52:11 -06:00
|
|
|
|
2020-05-30 09:08:50 -05:00
|
|
|
Sphinx is tested using `pytest`__ for Python code and `Karma`__ for JavaScript.
|
2016-12-16 09:52:11 -06:00
|
|
|
|
2020-05-30 09:08:50 -05:00
|
|
|
.. __: https://docs.pytest.org/en/latest/
|
|
|
|
.. __: https://karma-runner.github.io
|
2016-12-16 09:52:11 -06:00
|
|
|
|
2020-05-30 09:08:50 -05:00
|
|
|
To run Python unit tests, we recommend using ``tox``, which provides a number
|
|
|
|
of targets and allows testing against multiple different Python environments:
|
2016-12-16 09:52:11 -06:00
|
|
|
|
2020-05-30 09:08:50 -05:00
|
|
|
* To list all possible targets::
|
2016-12-16 09:52:11 -06:00
|
|
|
|
2020-05-30 09:08:50 -05:00
|
|
|
tox -av
|
2016-12-16 09:52:11 -06:00
|
|
|
|
2022-06-16 13:33:55 -05:00
|
|
|
* To run unit tests for a specific Python version, such as Python 3.10::
|
2016-12-16 09:52:11 -06:00
|
|
|
|
2022-06-16 13:33:55 -05:00
|
|
|
tox -e py310
|
2016-12-16 09:52:11 -06:00
|
|
|
|
2020-05-30 09:08:50 -05:00
|
|
|
* To run unit tests for a specific Python version and turn on deprecation
|
2022-12-16 09:38:53 -06:00
|
|
|
warnings so they're shown in the test output::
|
2018-02-06 08:38:46 -06:00
|
|
|
|
2023-02-01 05:15:05 -06:00
|
|
|
PYTHONWARNINGS=error tox -e py310
|
2017-05-07 02:46:44 -05:00
|
|
|
|
2022-12-16 09:38:53 -06:00
|
|
|
* Arguments to ``pytest`` can be passed via ``tox``, e.g., in order to run a
|
2020-05-30 09:08:50 -05:00
|
|
|
particular test::
|
2017-05-07 02:46:44 -05:00
|
|
|
|
2022-06-16 13:33:55 -05:00
|
|
|
tox -e py310 tests/test_module.py::test_new_feature
|
2017-05-07 02:46:44 -05:00
|
|
|
|
2020-05-30 09:08:50 -05:00
|
|
|
You can also test by installing dependencies in your local environment::
|
2017-05-07 02:46:44 -05:00
|
|
|
|
2020-05-30 09:08:50 -05:00
|
|
|
pip install .[test]
|
2017-05-07 02:46:44 -05:00
|
|
|
|
2020-05-30 09:08:50 -05:00
|
|
|
To run JavaScript tests, use ``npm``::
|
2017-05-07 02:46:44 -05:00
|
|
|
|
2020-05-30 09:08:50 -05:00
|
|
|
npm install
|
|
|
|
npm run test
|
2017-05-07 02:46:44 -05:00
|
|
|
|
2020-05-30 09:08:50 -05:00
|
|
|
New unit tests should be included in the ``tests`` directory where
|
|
|
|
necessary:
|
|
|
|
|
|
|
|
* For bug fixes, first add a test that fails without your changes and passes
|
|
|
|
after they are applied.
|
|
|
|
|
|
|
|
* Tests that need a ``sphinx-build`` run should be integrated in one of the
|
|
|
|
existing test modules if possible. New tests that to ``@with_app`` and
|
|
|
|
then ``build_all`` for a few assertions are not good since *the test suite
|
|
|
|
should not take more than a minute to run*.
|
2018-07-22 13:20:32 -05:00
|
|
|
|
|
|
|
.. versionadded:: 1.8
|
2020-05-30 09:08:50 -05:00
|
|
|
|
2018-07-22 13:20:32 -05:00
|
|
|
Sphinx also runs JavaScript tests.
|
2020-03-28 08:37:22 -05:00
|
|
|
|
2020-05-30 09:08:50 -05:00
|
|
|
.. versionadded:: 1.6
|
|
|
|
|
|
|
|
``sphinx.testing`` is added as a experimental.
|
2020-03-28 08:37:22 -05:00
|
|
|
|
2020-05-30 09:08:50 -05:00
|
|
|
.. versionchanged:: 1.5.2
|
2020-03-28 08:37:22 -05:00
|
|
|
|
2020-05-30 09:08:50 -05:00
|
|
|
Sphinx was switched from nose to pytest.
|
2020-03-28 08:37:22 -05:00
|
|
|
|
2020-05-30 09:08:50 -05:00
|
|
|
.. todo:: The below belongs in the developer guide
|
2020-03-28 08:37:22 -05:00
|
|
|
|
2020-05-30 09:08:50 -05:00
|
|
|
Utility functions and pytest fixtures for testing are provided in
|
|
|
|
``sphinx.testing``. If you are a developer of Sphinx extensions, you can write
|
2022-12-16 09:38:53 -06:00
|
|
|
unit tests by using pytest. At this time, ``sphinx.testing`` will help your
|
2020-05-30 09:08:50 -05:00
|
|
|
test implementation.
|
|
|
|
|
|
|
|
How to use pytest fixtures that are provided by ``sphinx.testing``? You can
|
|
|
|
require ``'sphinx.testing.fixtures'`` in your test modules or ``conftest.py``
|
|
|
|
files like this::
|
|
|
|
|
|
|
|
pytest_plugins = 'sphinx.testing.fixtures'
|
|
|
|
|
|
|
|
If you want to know more detailed usage, please refer to ``tests/conftest.py``
|
2022-12-16 09:38:53 -06:00
|
|
|
and other ``test_*.py`` files under the ``tests`` directory.
|
2020-05-30 09:08:50 -05:00
|
|
|
|
|
|
|
|
2022-07-18 16:48:28 -05:00
|
|
|
Contribute documentation
|
|
|
|
------------------------
|
|
|
|
|
|
|
|
Contributing to documentation involves modifying the source files found in the
|
|
|
|
``doc/`` folder. To get started, you should first follow :ref:`contribute-get-started`,
|
|
|
|
and then take the steps below to work with the documentation.
|
|
|
|
|
|
|
|
The following sections describe how to get started with contributing
|
|
|
|
documentation, as well as key aspects of a few different tools that we use.
|
2020-05-30 09:08:50 -05:00
|
|
|
|
|
|
|
.. todo:: Add a more extensive documentation contribution guide.
|
|
|
|
|
2022-07-18 16:48:28 -05:00
|
|
|
Build the documentation
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
2023-02-14 20:10:09 -06:00
|
|
|
To build the documentation, run the following command::
|
2022-07-18 16:48:28 -05:00
|
|
|
|
2023-02-14 20:10:09 -06:00
|
|
|
sphinx-build -M html ./doc ./build/sphinx -W --keep-going
|
2020-05-30 09:08:50 -05:00
|
|
|
|
2022-07-18 16:48:28 -05:00
|
|
|
This will parse the Sphinx documentation's source files and generate HTML for
|
|
|
|
you to preview in ``build/sphinx/html``.
|
|
|
|
|
|
|
|
You can also build a **live version of the documentation** that you can preview
|
|
|
|
in the browser. It will detect changes and reload the page any time you make
|
|
|
|
edits. To do so, run the following command::
|
|
|
|
|
2023-02-14 20:10:09 -06:00
|
|
|
sphinx-autobuild ./doc ./build/sphinx/
|
2022-07-18 16:48:28 -05:00
|
|
|
|
2020-05-30 09:08:50 -05:00
|
|
|
Translations
|
|
|
|
~~~~~~~~~~~~
|
2020-03-28 08:37:22 -05:00
|
|
|
|
|
|
|
The parts of messages in Sphinx that go into builds are translated into several
|
|
|
|
locales. The translations are kept as gettext ``.po`` files translated from the
|
|
|
|
master template :file:`sphinx/locale/sphinx.pot`.
|
|
|
|
|
2021-05-16 08:16:09 -05:00
|
|
|
Sphinx uses `Babel <https://babel.pocoo.org/en/latest/>`_ to extract messages
|
2022-04-16 14:58:59 -05:00
|
|
|
and maintain the catalog files. The ``utils`` directory contains a helper
|
|
|
|
script, ``babel_runner.py``.
|
2020-03-28 08:37:22 -05:00
|
|
|
|
2022-04-16 14:58:59 -05:00
|
|
|
* Use ``python babel_runner.py extract`` to update the ``.pot`` template.
|
|
|
|
* Use ``python babel_runner.py update`` to update all existing language
|
2020-03-28 08:37:22 -05:00
|
|
|
catalogs in ``sphinx/locale/*/LC_MESSAGES`` with the current messages in the
|
|
|
|
template file.
|
2022-04-16 14:58:59 -05:00
|
|
|
* Use ``python babel_runner.py compile`` to compile the ``.po`` files to binary
|
2020-03-28 08:37:22 -05:00
|
|
|
``.mo`` files and ``.js`` files.
|
|
|
|
|
2022-04-16 14:58:59 -05:00
|
|
|
When an updated ``.po`` file is submitted, run
|
|
|
|
``python babel_runner.py compile`` to commit both the source and the compiled
|
|
|
|
catalogs.
|
2020-03-28 08:37:22 -05:00
|
|
|
|
|
|
|
When a new locale is submitted, add a new directory with the ISO 639-1 language
|
|
|
|
identifier and put ``sphinx.po`` in there. Don't forget to update the possible
|
|
|
|
values for :confval:`language` in ``doc/usage/configuration.rst``.
|
|
|
|
|
|
|
|
The Sphinx core messages can also be translated on `Transifex
|
2020-11-05 08:52:59 -06:00
|
|
|
<https://www.transifex.com/sphinx-doc/sphinx-1/>`_. There ``tx`` client tool,
|
|
|
|
which is provided by the ``transifex_client`` Python package, can be used to
|
|
|
|
pull translations in ``.po`` format from Transifex. To do this, go to
|
2020-05-30 09:08:50 -05:00
|
|
|
``sphinx/locale`` and then run ``tx pull -f -l LANG`` where ``LANG`` is an
|
2022-04-16 14:58:59 -05:00
|
|
|
existing language identifier. It is good practice to run
|
|
|
|
``python babel_runner.py update`` afterwards to make sure the ``.po`` file has the
|
|
|
|
canonical Babel formatting.
|
2020-05-30 09:08:50 -05:00
|
|
|
|
|
|
|
|
|
|
|
Debugging tips
|
|
|
|
--------------
|
|
|
|
|
|
|
|
* Delete the build cache before building documents if you make changes in the
|
|
|
|
code by running the command ``make clean`` or using the
|
|
|
|
:option:`sphinx-build -E` option.
|
|
|
|
|
|
|
|
* Use the :option:`sphinx-build -P` option to run ``pdb`` on exceptions.
|
|
|
|
|
|
|
|
* Use ``node.pformat()`` and ``node.asdom().toxml()`` to generate a printable
|
|
|
|
representation of the document structure.
|
|
|
|
|
|
|
|
* Set the configuration variable :confval:`keep_warnings` to ``True`` so
|
|
|
|
warnings will be displayed in the generated output.
|
|
|
|
|
|
|
|
* Set the configuration variable :confval:`nitpicky` to ``True`` so that Sphinx
|
|
|
|
will complain about references without a known target.
|
|
|
|
|
|
|
|
* Set the debugging options in the `Docutils configuration file
|
2021-05-16 07:42:26 -05:00
|
|
|
<https://docutils.sourceforge.io/docs/user/config.html>`_.
|
2020-05-30 09:08:50 -05:00
|
|
|
|
2022-10-23 19:07:05 -05:00
|
|
|
* JavaScript stemming algorithms in ``sphinx/search/non-minified-js/*.js``
|
|
|
|
are generated using `snowball <https://github.com/snowballstem/snowball>`_
|
|
|
|
by cloning the repository, executing ``make dist_libstemmer_js`` and then
|
|
|
|
unpacking the tarball which is generated in ``dist`` directory.
|
|
|
|
|
|
|
|
Minified files in ``sphinx/search/minified-js/*.js`` are generated from
|
|
|
|
non-minified ones using ``uglifyjs`` (installed via npm), with ``-m``
|
|
|
|
option to enable mangling.
|