Skip to content

Commit d926651

Browse files
committed
WIP sphinx docs - initial local build working
1 parent 60d7469 commit d926651

File tree

9 files changed

+227
-5
lines changed

9 files changed

+227
-5
lines changed

CONTRIBUTING.md

+14
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,20 @@ $ nox --session=pre-commit
7171
Unit tests are located in the [tests/](tests/) directory,
7272
and are written using the [pytest](https://pytest.readthedocs.io/) testing framework.
7373

74+
## How to build docs
75+
76+
To build docs, serve them locally, and rebuild as they change:
77+
78+
```console
79+
$ nox --session=docs
80+
```
81+
82+
To just build docs to [docs/build/](docs/build/):
83+
84+
```console
85+
$ nox --non-interactive --session=docs
86+
```
87+
7488
## How to submit changes
7589

7690
Open a [pull request](https://github.com/jantman/machine_access_control/pulls) to submit changes to this project.

docs/Makefile

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Minimal makefile for Sphinx documentation
2+
#
3+
4+
# You can set these variables from the command line, and also
5+
# from the environment for the first two.
6+
SPHINXOPTS ?=
7+
SPHINXBUILD ?= sphinx-build
8+
SOURCEDIR = source
9+
BUILDDIR = build
10+
11+
# Put it first so that "make" without argument is like "make help".
12+
help:
13+
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
14+
15+
VENV = .venv
16+
export VIRTUAL_ENV := $(abspath ${VENV})
17+
export PATH := ${VIRTUAL_ENV}/bin:${PATH}
18+
export GIT_COMMIT := $(shell git rev-parse --short HEAD)
19+
export GITURL := $(shell git config remote.origin.url)
20+
export BRANCH_NAME := $(shell git rev-parse --abbrev-ref HEAD)
21+
# TODO: update the proper git URL here:
22+
ifneq "$(GITURL)" "[email protected]:jantman/machine-access-control.git"
23+
export GIT_COMMIT := ${GIT_COMMIT} (branch '${BRANCH_NAME}' from $(GITURL))
24+
endif
25+
26+
${VENV}:
27+
python3 -mvenv $@;
28+
29+
setup: ${VENV}
30+
# pin docutils due to bug: https://stackoverflow.com/questions/67542699/readthedocs-sphinx-not-rendering-bullet-list-from-rst-file
31+
. .venv/bin/activate; python3 -m pip install -r requirements.txt
32+
33+
ghp: setup
34+
# WARNING - there aren't any checks to prevent someone with appropriate permissions
35+
# from pushing their local build directly to the live docs. Don't copy this pattern!
36+
@echo giturl is $(GITURL)
37+
cd build/dirhtml && \
38+
git init && \
39+
git remote add origin $(GITURL) && \
40+
git checkout -b gh-pages && \
41+
git add --all && \
42+
git commit -m "local docs build" && \
43+
git push -f origin HEAD:gh-pages
44+
45+
.PHONY: help setup all
46+
47+
html: setup
48+
. .venv/bin/activate; python3 -msphinx "$(SOURCEDIR)" "$(BUILDDIR)/html" -b html -E -W
49+
50+
all: clean html
51+
52+
# Catch-all target: route all unknown targets to Sphinx using the new
53+
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
54+
%: all

docs/requirements.txt

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
sphinx==7.4.7
2+
sphinx_rtd_theme==2.0.0
3+
sphinx-autobuild==2024.4.16
4+
sphinx-last-updated-by-git==0.3.7
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/* thanks to: https://rackerlabs.github.io/docs-rackspace/tools/rtd-tables.html */
2+
/* override table width restrictions */
3+
@media screen and (min-width: 767px) {
4+
.wy-table-responsive table td {
5+
/* !important prevents the common CSS stylesheets from overriding
6+
this as on RTD they are loaded after this stylesheet */
7+
white-space: normal !important;
8+
}
9+
10+
.wy-table-responsive {
11+
overflow: visible !important;
12+
}
13+
}

docs/source/conf.py

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
"""Configuration file for the Sphinx documentation builder.
2+
3+
For the full list of built-in configuration values, see the documentation:
4+
https://www.sphinx-doc.org/en/master/usage/configuration.html
5+
"""
6+
7+
import os
8+
from urllib.parse import urlparse
9+
10+
11+
# -- Project information -----------------------------------------------------
12+
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
13+
14+
project = "machine-access-control"
15+
copyright = "2024, Jason Antman"
16+
author = "Jason Antman"
17+
18+
# -- General configuration ---------------------------------------------------
19+
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
20+
21+
extensions = [
22+
"sphinx.ext.githubpages",
23+
"sphinx.ext.todo",
24+
"sphinx.ext.intersphinx",
25+
"sphinx_last_updated_by_git",
26+
]
27+
28+
templates_path = ["_templates"]
29+
exclude_patterns = []
30+
31+
# If true, `todo` and `todoList` produce output, else they produce nothing.
32+
todo_include_todos = True
33+
34+
# -- Options for HTML output -------------------------------------------------
35+
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
36+
37+
html_theme = "sphinx_rtd_theme"
38+
html_theme_options = {
39+
"navigation_depth": 4,
40+
"collapse_navigation": False,
41+
"sticky_navigation": False,
42+
}
43+
html_static_path = ["_static"]
44+
45+
html_context = {"theme_vcs_pageview_mode": "edit", "conf_py_path": "/source/"}
46+
47+
if os.environ.get("GITHUB_ACTIONS") == "true":
48+
html_context["display_github"] = True
49+
html_context["github_user"], html_context["github_repo"] = os.environ[
50+
"GITHUB_REPOSITORY"
51+
].split("/")
52+
html_context["github_host"] = urlparse(os.environ["GITHUB_API_URL"]).hostname
53+
html_context["github_version"] = os.environ.get(
54+
"GITHUB_REF_NAME",
55+
os.environ.get("GITHUB_HEAD_REF", os.environ.get("GITHUB_SHA")),
56+
)
57+
58+
html_css_files = [
59+
# thanks to: https://rackerlabs.github.io/docs-rackspace/tools/rtd-tables.html
60+
"theme_overrides.css" # override wide tables in RTD theme
61+
]

docs/source/index.rst

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
.. machine-access-control documentation master file, created by
2+
sphinx-quickstart on Sun Aug 4 15:42:24 2024.
3+
You can adapt this file completely to your liking, but it should at least
4+
contain the root `toctree` directive.
5+
6+
Welcome to machine-access-control's documentation!
7+
==================================================
8+
9+
.. toctree::
10+
:maxdepth: 2
11+
:caption: Contents:
12+
13+
14+
15+
Indices and tables
16+
==================
17+
18+
* :ref:`genindex`
19+
* :ref:`modindex`
20+
* :ref:`search`

noxfile.py

+21
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import os
44
import shlex
5+
import shutil
56
import sys
67
from pathlib import Path
78
from textwrap import dedent
@@ -197,3 +198,23 @@ def typeguard(session: Session) -> None:
197198
session.install(".")
198199
session.install("pytest", "typeguard", "pygments")
199200
session.run("pytest", f"--typeguard-packages={package}", *session.posargs)
201+
202+
203+
@session(python=python_versions[0], reuse_venv=True)
204+
def docs(session: Session) -> None:
205+
"""Build the documentation."""
206+
args = session.posargs or ["-b", "html", "docs/source", "docs/build", "-E", "-W"]
207+
208+
if session.interactive and not session.posargs:
209+
args = ["-a", "--watch=docs/source/_static", "--open-browser", *args]
210+
211+
builddir = Path("docs", "build")
212+
if builddir.exists():
213+
shutil.rmtree(builddir)
214+
215+
session.install("-r", "docs/requirements.txt")
216+
217+
if session.interactive:
218+
session.run("sphinx-autobuild", *args)
219+
else:
220+
session.run("sphinx-build", *args)

poetry.lock

+38-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

+2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ typeguard = ">=2.13.3"
4747

4848
[tool.poetry.group.dev.dependencies]
4949
pytest-blockage = "^0.2.4"
50+
sphinx = "<8.0"
51+
sphinx-rtd-theme = "^2.0.0"
5052

5153
[tool.coverage.paths]
5254
source = ["src", "*/site-packages"]

0 commit comments

Comments
 (0)