From 0bb832e1f9591508b217f482bb47e171dda4b741 Mon Sep 17 00:00:00 2001 From: AA Turner <9087854+AA-Turner@users.noreply.github.com> Date: Sun, 18 Apr 2021 05:36:59 +0100 Subject: [PATCH 01/10] Update .gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index e6e16dd974f..b9c89215748 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,5 @@ __pycache__ .vscode *.swp /build +/package +/venv From 4e7f7e0fc8070580118db0581f436ce6097dd6e7 Mon Sep 17 00:00:00 2001 From: AA Turner <9087854+AA-Turner@users.noreply.github.com> Date: Sun, 18 Apr 2021 05:37:48 +0100 Subject: [PATCH 02/10] Add base sphinx build script --- build.py | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 build.py diff --git a/build.py b/build.py new file mode 100644 index 00000000000..be051938974 --- /dev/null +++ b/build.py @@ -0,0 +1,46 @@ +"""Build script for Sphinx documentation""" + +import argparse +from pathlib import Path + +from sphinx.application import Sphinx + + +def create_parser(): + parser = argparse.ArgumentParser(description="Build PEP documents") + # builders: + parser.add_argument("-b", "--builder", default="html", choices=("html", "dirhtml", "linkcheck")) + + # checks + parser.add_argument("-f", "--fail-on-warning", action="store_true") + parser.add_argument("-n", "--nitpicky", action="store_true") + + # extra build steps + parser.add_argument("-i", "--index-file", action="store_true") # for PEP 0 + + return parser.parse_args() + + +if __name__ == "__main__": + args = create_parser() + + root_directory = Path(".").absolute() + source_directory = root_directory + build_directory = root_directory / "build" + doctree_directory = build_directory / ".doctrees" + + config_overrides = {} + if args.nitpicky: + config_overrides["nitpicky"] = True + + app = Sphinx( + source_directory, + confdir=source_directory, + outdir=build_directory, + doctreedir=doctree_directory, + buildername=args.builder, + confoverrides=config_overrides, + warningiserror=args.fail_on_warning, + ) + app.builder.copysource = False # Prevent unneeded source copying - we link direct to GitHub + app.build() From 332ffb93f063b25c86cfa6d87444423831187588 Mon Sep 17 00:00:00 2001 From: AA Turner <9087854+AA-Turner@users.noreply.github.com> Date: Sun, 18 Apr 2021 05:38:02 +0100 Subject: [PATCH 03/10] Add requirements file --- requirements.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 requirements.txt diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 00000000000..99202ceca35 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +# Requirements for building PEPs with Sphinx +sphinx >= 3.5 +docutils >= 0.16 From 855cf8bd9f59b303425edfbf0d06da7f63a458c4 Mon Sep 17 00:00:00 2001 From: AA Turner <9087854+AA-Turner@users.noreply.github.com> Date: Sun, 18 Apr 2021 05:38:36 +0100 Subject: [PATCH 04/10] Update Makefile with sphinx targets --- Makefile | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 889134e6d48..284611a6a34 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,5 @@ -# Rules to only make the required HTML versions, not all of them, -# without the user having to keep track of which. -# -# Not really important, but convenient. +# Builds PEP files to HTML using sphinx +# Also contains testing targets PEP2HTML=pep2html.py @@ -34,7 +32,6 @@ install: clean: -rm pep-0000.rst - -rm pep-0000.txt -rm *.html -rm -rf build @@ -43,7 +40,7 @@ update: venv: $(PYTHON) -m venv $(VENV_DIR) - ./$(VENV_DIR)/bin/python -m pip install -U docutils + ./$(VENV_DIR)/bin/python -m pip install -r requirements.txt package: all rss mkdir -p build/peps @@ -57,3 +54,24 @@ package: all rss lint: pre-commit --version > /dev/null || python3 -m pip install pre-commit pre-commit run --all-files + +pages: rss + $(PYTHON) build.py --index-file + +sphinx: + $(PYTHON) build.py + +fail_on_warning: + $(PYTHON) build.py -f + +check_links: + $(PYTHON) build.py -c + +sphinx_package: all rss + mkdir -p package/peps + $(PYTHON) package.py + cp pep-*.txt build/peps/ + cp pep-*.rst build/peps/ + cp *.png build/peps/ + cp *.rss package/peps + tar -C package -czf package/peps.tar.gz peps From 0f2033e932dadcf8ac0f589dc0e42d3b1e7a9dcd Mon Sep 17 00:00:00 2001 From: AA Turner <9087854+AA-Turner@users.noreply.github.com> Date: Sun, 18 Apr 2021 05:45:01 +0100 Subject: [PATCH 05/10] Add GH actions deploy script --- .github/workflows/deploy-gh-pages.yaml | 44 ++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 .github/workflows/deploy-gh-pages.yaml diff --git a/.github/workflows/deploy-gh-pages.yaml b/.github/workflows/deploy-gh-pages.yaml new file mode 100644 index 00000000000..6bbadab5d4e --- /dev/null +++ b/.github/workflows/deploy-gh-pages.yaml @@ -0,0 +1,44 @@ +name: Deploy to GitHub Pages + +on: [push] + +jobs: + deploy-to-pages: + runs-on: ubuntu-latest + + steps: + - name: 🛎️ Checkout + uses: actions/checkout@v2 + + - name: 🐍 Set up Python 3.9 + uses: actions/setup-python@v2 + with: + python-version: 3.9 + + - name: 🧳 Cache pip + uses: actions/cache@v2 + with: + # This path is specific to Ubuntu + path: ~/.cache/pip + # Look to see if there is a cache hit for the corresponding requirements file + key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }} + restore-keys: | + ${{ runner.os }}-pip- + ${{ runner.os }}- + + # Install dependencies and build PEPs using sphinx + - name: 👷 Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + make pages + + # Install dependencies and build PEPs using sphinx + - name: 🔧 Build PEPs + run: make pages + + - name: 🚀 Deploy to GitHub pages + uses: JamesIves/github-pages-deploy-action@4.1.1 + with: + BRANCH: gh-pages # The branch the action should deploy to. + FOLDER: build # The folder the action should deploy. From d2c92d537f4ae296464369c85c3d18df4474d85d Mon Sep 17 00:00:00 2001 From: AA Turner <9087854+AA-Turner@users.noreply.github.com> Date: Sun, 18 Apr 2021 05:55:33 +0100 Subject: [PATCH 06/10] Add conf.py and contents.rst for Sphinx --- conf.py | 37 +++++++++++++++++++++++++++++++++++++ contents.rst | 16 ++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 conf.py create mode 100644 contents.rst diff --git a/conf.py b/conf.py new file mode 100644 index 00000000000..34835c38a3b --- /dev/null +++ b/conf.py @@ -0,0 +1,37 @@ +"""Configuration for building PEPs using Sphinx.""" + +# -- Project information ----------------------------------------------------- + +project = "PEPs" +master_doc = "contents" + +# -- General configuration --------------------------------------------------- + +# The file extensions of source files. Sphinx uses these suffixes as sources. +source_suffix = { + ".rst": "restructuredtext", + ".txt": "restructuredtext", +} + +# List of patterns (relative to source dir) to ignore when looking for source files. +exclude_patterns = [ + # Windows: + "Thumbs.db", + ".DS_Store", + # Python: + "venv", + "requirements.txt", + # Sphinx: + "build", + "output.txt", # Link-check output + # PEPs: + "README.rst", + "CONTRIBUTING.rst", +] + +# -- Options for HTML output ------------------------------------------------- + +# HTML output settings +html_show_copyright = False # Turn off miscellany +html_show_sphinx = False +html_title = "peps.python.org" # Set