Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always vendor all external JS/CSS #169

Merged
Merged
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
7345622
first chunk of vendoring
bollwyvl Apr 30, 2020
bed20ed
fonts
bollwyvl Apr 30, 2020
bb35aef
lawyer up
bollwyvl Apr 30, 2020
0e04b2a
more verbose cdn config name, default to cdn, handle sphinx <3
bollwyvl Apr 30, 2020
b486a75
some more tweaking to conf
bollwyvl Apr 30, 2020
7a650b0
remove configurability, simplify config
bollwyvl May 1, 2020
eff61b2
remove NAME variable, as only used in one place again
bollwyvl May 1, 2020
a331540
build in ci
bollwyvl May 1, 2020
7fb62c8
fix conda install
bollwyvl May 1, 2020
6e5f40e
actually fix conda install of yarn
bollwyvl May 1, 2020
09624fe
linting
bollwyvl May 1, 2020
478f3ee
merge master
bollwyvl May 4, 2020
0e1b35b
Merge remote-tracking branch 'upstream/master' into always-vendor-ext…
bollwyvl May 12, 2020
aaa92d4
revert all mathjax-related changes
bollwyvl May 13, 2020
77bbbd5
add vendored assets to repo
bollwyvl May 13, 2020
c5bc9f5
merge master
bollwyvl Jun 16, 2020
d127923
rebuild yarn.lock, regenerate static
bollwyvl Jun 16, 2020
c8d033d
avoid node_modules in scss import, add preload of js in template
bollwyvl Jun 16, 2020
1b581fb
add cache-busting html macros: hash for built, versions for vendor
bollwyvl Jun 16, 2020
5477208
use proper hashes for current and future css and js in macros
bollwyvl Jun 16, 2020
40a88c2
Merge remote-tracking branch 'upstream/master' into always-vendor-ext…
bollwyvl Jun 19, 2020
d76ef11
remove ProvidePlugin
bollwyvl Jun 20, 2020
ba38d75
merge master
bollwyvl Jun 23, 2020
22c2470
rebuild assets after merging master
bollwyvl Jun 23, 2020
3eb4d1c
Merge remote-tracking branch 'upstream/master' into always-vendor-ext…
bollwyvl Jun 24, 2020
d90f795
add user_guide docs about customizing fonts, contributing about macro…
bollwyvl Jun 24, 2020
879fcf9
update pull request screenshot
bollwyvl Jun 24, 2020
2b7d4a5
pngcrush screenshot, fix some sentence continuation
bollwyvl Jun 24, 2020
f85cffe
move webpack macros into static
bollwyvl Jun 24, 2020
7bbe4c7
clean up some paths
bollwyvl Jun 24, 2020
dec25bc
add some more about fonts and selectors
bollwyvl Jun 24, 2020
356f8f9
rebuild
bollwyvl Jun 24, 2020
c1ac080
whitespace
bollwyvl Jun 24, 2020
1ee04a5
another pass over contributiong/customizing
bollwyvl Jun 25, 2020
7d32515
merge master
bollwyvl Jun 25, 2020
fe3b00a
update figure
jorisvandenbossche Jul 6, 2020
993bb3b
don't build with yarn in CI + use installed (not editable) python pac…
jorisvandenbossche Jul 6, 2020
6f934a1
some rst edits
jorisvandenbossche Jul 6, 2020
b1da116
fix rst edits
jorisvandenbossche Jul 6, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ jobs:
conda config --set always_yes yes --set changeps1 no
conda update conda
conda config --add channels conda-forge
conda install yarn
yarn && yarn build
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this might have been raised / discussed before, but in principle this is not needed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if it's not trying to re-build in CI, I don't that a PR actually is actually checked as to whether they author checked in the assets. but perhaps i'm wrong?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does solve the author forgetting to build the production assets.
It doesn't solve committing the builded assets though?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is actually checked as to whether they author checked in the assets.

The linting CI build should ensure that

# Install pandas + some optional dependencies
pip install -r docs/requirements.txt
# install the theme package
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ celerybeat-schedule
.venv
venv/
ENV/
envs/

# Spyder project settings
.spyderproject
Expand Down
Binary file modified docs/_static/pull-request-preview-link.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
281 changes: 212 additions & 69 deletions docs/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,142 +2,285 @@
Contributing
************

The documentation of the theme (what you are looking at now) also serves
as a demo site for the theme. In the top-level "Demo site" section,
more pages with typical sphinx content and structural elements are included.
The documentation for this theme (what you are looking at now) also serves
as a demo site for the theme.

Installing
==========
.. Hint::

To get this demo site up and running, you first need to install the requirements:
``/doc/requirements.txt`` (with for example pip or conda).
The top-level `Demo site` section includes
more pages with typical Sphinx content and structural elements.

