Skip to content

Commit 1668a16

Browse files
authored
Improve php-src docs sphinx build, also on *nix (GH-16743)
* Document .rst file maximum line length of 100 In 19d2b84 ("Create book for docs", 2024-01-30) the build of the php-src documentation has been introduced. It is based on reStructuredText (rst) [Docutils] for its source files, this stems from the sphinx-build utility in use to build the static HTML pages of the php-src documentation. The maximum line length of these text files has been set to 100 characters in 19d2b84 ("Create book for docs", 2024-01-30), the rationale is unknown to the documenting author at time of writing this message. This formatting constraint is applied with the rstfmt utility [rstfmt] via its invocation (documented in CI build instructions and README.md:) rstfmt -w 100 source The `-w, --width` option takes a WIDTH argument that is "the target line length in characters" (cf. `rstfmt --help`.) There is also an `--ext EXT` argument option, that is "the extension of files to look at when passed a directory" ("source" is the name of a directory in the invocation above) and defaults to "rst". Henceforth, the editor configuration [EditorConfig] can benefit from documenting this expectation in the repositories .editorconfig file, which has been introduced already earlier in 5c38fbe ("Added editorconfig file", 2016-06-26). [Docutils]: https://docutils.sourceforge.io/index.html "Docutils: Documentation Utilities — Written in Python, for General- and Special-Purpose Use" [rstfmt]: https://github.com/dzhu/rstfmt "A formatter for reStructuredText" [EditorConfig]: https://editorconfig.org/ "EditorConfig helps maintain consistent coding styles for multiple developers working on the same project across various editors and IDEs" * Makefile for php-src docs build In 19d2b84 ("Create book for docs", 2024-01-30) the php-src documentation (php-src docs) build has been introduced, yet the build instructions, namely `make html`, did not yield the expected results within the parenting setup of the php-src project on *nix systems. The reason is that the `make html` build instruction does not execute the make.bat file which contains the recipe to build the static HTML pages. It is an unused leftover file from initializing the project with sphinx-quickstart. [1] Removing it in and adding a Makefile suffices to recover the build of php-src ./docs on a *nix system. Formatting constraints checked in the docs workflow in CI update use the make file to make sure the commands stay consistent and the build is managed by the build manager. [1]: https://www.sphinx-doc.org/en/master/man/sphinx-quickstart.html "sphinx-quickstart is an interactive tool that asks some questions about your project and then generates a complete documentation directory and sample Makefile to be used with sphinx-build(1)." * Bind requirements.txt for php-src docs build Define the required packages to install for the php-src docs build in the docs/requirements.txt file: 1) Sphinx 2) sphinx-design 3) sphinxawesome-theme 4) rstfmt This should also later on ease the use of a requirements_frozen.txt file to pin the build dependencies if needed/wanted. Additionally, some formatting corrections in README.md (based on the profile in .editorconfig) as well as adding the recommendation to use a Python virtual environment. Python3 and Pip were already named, and with Python3 there is the venv module (Python 3.3; Sep 2012) to manage these so-called python virtual environments [venv], which are commonly a preferred way to install dependencies within development projects and build systems. [venv]: https://docs.python.org/3/library/venv.html "venv — Creation of virtual environments — Python documentation" * Remove deprecated theme configuration For the configured Awesome Sphinx Theme [1] highlighting extension, the sphinx-build currently yields the following diagnostics: WARNING: while setting up extension sphinxawesome_theme.highlighting: \ You no longer have to include the `sphinxawsome_theme.highlighting` \ extension. This extension will be removed in the next major release. (via `make html`, the configuration file is `source/conf.py`.) The diagnostic message was introduced by sphinxawesome-theme 5.2.0, released May 31, 2024. [2], [3] Removing the extension from the list of extensions in the configuration file levitates. No changes to requirements.txt, the extension was transitive as bundled by the Awesome Sphinx Theme [1], and 5.2.0 deprecates it with the new feature to "Support `pygments_style_dark` option that allows you to set a different syntax highlighting scheme in light and dark modes." [3] [1]: https://sphinxawesome.xyz/ "Awesome Sphinx Theme — Create functional and beautiful websites for your documentation with Sphinx." [2]: https://pypi.org/project/sphinxawesome-theme/5.2.0/#history [3]: https://github.com/kai687/sphinxawesome-theme/releases/tag/5.2.0
1 parent 563da1b commit 1668a16

File tree

7 files changed

+58
-45
lines changed

7 files changed

