Skip to content

Commit e6d3df3

Browse files
committed
DOCS: refactor dev docs
1 parent d351b9b commit e6d3df3

File tree

9 files changed

+520
-462
lines changed

9 files changed

+520
-462
lines changed

docs/conf.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,12 @@
3434
# ones.
3535

3636
extensions = [
37+
"jupyter_sphinx",
38+
"myst_parser",
39+
"numpydoc",
3740
"sphinx.ext.autodoc",
3841
"sphinx.ext.autosummary",
39-
"numpydoc",
40-
"myst_parser",
41-
"jupyter_sphinx",
42+
"sphinxext.rediraffe",
4243
]
4344

4445
# -- Internationalization ------------------------------------------------
@@ -115,6 +116,10 @@
115116
"doc_path": "docs",
116117
}
117118

119+
rediraffe_redirects = {
120+
"contributing.rst": "contribute/index.rst",
121+
}
122+
118123
# Add any paths that contain custom static files (such as style sheets) here,
119124
# relative to this directory. They are copied after the builtin static files,
120125
# so a file named "default.css" will overwrite the builtin "default.css".

docs/contribute/index.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
---
2+
html_meta:
3+
"description lang=en": "How to become a contributor to the pydata-sphinx-theme."
4+
---
5+
6+
# Contribute
7+
8+
These pages contain information about how you can get up-and-running with a development version of this theme, and how you can contribute to the project.
9+
10+
## Workflow for contributing changes
11+
12+
We follow a [typical GitHub workflow](https://guides.github.com/introduction/flow/)
13+
of:
14+
15+
- create a personal fork of this repo
16+
- create a branch
17+
- open a pull request
18+
- fix findings of various linters and checks
19+
- work through code review
20+
21+
For each pull request, the demo site is built and deployed to make it easier to review
22+
the changes in the PR. To access this, click on the "ReadTheDocs" preview in the CI/CD jobs.
23+
24+
## Location and structure of documentation
25+
26+
The documentation for this theme is in the `docs/` folder.
27+
It is structured as a [Sphinx documentation site](https://sphinx-doc.org).
28+
The content is written in a combination of reStructuredText and MyST Markdown.
29+
30+
## Location and structure of CSS/JS assets
31+
32+
The CSS and JS for this theme are built for the browser from `src/*` with
33+
[webpack](https://webpack.js.org/). The main entrypoints are:
34+
35+
- CSS: `src/scss/index.scss`
36+
37+
- the main part of the theme assets
38+
- customizes [Bootstrap](https://getbootstrap.com/) with [Sass](https://sass-lang.com)
39+
- points to the `font-face` of vendored web fonts, but does not include their
40+
CSS `@font-face` declaration
41+
42+
- JS: `src/js/index.js`
43+
44+
- provides add-on Bootstrap features, as well as some custom navigation behavior
45+
46+
- webpack: `webpack.config.js`
47+
48+
- captures the techniques for transforming the JS and CSS source files in
49+
`src/` into the production assets in `pydata_sphinx_theme/static/`
50+
51+
**For more information** about developing this theme, see the sections below and in the left sidebar.
52+
53+
```{toctree}
54+
:maxdepth: 2
55+
setup
56+
topics
57+
manual
58+
```

docs/contribute/manual.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
(manual-environment)=
2+
3+
# Set up a manual development environment
4+
5+
If you prefer not to use automation tools like `nox`, you may also manually set up a development environment locally.
6+
To do so, follow the instructions on this page.
7+
8+
## Create a new development environment
9+
10+
This is optional, but it's best to start with a fresh development environment so that you've isolated the packages that you're using for this repository.
11+
12+
To do so, use a tool like [conda](https://docs.conda.io/en/latest/), [mamba](https://github.com/mamba-org/mamba), or [virtualenv](https://virtualenv.pypa.io/).
13+
14+
## Clone the repository locally
15+
16+
First clone this repository from the `pydata` organization, or from a fork that you have created:
17+
18+
```console
19+
$ git clone https://github.com/pydata/pydata-sphinx-theme
20+
$ cd pydata-sphinx-theme
21+
```
22+
23+
## Install the `sphinx-theme-builder`
24+
25+
We use the `sphinx-theme-builder` to install `nodejs` locally and to compile all CSS and JS assets needed for the theme.
26+
Install it like so (note the `cli` option so that we can run it from the command line):
27+
28+
```console
29+
$ pip install sphinx-theme-builder[cli]
30+
```
31+
32+
## Install this theme locally
33+
34+
Next, install this theme locally so that we have the necessary dependencies to build the documentation and testing suite:
35+
36+
```console
37+
$ pip install -e .[dev]
38+
```
39+
40+
Note that the `sphinx-theme-builder` will automatically install a local copy of `nodejs` for building the theme's assets.
41+
This will be placed in a `.nodeenv` folder.
42+
43+
## Build the documentation
44+
45+
To manually build the documentation, run the following command:
46+
47+
```console
48+
$ sphinx-build docs docs/_build/html
49+
```
50+
51+
## Compile web assets (JS/CSS)
52+
53+
To compile the javascript and CSS assets for the theme, run the following command:
54+
55+
```console
56+
$ stb compile
57+
```
58+
59+
This will compile everything in the `src/pydata_sphinx_theme/assets` folder and place them in the appropriate places in our theme's folder structure.
60+
61+
## Start a live-server to build and serve your documentation
62+
63+
To manually open a server to watch your documentation for changes, build them, and display them locally in a browser, run this command:
64+
65+
```console
66+
$ stb serve docs --open-browser
67+
```
68+
69+
## Run the tests
70+
71+
To manually run the tests for this theme, first set up your environment locally, and then run:
72+
73+
```console
74+
$ pytest
75+
```

docs/contribute/setup.md

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
# Get started with development
2+
3+
This section covers the simplest way to get started developing this theme locally so that you can contribute.
4+
It uses automation and as few steps as possible to get things done.
5+
If you'd like to do more operations manually, see [](manual.md).
6+
7+
## Clone the repository
8+
9+
First off you'll need your own copy of the `pydata-sphinx-theme` codebase.
10+
You can clone it for local development like so:
11+
12+
1. **Fork the repository** so you have your own copy on GitHub.
13+
See [the GitHub forking guide](https://docs.github.com/en/get-started/quickstart/fork-a-repo) for more information.
14+
2. **Clone the repository locally** so that you have a local copy to work from:
15+
16+
```console
17+
$ git clone https://github.com/{{ YOUR USERNAME }}/pydata-sphinx-theme
18+
$ cd pydata-sphinx-theme
19+
```
20+
21+
## Install your tools
22+
23+
Building a Sphinx site uses a combination of Python and Jinja to manage HTML, SCSS, and Javascript.
24+
To simplify this process, we use a few helper tools:
25+
26+
- [The Sphinx Theme Builder](https://sphinx-theme-builder.readthedocs.io/en/latest/) to automatically perform compilation of web assets.
27+
- [pre-commit](https://pre-commit.com/) for automatically enforcing code standards and quality checks before commits.
28+
- [nox](https://nox.thea.codes/), for automating common development tasks.
29+
30+
In particular, `nox` can be used to automatically create isolated local development environments with all of the correct packages installed to work on the theme.
31+
The rest of this guide focuses on using `nox` to start with a basic environment.
32+
33+
```{seealso}
34+
The information on this page covers the basics to get you started, for information about manually compiling assets, see [](manual.md).
35+
```
36+
37+
### Setup `nox`
38+
39+
To start, install `nox`:
40+
41+
```console
42+
$ pip install nox
43+
```
44+
45+
You can call `nox` from the command line in order to perform common actions that are needed in building the theme.
46+
`nox` operates with isolated environments, so each action has its own packages installed in a local director (`.nox`).
47+
For common development actions, you'll simply need to use `nox` and won't need to set up any other packages.
48+
49+
### Setup `pre-commit`
50+
51+
`pre-commit` allows us to run several checks on the codebase every time a new Git commit is made.
52+
This ensures standards and basic quality control for our code.
53+
54+
Install `pre-commit` with the following command:
55+
56+
```console
57+
$ pip install pre-commit
58+
```
59+
60+
then navigate to this repository's folder and activate it like so:
61+
62+
```console
63+
$ pre-commit install
64+
```
65+
66+
This will install the necessary dependencies to run `pre-commit` every time you make a commit with Git.
67+
68+
## Build the documentation
69+
70+
Now that you have `nox` installed and cloned the repository, you should be able to build the documentation locally.
71+
72+
To build the documentation with `nox`, run the following command:
73+
74+
```console
75+
$ nox -s docs
76+
```
77+
78+
This will install the necessary dependencies and build the documentation located in the `docs/` folder.
79+
They will be placed in a `docs/_build/html` folder.
80+
If the docs have already been built, it will only build new pages that have been updated.
81+
You can open one of the HTML files there to preview the documentation locally.
82+
83+
### Change content and re-build
84+
85+
Now that you've built the documentation, edit one of the source files to see how the documentation updates with new builds.
86+
87+
1. **Make an edit to a page**. For example, add a word or fix a typo on any page.
88+
2. **Rebuild the documentation** with `nox -s docs`
89+
90+
It should go much faster this time, because `nox` is re-using the old environment, and because Sphinx has cached the pages that you didn't change.
91+
92+
## Compile the CSS/JS assets
93+
94+
The source files for CSS and JS assets are in `src/pydata_sphinx_theme/assets`.
95+
These are then built and bundled with the theme (e.g., `scss` is turned into `css`).
96+
97+
To compile the CSS/JS assets with `nox`, run the following command:
98+
99+
```console
100+
$ nox -s compile
101+
```
102+
103+
This will compile all assets and place them in the appropriate folder to be used with documentation builds.
104+
105+
```{note}
106+
Compiled assets are **not committed to git**.
107+
The `sphinx-theme-builder` will bundle these assets automatically when we make a new release, but we do not manually commit these compiled assets to git history.
108+
```
109+
110+
## Run a development server
111+
112+
You can combine the above two actions and run a development server so that changes to `src/` are automatically bundled with the package, and the documentation is immediately reloaded in a live preview window.
113+
114+
To run the development server with `nox`, run the following command:
115+
116+
```console
117+
$ nox -s docs-live
118+
```
119+
120+
When working on the theme, saving changes to any of these directories:
121+
122+
- `src/js/index.js`
123+
- `src/scss/index.scss`
124+
- `docs/**/*.rst`
125+
- `docs/**/*.py`
126+
127+
will cause the development server to do the following:
128+
129+
- bundle/copy the CSS, JS, and vendored fonts
130+
- regenerate the Jinja2 macros
131+
- re-run Sphinx
132+
133+
## Run the tests
134+
135+
This theme uses `pytest` for its testing, with a lightweight fixture defined
136+
in the `test_build.py` script that makes it easy to run a Sphinx build using
137+
this theme and inspect the results.
138+
139+
In addition, we use [pytest-regressions](https://pytest-regressions.readthedocs.io/en/latest/)
140+
to ensure that the HTML generated by the theme is what we'd expect. This module
141+
provides a `file_regression` fixture that will check the contents of an object
142+
against a reference file on disk. If the structure of the two differs, then the
143+
test will fail. If we _expect_ the structure to differ, then delete the file on
144+
disk and run the test. A new file will be created, and subsequent tests will pass.
145+
146+
To run the tests with `nox`, run the following command:
147+
148+
```console
149+
$ nox -s test
150+
```

0 commit comments

Comments
 (0)