Skip to content

Commit 3cad446

Browse files
authored
Always vendor all external JS/CSS (#169)
1 parent 3a538b1 commit 3cad446

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+11042
-782
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
# Install pandas + some optional dependencies
3131
pip install -r docs/requirements.txt
3232
# install the theme package
33-
pip install -e .
33+
pip install .
3434
# Cache some files for a speedup in subsequent builds
3535
- save_cache:
3636
key: cache-pip

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ celerybeat-schedule
8787
.venv
8888
venv/
8989
ENV/
90+
envs/
9091

9192
# Spyder project settings
9293
.spyderproject
10.7 KB
Loading

docs/contributing.rst

Lines changed: 224 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -2,142 +2,297 @@
22
Contributing
33
************
44

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

9-
Installing
10-
==========
8+
.. Hint::
119

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

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

20-
pip install --editable .
14+
Installing Python dependencies
15+
==============================
2116

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
2343
======================
2444

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
2749
2850
make html
2951
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+
3261

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+
===============================
3564

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

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

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
4574

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>`__.
47108

48-
Theme development was inspired by the `ReadTheDocs sphinx theme <https://github.com/readthedocs/sphinx_rtd_theme>`__.
49109

50110
Steps to develop the theme
51111
--------------------------
52112

53-
1. Install yarn
113+
1. Install ``yarn``
54114
2. Install theme dependencies
55115
3. Run development server
56116
4. Build production assets
57117

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

62-
Install yarn
63-
^^^^^^^^^^^^
125+
Installing ``yarn``
126+
^^^^^^^^^^^^^^^^^^^
64127

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``:
67132

68-
Install via conda::
133+
.. code-block:: bash
69134
70-
conda install yarn
135+
conda install -c conda-forge yarn
71136
72-
Install alternative: https://classic.yarnpkg.com/en/docs/install.
73137
74-
Install theme dependencies
138+
Installing JS dependencies
75139
^^^^^^^^^^^^^^^^^^^^^^^^^^
76140

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

79-
yarn install
153+
If changed, commit ``package.json`` and ``yarn.lock`` together to ensure
154+
reproducible builds.
80155

81156

82-
Run development server
83-
^^^^^^^^^^^^^^^^^^^^^^
157+
Running the development server
158+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
84159

85-
::
160+
To preview the frontend assets, from the root of this repo, run:
161+
162+
.. code-block:: bash
86163
87164
yarn build:dev
88165
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
93203

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
95206

96-
- ./src/js/index.js
97-
- ./src/scss/index.scss
98-
- ./docs/\*\*/\*.rst
99-
- ./docs/\*\*/\*.py
207+
- partially preloaded (mostly icons)
100208

101-
Build production assets
102-
^^^^^^^^^^^^^^^^^^^^^^^
209+
- reducing flicker and re-layout artifacts
103210

104-
To build the new theme assets into the theme, run the following command.
211+
- mostly managed in ``webpack.common.js``
105212

106-
::
213+
- allowing upgrades to be handled in a relatively sane, manageable way
107214

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>
108225
yarn build:production
109226
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+
110251

111252
Contributing changes
112253
====================
113254

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
116263

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
118265
the changes in the PR. To access this, click on "Details" of the "build_docs artifact"
119266
job of Circle CI:
120267

121268
.. image:: _static/pull-request-preview-link.png
122269

123270

124-
Ensuring correct commits with pre-commit hooks
125-
==============================================
271+
Ensuring correct commits
272+
========================
126273

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

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
131280
132281
# with pip
133282
pip install pre-commit
134283
# 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:
136287

137-
and then running from the root of this repo::
288+
.. code-block:: bash
138289
139290
pre-commit install
140291
141292
Now all of the checks will be run each time you commit changes.
142293

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

docs/user_guide/configuring.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.. _configuation:
1+
.. _configuration:
22

33
*************
44
Configuration

0 commit comments

Comments
 (0)