Skip to content

Commit

Permalink
Adds Sphinx config to generate Python SDK docs.
Browse files Browse the repository at this point in the history
  • Loading branch information
dom96 committed Jan 9, 2025
1 parent 19fc71c commit 4dbaa80
Show file tree
Hide file tree
Showing 10 changed files with 179 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/pyodide/internal/sphinx/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_build
20 changes: 20 additions & 0 deletions src/pyodide/internal/sphinx/Makefile
Original file line number Diff line number Diff line change
@@ -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)
17 changes: 17 additions & 0 deletions src/pyodide/internal/sphinx/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
## 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. These files are a part of the Python SDK.

### Usage


```
python -m venv .venv
source .venv/bin/activate
pip install -r requirements-doc.txt
make markdown
```

You'll then find the markdown in _build/markdown/docs/workers.md.

Make a PR in the cloudflare-docs repo to update the appropriate files.
39 changes: 39 additions & 0 deletions src/pyodide/internal/sphinx/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# 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",
"sphinx.ext.autosummary",
"myst_parser",
]
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 sys
from pathlib import Path

sys.path.insert(0, str(Path.resolve(Path(".."))))
7 changes: 7 additions & 0 deletions src/pyodide/internal/sphinx/docs/asgi.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
asgi module
===========

.. automodule:: asgi
:members:
:undoc-members:
:show-inheritance:
8 changes: 8 additions & 0 deletions src/pyodide/internal/sphinx/docs/modules.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
SDK
===

.. toctree::
:maxdepth: 4

asgi
workers
7 changes: 7 additions & 0 deletions src/pyodide/internal/sphinx/docs/workers.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
workers module
==============

.. automodule:: workers
:members:
:undoc-members:
:show-inheritance:
17 changes: 17 additions & 0 deletions src/pyodide/internal/sphinx/index.rst
Original file line number Diff line number Diff line change
@@ -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 <https://www.sphinx-doc.org/en/master/usage/restructuredtext/index.html>`_
documentation for details.


.. toctree::
:maxdepth: 2
:caption: Contents:

35 changes: 35 additions & 0 deletions src/pyodide/internal/sphinx/make.bat
Original file line number Diff line number Diff line change
@@ -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
28 changes: 28 additions & 0 deletions src/pyodide/internal/sphinx/requirements-doc.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
alabaster==1.0.0
babel==2.16.0
certifi==2024.12.14
charset-normalizer==3.4.1
docutils==0.21.2
idna==3.10
imagesize==1.4.1
Jinja2==3.1.5
markdown-it-py==3.0.0
MarkupSafe==3.0.2
mdit-py-plugins==0.4.2
mdurl==0.1.2
myst-parser==4.0.0
packaging==24.2
Pygments==2.19.1
PyYAML==6.0.2
requests==2.32.3
snowballstemmer==2.2.0
Sphinx==8.1.3
sphinx-markdown-builder==0.6.7
sphinxcontrib-applehelp==2.0.0
sphinxcontrib-devhelp==2.0.0
sphinxcontrib-htmlhelp==2.1.0
sphinxcontrib-jsmath==1.0.1
sphinxcontrib-qthelp==2.0.0
sphinxcontrib-serializinghtml==2.0.0
tabulate==0.9.0
urllib3==2.3.0

0 comments on commit 4dbaa80

Please sign in to comment.