Skip to content

Commit 3533799

Browse files
authored
Sphinx support: add Sphinx core files (#1930)
See #2, #1385 for context. Superseeds #1565. This is the minimal core Sphinx support part, adding a bare minimum of useful things to get Sphinx to build and deploy, whilst not affecting the current build system. There is no theming or custom parsing needed to properly deal with PEPs. - `build.py` - build script - `conf.py` - Sphinx configuration - `Makefile` - new targets for Sphinx - `.gitignore` - add ignores for `venv` and `package` directories - `contents.rst` - Sphinx page to discover all PEPs - `deploy-gh-pages.yaml` - builds and deploys to github pages - `requirements.txt`
1 parent 629a8b4 commit 3533799

File tree

7 files changed

+174
-6
lines changed

7 files changed

+174
-6
lines changed
+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Deploy to GitHub Pages
2+
3+
on: [push]
4+
5+
jobs:
6+
deploy-to-pages:
7+
runs-on: ubuntu-latest
8+
9+
steps:
10+
- name: 🛎️ Checkout
11+
uses: actions/checkout@v2
12+
13+
- name: 🐍 Set up Python 3.9
14+
uses: actions/setup-python@v2
15+
with:
16+
python-version: 3.9
17+
18+
- name: 🧳 Cache pip
19+
uses: actions/cache@v2
20+
with:
21+
# This path is specific to Ubuntu
22+
path: ~/.cache/pip
23+
# Look to see if there is a cache hit for the corresponding requirements file
24+
key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }}
25+
restore-keys: |
26+
${{ runner.os }}-pip-
27+
${{ runner.os }}-
28+
29+
- name: 👷‍ Install dependencies
30+
run: |
31+
python -m pip install --upgrade pip
32+
pip install -r requirements.txt
33+
34+
- name: 🔧 Build PEPs
35+
run: make pages -j$(nproc)
36+
37+
- name: 🚀 Deploy to GitHub pages
38+
uses: JamesIves/[email protected]
39+
with:
40+
branch: gh-pages # The branch to deploy to.
41+
folder: build # Synchronise with build.py -> build_directory
42+
single-commit: true # Delete existing files

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ __pycache__
1010
.vscode
1111
*.swp
1212
/build
13+
/package
14+
/venv

Makefile

+20-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
# Rules to only make the required HTML versions, not all of them,
2-
# without the user having to keep track of which.
3-
#
4-
# Not really important, but convenient.
1+
# Builds PEP files to HTML using docutils or sphinx
2+
# Also contains testing targets
53

64
PEP2HTML=pep2html.py
75

@@ -34,7 +32,6 @@ install:
3432

3533
clean:
3634
-rm pep-0000.rst
37-
-rm pep-0000.txt
3835
-rm *.html
3936
-rm -rf build
4037

@@ -43,7 +40,7 @@ update:
4340

4441
venv:
4542
$(PYTHON) -m venv $(VENV_DIR)
46-
./$(VENV_DIR)/bin/python -m pip install -U docutils
43+
./$(VENV_DIR)/bin/python -m pip install -r requirements.txt
4744

4845
package: all rss
4946
mkdir -p build/peps
@@ -57,3 +54,20 @@ package: all rss
5754
lint:
5855
pre-commit --version > /dev/null || python3 -m pip install pre-commit
5956
pre-commit run --all-files
57+
58+
# New Sphinx targets:
59+
60+
SPHINX_JOBS=8
61+
SPHINX_BUILD=$(PYTHON) build.py -j $(SPHINX_JOBS)
62+
63+
pages: rss
64+
$(SPHINX_BUILD) --index-file
65+
66+
sphinx:
67+
$(SPHINX_BUILD)
68+
69+
fail_on_warning:
70+
$(SPHINX_BUILD) --fail-on-warning
71+
72+
check_links:
73+
$(SPHINX_BUILD) --check-links

build.py

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
"""Build script for Sphinx documentation"""
2+
3+
import argparse
4+
from pathlib import Path
5+
6+
from sphinx.application import Sphinx
7+
8+
9+
def create_parser():
10+
parser = argparse.ArgumentParser(description="Build PEP documents")
11+
# alternative builders:
12+
parser.add_argument("-l", "--check-links", action="store_true")
13+
14+
# flags / options
15+
parser.add_argument("-f", "--fail-on-warning", action="store_true")
16+
parser.add_argument("-n", "--nitpicky", action="store_true")
17+
parser.add_argument("-j", "--jobs", type=int)
18+
19+
# extra build steps
20+
parser.add_argument("-i", "--index-file", action="store_true") # for PEP 0
21+
22+
return parser.parse_args()
23+
24+
25+
if __name__ == "__main__":
26+
args = create_parser()
27+
28+
root_directory = Path(".").absolute()
29+
source_directory = root_directory
30+
build_directory = root_directory / "build" # synchronise with deploy-gh-pages.yaml -> deploy step
31+
doctree_directory = build_directory / ".doctrees"
32+
33+
# builder configuration
34+
sphinx_builder = "dirhtml"
35+
if args.check_links:
36+
sphinx_builder = "linkcheck"
37+
38+
# other configuration
39+
config_overrides = {}
40+
if args.nitpicky:
41+
config_overrides["nitpicky"] = True
42+
43+
app = Sphinx(
44+
source_directory,
45+
confdir=source_directory,
46+
outdir=build_directory,
47+
doctreedir=doctree_directory,
48+
buildername=sphinx_builder,
49+
confoverrides=config_overrides,
50+
warningiserror=args.fail_on_warning,
51+
parallel=args.jobs,
52+
)
53+
app.builder.copysource = False # Prevent unneeded source copying - we link direct to GitHub
54+
app.build()

conf.py

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
"""Configuration for building PEPs using Sphinx."""
2+
3+
# -- Project information -----------------------------------------------------
4+
5+
project = "PEPs"
6+
master_doc = "contents"
7+
8+
# -- General configuration ---------------------------------------------------
9+
10+
# The file extensions of source files. Sphinx uses these suffixes as sources.
11+
source_suffix = {
12+
".rst": "restructuredtext",
13+
".txt": "restructuredtext",
14+
}
15+
16+
# List of patterns (relative to source dir) to ignore when looking for source files.
17+
exclude_patterns = [
18+
# Windows:
19+
"Thumbs.db",
20+
".DS_Store",
21+
# Python:
22+
"venv",
23+
"requirements.txt",
24+
# Sphinx:
25+
"build",
26+
"output.txt", # Link-check output
27+
# PEPs:
28+
"README.rst",
29+
"CONTRIBUTING.rst",
30+
]
31+
32+
# -- Options for HTML output -------------------------------------------------
33+
34+
# HTML output settings
35+
html_show_copyright = False # Turn off miscellany
36+
html_show_sphinx = False
37+
html_title = "peps.python.org" # Set <title/>

contents.rst

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
Python Enhancement Proposals (PEPs)
3+
***********************************
4+
5+
6+
This is an internal Sphinx page, please go to the :doc:`PEP Index<pep-0000>`.
7+
8+
9+
.. toctree::
10+
:maxdepth: 3
11+
:titlesonly:
12+
:hidden:
13+
:glob:
14+
:caption: PEP Table of Contents (needed for Sphinx):
15+
16+
pep-*

requirements.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Requirements for building PEPs with Sphinx
2+
sphinx >= 3.5
3+
docutils >= 0.16

0 commit comments

Comments
 (0)