Sphinx theme for PyTorch Docs and PyTorch Tutorials based on the Read the Docs Sphinx Theme.
To develop on this theme locally you should do the following steps:
First go through the process of building the docs locally in the Geodesic Python API. This will clone and build the
theme repo locally in the docs/src
folder. Make modification to this folder if you want to see the results from
building the docs locally. Change to the src/seerai_sphinx_theme
folder.
Install all of the npm packages to build the theme. This will install grunt which will be used to build.
npm install
In order for grunt to build correctly, you will need to create an environment file (not really sure why this is needed and
not done automatically). Create a file called .env.json
with an empty json doc in it {}
. Grunt should now build the
package correctly.
grunt build
You then need to reinstall the python package for sphinx to pick up the changes to the theme.
python setup.py install
You should now be able to rebuild the docs to see the changes. Change do the docs/
folder and run
make html
Below are the original README instructions from the pytorch repo.
Run python setup:
python setup.py install
and install the dependencies using pip install -r docs/requirements.txt
In the root directory install the package.json
:
# node version 8.4.0
yarn install
If you have npm
installed then run:
npm install
- If you want to see generated documentation for
docs/demo
then create.env.json
file and make it empty json file. Means.env.json file
will contain
{}
Run grunt to build the html site and enable live reloading of the demo app at localhost:1919
:
grunt
- If you want to specify the project folder (docs or tutorial for which
you want to see docs generated) then you need to specify it into
.env.json
file:
{
"DOCS_DIR": "docs/",
"TUTORIALS_DIR": "path/to/tutorial/directory"
}
Run grunt to build the html site for docs:
grunt --project=docs
and to build the html site for tutorial:
grunt --project=tutorials
The resulting site is a demo.
When you are ready to submit a PR with your changes you can first test that your changes have been applied correctly against either the PyTorch Docs or Tutorials repo:
- Run the
grunt build
task on your branch and commit the build to Github. - In your local docs or tutorials repo, remove any existing
pytorch_sphinx_theme
packages in thesrc
folder (there should be apip-delete-this-directory.txt
file there) - In
requirements.txt
replace the existing git link with a link pointing to your commit or branch, e.g.-e git+git://github.com/{ your repo }/pytorch_sphinx_theme.git@{ your commit hash }#egg=pytorch_sphinx_theme
- Install the requirements
pip install -r requirements.txt
- Remove the current build. In the docs this is
make clean
, tutorials ismake clean-cache
- Build the static site. In the docs this is
make html
, tutorials ismake html-noplot
- Open the site and look around. In the docs open
docs/build/html/index.html
, in the tutorials open_build/html.index.html
If your changes have been applied successfully, remove the build commit from your branch and submit your PR.
Before the new changes are visible in the theme the maintainer will need to run the build process:
grunt build
Once that is successful commit the change to Github.
To be able to modify and preview the theme locally against the PyTorch Docs and/or the PyTorch Tutorials first clone the repositories:
Then follow the instructions in each repository to make the docs.
Once the docs have been successfully generated you should be able to run the following to create an html build.
# in ./docs
make html
# root directory
make html
Once these are successful, navigate to the conf.py
file in each project. In the Docs these are at ./docs/source
. The Tutorials one can be found in the root directory.
In conf.py
change the html theme to pytorch_sphinx_theme
and point the html theme path to this repo's local folder, which will end up looking something like:
html_theme = 'pytorch_sphinx_theme'
html_theme_path = ["../../../pytorch_sphinx_theme"]
Next create a file .env.json
in the root of this repo with some keys/values referencing the local folders of the Docs and Tutorials repos:
{
"TUTORIALS_DIR": "../tutorials",
"DOCS_DIR": "../pytorch/docs/source"
}
You can then build the Docs or Tutorials by running
grunt --project=docs
or
grunt --project=tutorials
These will generate a live-reloaded local build for the respective projects available at localhost:1919
.
Note that while live reloading works these two projects are hefty and will take a few seconds to build and reload, especially the Docs.
There are a couple of stylesheets and fonts inside the Docs and Tutorials repos themselves meant to override the existing theme. To ensure the most accurate styles we should comment out those files until the maintainers of those repos remove them:
# ./docs/source/conf.py
html_context = {
# 'css_files': [
# 'https://fonts.googleapis.com/css?family=Lato',
# '_static/css/pytorch_theme.css'
# ],
}
# ./conf.py
# app.add_stylesheet('css/pytorch_theme.css')
# app.add_stylesheet('https://fonts.googleapis.com/css?family=Lato')
The top navigation and mobile menu expect an "active" state for one of the menu items. To ensure that either "Docs" or "Tutorials" is marked as active, set the following config value in the respective conf.py
, where {project}
is either "docs"
or "tutorials"
.
html_theme_options = {
...
'pytorch_project': {project}
...
}