|
2 | 2 | Contributing
|
3 | 3 | ************
|
4 | 4 |
|
5 |
| -The documentation of the theme (what you are looking at now) also serves |
6 |
| -as a demo site for the theme. In the top-level "Demo site" section, |
7 |
| -more pages with typical sphinx content and structural elements are included. |
| 5 | +The documentation for this theme (what you are looking at now) also serves |
| 6 | +as a demo site for the theme. |
8 | 7 |
|
9 |
| -Installing |
10 |
| -========== |
| 8 | +.. Hint:: |
11 | 9 |
|
12 |
| -To get this demo site up and running, you first need to install the requirements: |
13 |
| -``/doc/requirements.txt`` (with for example pip or conda). |
| 10 | + The top-level `Demo site` section includes |
| 11 | + more pages with typical Sphinx content and structural elements. |
14 | 12 |
|
15 |
| -Then, you need to install the sphinx theme (the theme itself is a python package). |
16 |
| -When developing, the easiest is to install it in "development" or "editable" mode, |
17 |
| -which means you can make changes in the repo and directly test it with the docs. |
18 |
| -To install, you can run this from the root of the repo:: |
19 | 13 |
|
20 |
| - pip install --editable . |
| 14 | +Installing Python dependencies |
| 15 | +============================== |
21 | 16 |
|
22 |
| -Building the demo docs |
| 17 | +To run the demo site, first install the Python dependencies, for example with ``pip`` |
| 18 | +or ``conda``: |
| 19 | + |
| 20 | +.. code-block:: bash |
| 21 | +
|
| 22 | + # with pip |
| 23 | + python -m pip install -r docs/requirements.txt |
| 24 | + # or with conda |
| 25 | + conda install -c conda-forge --file docs/requirements.txt |
| 26 | +
|
| 27 | +
|
| 28 | +Installing this theme |
| 29 | +===================== |
| 30 | + |
| 31 | +Next, install this theme itself, a python package. |
| 32 | +When developing, it is recommended to install in "development" or "editable" mode, |
| 33 | +allowing changes in the repo to be directly tested with this documentation suite. |
| 34 | + |
| 35 | +To install the package, from the root of this repo, run: |
| 36 | + |
| 37 | +.. code-block:: bash |
| 38 | +
|
| 39 | + python -m pip install --editable . |
| 40 | +
|
| 41 | +
|
| 42 | +Building the demo site |
23 | 43 | ======================
|
24 | 44 |
|
25 |
| -For the tradiditional sphinx-way to build the demo site, navigate to the |
26 |
| -`docs/` directory, and then run:: |
| 45 | +For a traditional Sphinx build of the demo site, navigate to the ``docs/`` directory, |
| 46 | +and run: |
| 47 | + |
| 48 | +.. code-block:: bash |
27 | 49 |
|
28 | 50 | make html
|
29 | 51 |
|
30 |
| -This will trigger sphinx to build the html version of the site. The output can |
31 |
| -be found in the ``docs/_build/html`` directory. |
| 52 | +Sphinx will build the HTML version of the site in the ``docs/_build/html`` directory. |
| 53 | + |
| 54 | +.. Note:: |
| 55 | + |
| 56 | + If you wish to customize the CSS or JS beyond what is available in the |
| 57 | + :ref:`configuration` and :ref:`customizing` sections of the user guide, |
| 58 | + extra steps are required. The next section covers the full workflow, from |
| 59 | + changing the source files, to seeing the updated site. |
| 60 | + |
32 | 61 |
|
33 |
| -However, when you want to edit the css/js sources, those need to be bundled |
34 |
| -and the workflow for this is explained in the next section. |
| 62 | +Developing the theme CSS and JS |
| 63 | +=============================== |
35 | 64 |
|
36 |
| -Theme development |
37 |
| -================= |
| 65 | +The CSS and JS for this theme are built for the browser from ``src/*`` with |
| 66 | +`webpack <https://webpack.js.org/>`__. The main entrypoints are: |
38 | 67 |
|
39 |
| -The css and javascript part of this theme is bundled via Webpack. In ``./src/*`` |
40 |
| -the theme related stylesheets and javascript is located. 2 entrypoints are |
41 |
| -available: |
| 68 | +- CSS: ``src/scss/index.scss`` |
42 | 69 |
|
43 |
| -- Stylesheet: ``./src/scss/index.scss`` |
44 |
| -- Javascript: ``./src/js/index.js`` |
| 70 | + - the main part of the theme assets |
| 71 | + - customizes `Bootstrap <https://getbootstrap.com/>`__ with `Sass <https://sass-lang.com>`__ |
| 72 | + - points to the ``font-face`` of vendored web fonts, but does not include their |
| 73 | + CSS ``@font-face`` declaration |
45 | 74 |
|
46 |
| -Both entrypoints will be bundled into ``./pydata_sphinx_theme/static/{css,js}``. |
| 75 | +- JS: ``src/js/index.js`` |
| 76 | + |
| 77 | + - provides add-on Bootstrap features, as well as some custom navigation behavior |
| 78 | + |
| 79 | +- webpack: ``webpack.common.js`` |
| 80 | + |
| 81 | + - captures the techniques for transforming the JS and CSS source files in |
| 82 | + ``src/`` into the production assets in ``pydata_sphinx_theme/static/`` |
| 83 | + |
| 84 | +These entrypoints, and all files they reference, are bundled into |
| 85 | +``pydata_sphinx_theme/static/{css,js}/index.<hash>.{css,js}``. |
| 86 | + |
| 87 | +The ``<hash>`` ensures the correct asset versions are served when viewers return to your |
| 88 | +site after upgrading the theme, and is reproducibly derived from ``src/**/*``, |
| 89 | +``webpack.{common,prod}.js``, and the ``dependencies`` and ``devDependencies`` |
| 90 | +in ``package.json``/``yarn.lock``. |
| 91 | + |
| 92 | +Web fonts, and their supporting CSS, are copied into |
| 93 | +``pydata_sphinx_theme/static/vendor/<font name>/<font version>/``. Including |
| 94 | +the ``<font version>`` also ensures the correct assets are served when upgrading. |
| 95 | + |
| 96 | +The links to these unique file names are captured as Jinja2 macros in |
| 97 | +``pydata_sphinx_theme/static/webpack-macros.html``. |
| 98 | + |
| 99 | +Finally, all of these files are committed to the repo, in-place, along with the |
| 100 | +rest of the code. This allows use of the theme directly from a ``git`` checkout, |
| 101 | +without any of the finicky web development dependencies, or even a ``nodejs`` |
| 102 | +runtime. |
| 103 | + |
| 104 | +.. Hint:: |
| 105 | + |
| 106 | + Theme development was inspired by the |
| 107 | + `ReadTheDocs Sphinx theme <https://github.com/readthedocs/sphinx_rtd_theme>`__. |
47 | 108 |
|
48 |
| -Theme development was inspired by the `ReadTheDocs sphinx theme <https://github.com/readthedocs/sphinx_rtd_theme>`__. |
49 | 109 |
|
50 | 110 | Steps to develop the theme
|
51 | 111 | --------------------------
|
52 | 112 |
|
53 |
| -1. Install yarn |
| 113 | +1. Install ``yarn`` |
54 | 114 | 2. Install theme dependencies
|
55 | 115 | 3. Run development server
|
56 | 116 | 4. Build production assets
|
57 | 117 |
|
58 |
| -**Important:** in order to commit changes to the theme, ensure you run |
59 |
| -``yarn build:production`` so all assets will be bundled into |
60 |
| -``./pydata_sphinx_theme/static/``. |
| 118 | +.. Attention:: |
| 119 | + |
| 120 | + In order to commit changes to the theme, ensure you run |
| 121 | + ``yarn build:production`` so all built assets will be bundled, copied, or |
| 122 | + generated into ``pydata_sphinx_theme/static/``. |
| 123 | + |
61 | 124 |
|
62 |
| -Install yarn |
63 |
| -^^^^^^^^^^^^ |
| 125 | +Installing ``yarn`` |
| 126 | +^^^^^^^^^^^^^^^^^^^ |
64 | 127 |
|
65 |
| -`Yarn <https://yarnpkg.com>`__ is a package manager we use for managing |
66 |
| -Javascript and CSS dependencies. |
| 128 | +`Yarn <https://yarnpkg.com>`__ is a package manager for JS and CSS dependencies. |
| 129 | +Yarn itself can be installed with a number of |
| 130 | +`package managers <https://classic.yarnpkg.com/en/docs/install>`__, including |
| 131 | +``conda``: |
67 | 132 |
|
68 |
| -Install via conda:: |
| 133 | +.. code-block:: bash |
69 | 134 |
|
70 |
| - conda install yarn |
| 135 | + conda install -c conda-forge yarn |
71 | 136 |
|
72 |
| -Install alternative: https://classic.yarnpkg.com/en/docs/install. |
73 | 137 |
|
74 |
| -Install theme dependencies |
| 138 | +Installing JS dependencies |
75 | 139 | ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
76 | 140 |
|
77 |
| -Install theme related dependencies:: |
| 141 | +To install theme-related ``dependencies`` and ``devDependencies`` from ``package.json``, |
| 142 | +from the root of this repo, run: |
| 143 | + |
| 144 | +.. code-block:: bash |
| 145 | +
|
| 146 | + yarn |
| 147 | +
|
| 148 | +After adding/updating dependencies with ``yarn add``, or manually changing ``package.json`` |
| 149 | +and re-running ``yarn``, the ``yarn.lock`` and ``package.json`` files will likely change. |
| 150 | + |
| 151 | +.. Important:: |
78 | 152 |
|
79 |
| - yarn install |
| 153 | + If changed, commit ``package.json`` and ``yarn.lock`` together to ensure |
| 154 | + reproducible builds. |
80 | 155 |
|
81 | 156 |
|
82 |
| -Run development server |
83 |
| -^^^^^^^^^^^^^^^^^^^^^^ |
| 157 | +Running the development server |
| 158 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
84 | 159 |
|
85 |
| -:: |
| 160 | +To preview the frontend assets, from the root of this repo, run: |
| 161 | + |
| 162 | +.. code-block:: bash |
86 | 163 |
|
87 | 164 | yarn build:dev
|
88 | 165 |
|
89 |
| -A development server is available at http://localhost:1919. When working |
90 |
| -on the theme, like editing stylesheets, javascript, .rst or .py files |
91 |
| -every save reloads the development server. This reload includes bundling |
92 |
| -stylesheets, javascript, and running sphinx again. |
| 166 | +This launches a development server at http://localhost:1919. When working |
| 167 | +on the theme, saving changes to any of: |
| 168 | + |
| 169 | +- ``src/js/index.js`` |
| 170 | +- ``src/scss/index.scss`` |
| 171 | +- ``docs/**/*.rst`` |
| 172 | +- ``docs/**/*.py`` |
| 173 | + |
| 174 | +...causes the development server to reload: |
| 175 | + |
| 176 | +- bundle/copy the CSS, JS, and vendored fonts |
| 177 | +- regenerate the Jinja2 macros |
| 178 | +- re-run Sphinx |
| 179 | + |
| 180 | + |
| 181 | +Building the production assets |
| 182 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 183 | + |
| 184 | +To build the new theme assets into the python package, from the root of this repo, |
| 185 | +run: |
| 186 | + |
| 187 | +.. code-block:: bash |
| 188 | +
|
| 189 | + yarn build:production |
| 190 | +
|
| 191 | +
|
| 192 | +Changing fonts |
| 193 | +-------------- |
| 194 | + |
| 195 | +Fonts are an important, performance-sensitive, but ultimately, subjective, part |
| 196 | +of the theme. The current font selections are: |
| 197 | + |
| 198 | +- managed as dependencies in ``package.json`` |
| 199 | + |
| 200 | + - allowing the versions to be managed centrally |
| 201 | + |
| 202 | +- copied directly into the site statics, including licenses |
93 | 203 |
|
94 |
| -The following files will be watched and reloaded on change: |
| 204 | + - allowing the chosen fonts to be replaced (or removed entirely) with minimal |
| 205 | + templating changes |
95 | 206 |
|
96 |
| -- ./src/js/index.js |
97 |
| -- ./src/scss/index.scss |
98 |
| -- ./docs/\*\*/\*.rst |
99 |
| -- ./docs/\*\*/\*.py |
| 207 | +- partially preloaded (mostly icons) |
100 | 208 |
|
101 |
| -Build production assets |
102 |
| -^^^^^^^^^^^^^^^^^^^^^^^ |
| 209 | + - reducing flicker and re-layout artifacts |
103 | 210 |
|
104 |
| -To build the new theme assets into the theme, run the following command. |
| 211 | +- mostly managed in ``webpack.common.js`` |
105 | 212 |
|
106 |
| -:: |
| 213 | + - allowing upgrades to be handled in a relatively sane, manageable way |
107 | 214 |
|
| 215 | + |
| 216 | +Upgrading a font |
| 217 | +^^^^^^^^^^^^^^^^ |
| 218 | + |
| 219 | +If *only* the version of an `existing` font must change, for example to enable |
| 220 | +new icons, run: |
| 221 | + |
| 222 | +.. code-block:: bash |
| 223 | +
|
| 224 | + yarn add <font name>@<version> |
108 | 225 | yarn build:production
|
109 | 226 |
|
| 227 | +It *may* also be necessary to clear out old font versions from |
| 228 | +``pydata_sphinx_theme/static/vendor/`` before committing. |
| 229 | + |
| 230 | + |
| 231 | +Changing a font |
| 232 | +^^^^^^^^^^^^^^^ |
| 233 | + |
| 234 | +If the above doesn't work, for example if file names for an existing font change, |
| 235 | +or a new font altogether is being added, hand-editing of ``webpack.common.js`` is |
| 236 | +required. The steps are roughly: |
| 237 | + |
| 238 | +- install the new font, as above, with ``yarn add`` |
| 239 | +- in ``webpack.common.js``: |
| 240 | + |
| 241 | + - add the new font to ``vendorVersions`` and ``vendorPaths`` |
| 242 | + - add new ``link`` tags to the appropriate macro in ``macroTemplate`` |
| 243 | + - add the new font files (including the license) to ``CopyPlugin`` |
| 244 | + - remove referencs to the font being replaced/removed, if applicable |
| 245 | + |
| 246 | +- restart the development server, if running |
| 247 | +- rebuild the production assets, as above, with ``yarn build:production`` |
| 248 | +- potentially remove the font being replaced from ``package.json`` and re-run ``yarn`` |
| 249 | +- commit all of the changes files |
| 250 | + |
110 | 251 |
|
111 | 252 | Contributing changes
|
112 | 253 | ====================
|
113 | 254 |
|
114 |
| -We follow the typical GitHub workflow of forking a repo, creating a branch, |
115 |
| -opening pull requests (https://guides.github.com/introduction/flow/). |
| 255 | +We follow a `typical GitHub workflow <https://guides.github.com/introduction/flow/>`__ |
| 256 | +of: |
| 257 | + |
| 258 | +- create a personal fork of this repo |
| 259 | +- create a branch |
| 260 | +- open a pull request |
| 261 | +- fix findings of various linters and checks |
| 262 | +- work through code review |
116 | 263 |
|
117 |
| -For each pull request, the demo site gets build to make it easier to preview |
| 264 | +For each pull request, the demo site is built and deployed to make it easier to review |
118 | 265 | the changes in the PR. To access this, click on "Details" of the "build_docs artifact"
|
119 | 266 | job of Circle CI:
|
120 | 267 |
|
121 | 268 | .. image:: _static/pull-request-preview-link.png
|
122 | 269 |
|
123 | 270 |
|
124 |
| -Ensuring correct commits with pre-commit hooks |
125 |
| -============================================== |
| 271 | +Ensuring correct commits |
| 272 | +======================== |
126 | 273 |
|
127 |
| -To ensure all source files have been correctly build, a `pre-commit <https://pre-commit.com/>`__ |
128 |
| -hook is available to use. |
| 274 | +To ensure all source files have been correctly built, a `pre-commit <https://pre-commit.com/>`__ |
| 275 | +hook is available. |
129 | 276 |
|
130 |
| -To set this up, first install the ``pre-commit`` package:: |
| 277 | +To set this up, first install the ``pre-commit`` package: |
| 278 | + |
| 279 | +.. code-block:: bash |
131 | 280 |
|
132 | 281 | # with pip
|
133 | 282 | pip install pre-commit
|
134 | 283 | # or with conda
|
135 |
| - conda install pre-commit -c conda-forge |
| 284 | + conda install -c conda-forge pre-commit |
| 285 | +
|
| 286 | +Then, from the root of this repo, run: |
136 | 287 |
|
137 |
| -and then running from the root of this repo:: |
| 288 | +.. code-block:: bash |
138 | 289 |
|
139 | 290 | pre-commit install
|
140 | 291 |
|
141 | 292 | Now all of the checks will be run each time you commit changes.
|
142 | 293 |
|
143 |
| -Note that if needed, you can skip these checks with ``git commit --no-verify``. |
| 294 | +Note that if needed, you can skip these checks with: |
| 295 | + |
| 296 | +.. code-block:: bash |
| 297 | +
|
| 298 | + git commit --no-verify |
0 commit comments