Then, you need to install the sphinx theme (the theme itself is a python package).
When developing, the easiest is to install it in "development" or "editable" mode,
which means you can make changes in the repo and directly test it with the docs.
To install, you can run this from the root of the repo::

pip install --editable .
Installing Python dependencies
==============================

Building the demo docs
To run the demo site, first install the Python dependencies, for example with ``pip``
or ``conda``:

.. code-block:: bash

# with pip
python -m pip install -r docs/requirements.txt
# or with conda
conda install -c conda-forge --file docs/requirements.txt


Installing this theme
=====================

Next, install this theme itself, a python package.
When developing, it is recommended to install in "development" or "editable" mode,
allowing changes in the repo to be directly tested with this documentation suite.

To install the package, from the root of this repo, run:

.. code-block:: bash

python -m pip install --editable .


Building the demo site
======================

For the tradiditional sphinx-way to build the demo site, navigate to the
`docs/` directory, and then run::
For a traditional Sphinx build of the demo site, navigate to the ``docs/`` directory,
and run:

.. code-block:: bash

make html

This will trigger sphinx to build the html version of the site. The output can
be found in the ``docs/_build/html`` directory.
Sphinx will build the HTML version of the site in the ``docs/_build/html`` directory.

However, when you want to edit the css/js sources, those need to be bundled
and the workflow for this is explained in the next section.
.. Note::

Theme development
=================
If you wish to customize the CSS or JS beyond what is available in the
:ref:`configuration` and :ref:`customizing` sections of the user guide,
extra steps are required. The next section covers the full workflow, from
changing the source files, to seeing the updated site.

The css and javascript part of this theme is bundled via Webpack. In ``./src/*``
the theme related stylesheets and javascript is located. 2 entrypoints are
available:

- Stylesheet: ``./src/scss/index.scss``
- Javascript: ``./src/js/index.js``
Developing the theme CSS and JS
===============================

Both entrypoints will be bundled into ``./pydata_sphinx_theme/static/{css,js}``.
The CSS and JS for this theme are built for the browser from ``src/*`` with
`webpack <https://webpack.js.org/>`__. The main entrypoints are:

- CSS: ``src/scss/index.scss``
- the main part of the theme assets
- customizes `Bootstrap <https://getbootstrap.com/>`__ with `Sass <https://sass-lang.com>`__
- points to the ``font-face`` of vendored web fonts, but does not include their
CSS ``@font-face`` declaration
- JS: ``src/js/index.js``
- provides add-on Bootstrap features, as well as some custom navigation behavior
- webpack: ``webpack.common.js``
- captures the techniques for transforming the JS and CSS source files in
``src/`` into the production assets in ``pydata_sphinx_theme/static/``

These entrypoints, and all files they reference, are bundled into
``pydata_sphinx_theme/static/{css,js}/index.<hash>.{css,js}``.

The ``<hash>`` ensures the correct asset versions are serve when viewers return to your
site after upgrading the theme, and is reproducibly derived from:

- ``src/**/*``
- ``webpack.{common,prod}.js``
- the ``dependencies`` and ``devDependencies`` in ``package.json``/``yarn.lock``

Web fonts, and their supporting CSS, are copied into
``pydata_sphinx_theme/static/vendor/<font name>/<font version>/``. Including
the ``<font version>`` also ensures the correct assets are served when upgrading.

The links to these unique file names are captured as Jinja2 macros in
``pydata_sphinx_theme/static/webpack-macros.html``.

Finally, all of these files are committed to the repo, in-place, along with the
rest of the code. This allows use of the theme directly from a ``git`` checkout,
without any of the finicky web development dependencies, or even a ``nodejs``
runtime.

.. Hint::

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

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

Steps to develop the theme
--------------------------

1. Install yarn
1. Install ``yarn``
2. Install theme dependencies
3. Run development server
4. Build production assets

**Important:** in order to commit changes to the theme, ensure you run
``yarn build:production`` so all assets will be bundled into
``./pydata_sphinx_theme/static/``.
.. Attention::

In order to commit changes to the theme, ensure you run
``yarn build:production`` so all built assets will be bundled, copied, or
generated into ``pydata_sphinx_theme/static/``.

Install yarn
^^^^^^^^^^^^

`Yarn <https://yarnpkg.com>`__ is a package manager we use for managing
Javascript and CSS dependencies.
Installing ``yarn``
^^^^^^^^^^^^^^^^^^^

Install via conda::
`Yarn <https://yarnpkg.com>`__ is a package manager for JS and CSS dependencies.
Yarn itself can be installed with a number of
`package managers <https://classic.yarnpkg.com/en/docs/install>`__, including
``conda``:

conda install yarn
.. code-block:: bash

Install alternative: https://classic.yarnpkg.com/en/docs/install.
conda install -c conda-forge yarn

Install theme dependencies

Installing JS dependencies
^^^^^^^^^^^^^^^^^^^^^^^^^^

