|
| 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