Skip to content
Snippets Groups Projects
Unverified Commit a0109e54 authored by Matt Wiese's avatar Matt Wiese Committed by GitHub
Browse files

:books: DOCS: Add local Sphinx extension documentation (#1058)


Co-authored-by: default avatarChris Holdgraf <choldgraf@gmail.com>
parent 92835692
No related branches found
No related tags found
No related merge requests found
...@@ -100,6 +100,49 @@ Simple is better than complex. 😵 ...@@ -100,6 +100,49 @@ Simple is better than complex. 😵
``` ```
```` ````
### Local Sphinx Extensions
[Sphinx is able to use local extensions](https://www.sphinx-doc.org/en/master/development/tutorials/helloworld.html#using-the-extension) by adding additional directories to the [Python path](https://docs.python.org/3/using/cmdline.html#envvar-PYTHONPATH). At present, this functionality is not available within Jupyter Book.
However, you can use a local Sphinx extension by using `pip` and installing the package locally. Below we'll document how you can create a local `pip`-installable Sphinx extension.
First, write a minimal `setup.py` as follows:
```python
from setuptools import setup
setup(
name='my_sphinx_ext'
)
```
```{seealso}
For further documentation on the purposes and configuration of `setup.py`, please refer to [the official Python documentation on setup scripts](https://docs.python.org/3/distutils/setupscript.html).
```
Next, create a new directory with your extension's name (in this case `my_sphinx_ext`) within the same directory as `setup.py`. Afterwards, create an *empty* file called `__init__.py` within this directory. If you are on Linux, simply `touch my_sphinx_ext/__init__.py`. The result should be:
```
setup.py
my_sphinx_ext/
└──__init__.py
```
Then, execute `pip install -e .` within the directory containing `setup.py`. This will install `my_sphinx_ext` as a local Python package.
It's then as easy as updating your `_config.yml` with your new extension:
```yaml
sphinx:
extra_extensions:
- my_sphinx_ext
```
:::{admonition,tip} More information on creating Sphinx extensions
The extension in this example is `pip`-installable, but does nothing! For more information about how to create your own Sphinx extension, try following [Sphinx's extension tutorials](https://www.sphinx-doc.org/en/master/development/tutorials/index.html).
:::
(custom-assets)= (custom-assets)=
## Custom CSS or JavaScript ## Custom CSS or JavaScript
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment