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 7, 2025
1 parent 19fc71c commit 8389436
Show file tree
Hide file tree
Showing 9 changed files with 146 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)
13 changes: 13 additions & 0 deletions src/pyodide/internal/sphinx/README.md
Original file line number Diff line number Diff line change
@@ -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.
38 changes: 38 additions & 0 deletions src/pyodide/internal/sphinx/conf.py
Original file line number Diff line number Diff line change
@@ -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('..'))
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

0 comments on commit 8389436

Please sign in to comment.