From 8389436a293cbb56fd6f489613792a76104e4362 Mon Sep 17 00:00:00 2001 From: Dominik Picheta Date: Tue, 7 Jan 2025 18:09:26 +0000 Subject: [PATCH] Adds Sphinx config to generate Python SDK docs. --- src/pyodide/internal/sphinx/.gitignore | 1 + src/pyodide/internal/sphinx/Makefile | 20 +++++++++++ src/pyodide/internal/sphinx/README.md | 13 +++++++ src/pyodide/internal/sphinx/conf.py | 38 ++++++++++++++++++++ src/pyodide/internal/sphinx/docs/asgi.rst | 7 ++++ src/pyodide/internal/sphinx/docs/modules.rst | 8 +++++ src/pyodide/internal/sphinx/docs/workers.rst | 7 ++++ src/pyodide/internal/sphinx/index.rst | 17 +++++++++ src/pyodide/internal/sphinx/make.bat | 35 ++++++++++++++++++ 9 files changed, 146 insertions(+) create mode 100644 src/pyodide/internal/sphinx/.gitignore create mode 100644 src/pyodide/internal/sphinx/Makefile create mode 100644 src/pyodide/internal/sphinx/README.md create mode 100644 src/pyodide/internal/sphinx/conf.py create mode 100644 src/pyodide/internal/sphinx/docs/asgi.rst create mode 100644 src/pyodide/internal/sphinx/docs/modules.rst create mode 100644 src/pyodide/internal/sphinx/docs/workers.rst create mode 100644 src/pyodide/internal/sphinx/index.rst create mode 100644 src/pyodide/internal/sphinx/make.bat diff --git a/src/pyodide/internal/sphinx/.gitignore b/src/pyodide/internal/sphinx/.gitignore new file mode 100644 index 00000000000..e35d8850c96 --- /dev/null +++ b/src/pyodide/internal/sphinx/.gitignore @@ -0,0 +1 @@ +_build diff --git a/src/pyodide/internal/sphinx/Makefile b/src/pyodide/internal/sphinx/Makefile new file mode 100644 index 00000000000..d4bb2cbb9ed --- /dev/null +++ b/src/pyodide/internal/sphinx/Makefile @@ -0,0 +1,20 @@ +# Minimal makefile for Sphinx documentation +# + +# You can set these variables from the command line, and also +# from the environment for the first two. +SPHINXOPTS ?= +SPHINXBUILD ?= sphinx-build +SOURCEDIR = . +BUILDDIR = _build + +# Put it first so that "make" without argument is like "make help". +help: + @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) + +.PHONY: help Makefile + +# Catch-all target: route all unknown targets to Sphinx using the new +# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). +%: Makefile + @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) diff --git a/src/pyodide/internal/sphinx/README.md b/src/pyodide/internal/sphinx/README.md new file mode 100644 index 00000000000..76d58a7b775 --- /dev/null +++ b/src/pyodide/internal/sphinx/README.md @@ -0,0 +1,13 @@ +## Python SDK docs markdown generator + +This directory contains config files for Sphinx, which can generate docs based on the exported methods in asgi.py and workers.py which make part of the Python SDK. + +### Usage + + +``` +# set up venv with sphinx and sphinx-markdown-builder installed +make markdown +``` + +You'll then find the markdown in _build/markdown/docs/workers.md. diff --git a/src/pyodide/internal/sphinx/conf.py b/src/pyodide/internal/sphinx/conf.py new file mode 100644 index 00000000000..c267905add4 --- /dev/null +++ b/src/pyodide/internal/sphinx/conf.py @@ -0,0 +1,38 @@ +# Configuration file for the Sphinx documentation builder. +# +# For the full list of built-in configuration values, see the documentation: +# https://www.sphinx-doc.org/en/master/usage/configuration.html + +# -- Project information ----------------------------------------------------- +# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information + +project = 'Python Workers API' +copyright = '2025, Cloudflare' +author = 'Cloudflare' + +# -- General configuration --------------------------------------------------- +# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration + +extensions = [ + 'sphinx.ext.autodoc', + 'sphinx_markdown_builder' +] +autodoc_mock_imports = ["js", "pyodide.http", "pyodide.ffi", "fastapi", "pyodide"] + + +templates_path = ['_templates'] +exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store'] + + + +# -- Options for HTML output ------------------------------------------------- +# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output + +html_theme = 'alabaster' +html_static_path = ['_static'] + +# Add the parent dir to the search path, so that the .py files can be accessed. +import os +import sys + +sys.path.insert(0, os.path.abspath('..')) diff --git a/src/pyodide/internal/sphinx/docs/asgi.rst b/src/pyodide/internal/sphinx/docs/asgi.rst new file mode 100644 index 00000000000..c616094b851 --- /dev/null +++ b/src/pyodide/internal/sphinx/docs/asgi.rst @@ -0,0 +1,7 @@ +asgi module +=========== + +.. automodule:: asgi + :members: + :undoc-members: + :show-inheritance: diff --git a/src/pyodide/internal/sphinx/docs/modules.rst b/src/pyodide/internal/sphinx/docs/modules.rst new file mode 100644 index 00000000000..e13e83a22c1 --- /dev/null +++ b/src/pyodide/internal/sphinx/docs/modules.rst @@ -0,0 +1,8 @@ +SDK +=== + +.. toctree:: + :maxdepth: 4 + + asgi + workers diff --git a/src/pyodide/internal/sphinx/docs/workers.rst b/src/pyodide/internal/sphinx/docs/workers.rst new file mode 100644 index 00000000000..184c1f373d1 --- /dev/null +++ b/src/pyodide/internal/sphinx/docs/workers.rst @@ -0,0 +1,7 @@ +workers module +============== + +.. automodule:: workers + :members: + :undoc-members: + :show-inheritance: diff --git a/src/pyodide/internal/sphinx/index.rst b/src/pyodide/internal/sphinx/index.rst new file mode 100644 index 00000000000..1837b6a7cd6 --- /dev/null +++ b/src/pyodide/internal/sphinx/index.rst @@ -0,0 +1,17 @@ +.. Python Workers API documentation master file, created by + sphinx-quickstart on Tue Jan 7 15:01:02 2025. + You can adapt this file completely to your liking, but it should at least + contain the root `toctree` directive. + +Python Workers API documentation +================================ + +Add your content using ``reStructuredText`` syntax. See the +`reStructuredText `_ +documentation for details. + + +.. toctree:: + :maxdepth: 2 + :caption: Contents: + diff --git a/src/pyodide/internal/sphinx/make.bat b/src/pyodide/internal/sphinx/make.bat new file mode 100644 index 00000000000..32bb24529f9 --- /dev/null +++ b/src/pyodide/internal/sphinx/make.bat @@ -0,0 +1,35 @@ +@ECHO OFF + +pushd %~dp0 + +REM Command file for Sphinx documentation + +if "%SPHINXBUILD%" == "" ( + set SPHINXBUILD=sphinx-build +) +set SOURCEDIR=. +set BUILDDIR=_build + +%SPHINXBUILD% >NUL 2>NUL +if errorlevel 9009 ( + echo. + echo.The 'sphinx-build' command was not found. Make sure you have Sphinx + echo.installed, then set the SPHINXBUILD environment variable to point + echo.to the full path of the 'sphinx-build' executable. Alternatively you + echo.may add the Sphinx directory to PATH. + echo. + echo.If you don't have Sphinx installed, grab it from + echo.https://www.sphinx-doc.org/ + exit /b 1 +) + +if "%1" == "" goto help + +%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% +goto end + +:help +%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% + +:end +popd