Install theme related dependencies::
To install theme-related ``dependencies`` and ``devDependencies`` from ``package.json``,
from the root of this repo, run:

.. code-block:: bash

yarn

yarn install
After adding/updating dependencies with ``yarn add``, or manually changing ``package.json``
and re-running ``yarn``, the ``yarn.lock`` and ``package.json`` files will likely change.

.. Important::

Run development server
^^^^^^^^^^^^^^^^^^^^^^
If changed, commit ``package.json`` and ``yarn.lock`` together to ensure
reproducible builds.

::

Running the development server
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

To preview the frontend assets, from the root of this repo, run:

.. code-block:: bash

yarn build:dev

A development server is available at http://localhost:1919. When working
on the theme, like editing stylesheets, javascript, .rst or .py files
every save reloads the development server. This reload includes bundling
stylesheets, javascript, and running sphinx again.
This launches a development server at http://localhost:1919. When working
on the theme, saving changes to any of:

- ``src/js/index.js``
- ``src/scss/index.scss``
- ``docs/**/*.rst``
- ``docs/**/*.py``

The following files will be watched and reloaded on change:
...causes the development server to:

- ./src/js/index.js
- ./src/scss/index.scss
- ./docs/\*\*/\*.rst
- ./docs/\*\*/\*.py
- bundle/copy the CSS, JS, and vendored fonts
- regenerate the Jinja2 macros
- re-run Sphinx

Build production assets
^^^^^^^^^^^^^^^^^^^^^^^

To build the new theme assets into the theme, run the following command.
Building the production assets
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

::
To build the new theme assets into the python package, from the root of this repo,
run:

.. code-block:: bash

yarn build:production


Changing fonts
--------------

Fonts are an important, performance-sensitive, but ultimately, subjective, part
of the theme. The current font selections are:

- managed as dependencies in ``package.json``
- allowing the versions to be managed centrally
- copied directly into the site statics, including licenses
- allowing the chosen fonts to be replaced (or removed entirely) with minimal
templating changes
- partially preloaded (mostly icons)
- reducing flicker and re-layout artifacts
- mostly managed in ``webpack.common.js``
- allowing upgrades to be handled in a relatively sane, manageable way


Upgrading a font
^^^^^^^^^^^^^^^^

If `only` the version of an `existing` font must change, for example to enable
new icons, run:

.. code-block:: bash

yarn add <font name>@<version>
yarn build:production

It `may` also be necessary to clear out old font versions from
``pydata_sphinx_theme/static/vendor/`` before committing.


Changing a font
^^^^^^^^^^^^^^^

If the above doesn't work, for example if file names for an existing font change,
or a new font altogether is being added, hand-editing of ``webpack.common.js`` is
required. The steps are roughly:

- install the new font, as above, with ``yarn add``
- in ``webpack.common.js``:
- add the new font to ``vendorVersions`` and ``vendorPaths``
- add new ``link`` tags to the appropriate macro in ``macroTemplate``
- add the new font files (including the license) to ``CopyPlugin``
- remove referencs to the font being replaced/removed, if applicable
- restart the development server, if running
- rebuild the production assets, as above, with ``yarn build:production``
- potentially remove the font being replaced from ``package.json`` and re-run ``yarn``
- commit all of the changes files


Contributing changes
====================

We follow the typical GitHub workflow of forking a repo, creating a branch,
opening pull requests (https://guides.github.com/introduction/flow/).
We follow a `typical GitHub workflow <https://guides.github.com/introduction/flow/>`__
of:

- create a personal fork of this repo
- create a branch
- open a pull request
- fix findings of various linters and checks
- work through code review

For each pull request, the demo site gets build to make it easier to preview
For each pull request, the demo site is built and deployed to make it easier to review
the changes in the PR. To access this, click on "Details" of the "build_docs artifact"
job of Circle CI:

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


Ensuring correct commits with pre-commit hooks
==============================================
Ensuring correct commits
========================

To ensure all source files have been correctly built, a `pre-commit <https://pre-commit.com/>`__
hook is available.

To ensure all source files have been correctly build, a `pre-commit <https://pre-commit.com/>`__
hook is available to use.
To set this up, first install the ``pre-commit`` package:

To set this up, first install the ``pre-commit`` package::
.. code-block:: bash

# with pip
pip install pre-commit
# or with conda
conda install pre-commit -c conda-forge
conda install -c conda-forge pre-commit

and then running from the root of this repo::
Then, from the root of this repo, run:

.. code-block:: bash

pre-commit install

Now all of the checks will be run each time you commit changes.

Note that if needed, you can skip these checks with ``git commit --no-verify``.
Note that if needed, you can skip these checks with:

.. code-block:: bash

git commit --no-verify
2 changes: 1 addition & 1 deletion docs/user_guide/configuring.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.. _configuation:
.. _configuration:

*************
Configuration
Expand Down
Loading