+58
-45
lines changed

.editorconfig

+4
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,7 @@ max_line_length = 80
3232

3333
[*.patch]
3434
trim_trailing_whitespace = false
35+
36+
[*.rst]
37+
indent_style = space
38+
max_line_length = 100

.github/workflows/docs.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ jobs:
1919
- name: git checkout
2020
uses: actions/checkout@v4
2121
- name: Install dependencies
22-
run: pip install sphinx-design sphinxawesome-theme rstfmt
22+
run: pip install -r docs/requirements.txt
2323
- name: Check formatting
24-
run: rstfmt --check -w 100 docs/source
24+
run: make -C docs check-formatting
2525
- name: Publish
2626
if: github.event_name == 'push'
2727
uses: sphinx-notes/pages@v3

docs/Makefile

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Makefile for php-src/docs
2+
# Copyright (c) The PHP Group
3+
4+
# If people set these on the make command line, use 'em
5+
6+
SPHINXBUILD ?= sphinx-build
7+
8+
SOURCEDIR = source
9+
BUILDDIR = build
10+
RSTFMT = rstfmt
11+
RSTFMTFLAGS = -w 100
12+
13+
rwildcard = $(foreach d,$(wildcard $(1:=/*)),$(call rwildcard,$d,$2) $(filter $(subst *,%,$2),$d))
14+
FILES = $(call rwildcard,$(SOURCEDIR),*.rst)
15+
16+
all : html
17+
18+
.PHONY : check-formatting clean html preflight
19+
.SUFFIXES : # Disable legacy behavior
20+
21+
check-formatting :
22+
$(RSTFMT) $(RSTFMTFLAGS) --check $(SOURCEDIR)
23+
24+
clean :
25+
rm -rf -- $(wildcard $(SOURCEDIR)/.~ $(BUILDDIR))
26+
27+
html : preflight
28+
$(SPHINXBUILD) -M $@ $(SOURCEDIR) $(BUILDDIR)
29+
@printf 'Browse the \e]8;;%s\e\\%s\e]8;;\e\\.\n' \
30+
"file://$(abspath $(BUILDDIR))/$@/index.$@" "php-src html docs locally"
31+
32+
preflight : $(SOURCEDIR)/.~
33+
34+
$(SOURCEDIR)/.~ : $(FILES)
35+
$(RSTFMT) $(RSTFMTFLAGS) $?
36+
touch $@

docs/README.md

+12-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
# php-src docs
22

33
This is the home of the php-src internal documentation, hosted at
4-
[php.github.io/php-src/](https://php.github.io/php-src/). It is in very early stages, but is
5-
intended to become the primary place where new information about php-src is documented. Over time,
6-
it is expected to replace various mediums like:
4+
[php.github.io/php-src/](https://php.github.io/php-src/). It is in very early
5+
stages, but is intended to become the primary place where new information about
6+
php-src is documented. Over time, it is expected to replace various mediums
7+
like:
78

89
* https://www.phpinternalsbook.com/
910
* https://wiki.php.net/internals
@@ -14,11 +15,15 @@ it is expected to replace various mediums like:
1415
`python` 3 and `pip` are required.
1516

1617
```bash
17-
pip install sphinx sphinx-design sphinxawesome-theme
18+
cd docs
19+
# Recommended: Initialize and activate a Python virtual environment
20+
pip install --upgrade pip
21+
pip install -r requirements.txt
1822
make html
1923
```
2024

21-
That's it! You can view the documentation under `./build/html/index.html` in your browser.
25+
That's it! You can view the documentation under `./build/html/index.html` in
26+
your browser.
2227

2328
## Formatting
2429

@@ -29,5 +34,5 @@ The files in this documentation are formatted using the
2934
rstfmt -w 100 source
3035
```
3136

32-
This tool is not perfect. It breaks on custom directives, so we might switch to either a fork or
33-
something else in the future.
37+
This tool is not perfect. It breaks on custom directives, so we might switch to
38+
either a fork or something else in the future.

docs/make.bat

-35
This file was deleted.

docs/requirements.txt

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Sphinx
2+
sphinx-design
3+
sphinxawesome-theme
4+
rstfmt

docs/source/conf.py

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
author = 'The PHP Group'
1717
extensions = [
1818
'sphinx_design',
19-
'sphinxawesome_theme.highlighting',
2019
]
2120
templates_path = ['_templates']
2221
html_theme = 'sphinxawesome_theme'

0 commit comments

Comments
 (0)