Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Python documentation generation #1218

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: docs
description: Build and deploy documentation (both C++/slang and Python/pyslang)

on:
push:
Expand All @@ -14,16 +15,22 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install dependencies
run: |
pip install jinja2 pygments
pip install jinja2 pygments docutils
wget https://sourceforge.net/projects/doxygen/files/rel-1.13.2/doxygen-1.13.2.linux.bin.tar.gz
tar -xvf doxygen-1.13.2.linux.bin.tar.gz
cp doxygen-1.13.2/bin/doxygen /usr/local/bin
- name: Build
- name: Build slang and pyslang docs via CMake
run: |
cmake -B build -DSLANG_INCLUDE_DOCS=ON -DSLANG_INCLUDE_TESTS=OFF
cmake --build build --target docs -j8
- name: Compress docs artifacts
run: |
tar -czvf slang.tar.gz build/docs build/bin/slang
- name: Upload
if: github.event_name != 'pull_request'
Expand Down
2 changes: 1 addition & 1 deletion bindings/python/StatementBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void registerStatements(py::module_& m) {
return fmt::format("Statement(StatementKind.{})", toString(self.kind));
});

py::enum_<Statement::EvalResult>(stmt, "EvalResult")
py::enum_<Statement::EvalResult>(m, "EvalResult")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did this change?

Copy link
Contributor Author

@parker-research parker-research Feb 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It gave an error/caused an issue during documentation generation. I also believed that this new way is the way it should have been; maybe an example/test case would be good to reinforce what's intended with it if you disagree though!

.value("Fail", Statement::EvalResult::Fail)
.value("Success", Statement::EvalResult::Success)
.value("Return", Statement::EvalResult::Return)
Expand Down
33 changes: 29 additions & 4 deletions docs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@

FetchContent_Declare(
mcss
URL https://github.com/MikePopoloski/m.css/releases/download/release-6/mcss.zip
URL_HASH MD5=df18825299064642a6f1b5df44faf80c
URL https://github.com/parker-research/m.css/archive/refs/heads/mike-re-add-python.zip # FIXME:
# Update.
URL_HASH MD5=2380ae79a15bf624d8667b50ef6c936b
SOURCE_DIR "${PROJECT_BINARY_DIR}/mcss"
UPDATE_DISCONNECTED YES)
FetchContent_MakeAvailable(mcss)
Expand Down Expand Up @@ -37,7 +38,8 @@ set(DOXYGEN_TAGFILES
set(DOXYFILE_IN ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in)
set(DOXYFILE_OUT ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
set(SCRIPTS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../scripts)
set(DOXYGENPY_PATH "${mcss_SOURCE_DIR}/documentation/doxygen.py")
set(MCSS_DOXYGENPY_PATH "${mcss_SOURCE_DIR}/documentation/doxygen.py")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I started working on adding this here; finishing it up now

set(MCSS_PYTHONPY_PATH "${mcss_SOURCE_DIR}/documentation/python.py")

string(REPLACE ";" " " DOXYGEN_INPUT_DIR "${DOXYGEN_INPUT_DIR_LIST}")
string(REPLACE ";" " " DOXYGEN_EXAMPLE_DIRS "${DOXYGEN_EXAMPLE_DIR_LIST}")
Expand All @@ -60,10 +62,33 @@ add_custom_command(
${CMAKE_CURRENT_BINARY_DIR}/warnings.dox
COMMAND "${CMAKE_COMMAND}" -E rm -rf ${CMAKE_CURRENT_BINARY_DIR}/html
${CMAKE_CURRENT_BINARY_DIR}/xml
COMMAND ${Python_EXECUTABLE} ${DOXYGENPY_PATH} ${DOXYFILE_OUT}
COMMAND ${Python_EXECUTABLE} ${MCSS_DOXYGENPY_PATH} ${DOXYFILE_OUT}
MAIN_DEPENDENCY ${DOXYFILE_OUT}
${DOXYFILE_IN}
COMMENT "Generating docs"
VERBATIM)

add_custom_target(docs ALL DEPENDS ${DOXYGEN_INDEX_FILE})

# --- Python documentation with virtual environment ---
set(PYTHON_DOCS_DIR ${CMAKE_CURRENT_BINARY_DIR}/pyslang)
set(PYTHON_VENV_DIR ${PROJECT_BINARY_DIR}/venv)
file(MAKE_DIRECTORY ${PYTHON_DOCS_DIR})

add_custom_command(
OUTPUT ${PYTHON_DOCS_DIR}/index.html
COMMAND ${Python_EXECUTABLE} -m venv ${PYTHON_VENV_DIR}
COMMAND ${PYTHON_VENV_DIR}/bin/python -m pip install --upgrade pip
COMMAND ${PYTHON_VENV_DIR}/bin/python -m pip install jinja2 pygments docutils
COMMAND ${PYTHON_VENV_DIR}/bin/python -m pip install .
COMMAND ${PYTHON_VENV_DIR}/bin/python ${MCSS_PYTHONPY_PATH}
${PROJECT_SOURCE_DIR}/pyslang/docs/conf.py
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
DEPENDS ${PROJECT_SOURCE_DIR}/pyslang/docs/conf.py
COMMENT "Generating Python docs in virtual environment"
VERBATIM)

add_custom_target(python_docs DEPENDS ${PYTHON_DOCS_DIR}/index.html)

# Make sure both docs and python_docs are built with `make docs`
add_dependencies(docs python_docs)
4 changes: 4 additions & 0 deletions docs/Doxyfile.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Doxyfile 1.13.2

# Note that this file cloned-and-modified by the settings in CMakeLists.txt.
# Various placeholders (e.g., `@DOXYGEN_OUTPUT_DIR@`) are replaced with the
# values of the corresponding CMake variables.

# This file describes the settings to be used by the documentation system
# Doxygen (www.doxygen.org) for a project.
#
Expand Down
22 changes: 22 additions & 0 deletions pyslang/docs/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Docs: https://mcss.mosra.cz/documentation/python/
# Run this file with `<mcss_clone_path>/documentation/python.py <path_to_this_file>`

from pathlib import Path

# Find the root of the git repository.
_GIT_REPO_ROOT_PATH = Path(__file__).parent.parent.parent
assert (
_GIT_REPO_ROOT_PATH / ".git"
).is_dir(), "Git repository root not found/set incorrectly"

_DOCS_OUTPUT_PATH = _GIT_REPO_ROOT_PATH / "build/docs/html/pyslang"
_DOCS_OUTPUT_PATH.mkdir(parents=True, exist_ok=True)

# Set the m.css configuration variables.
PROJECT_TITLE = "pyslang"
INPUT_MODULES = ["pyslang"]
PYBIND11_COMPATIBILITY = True
OUTPUT = str(_DOCS_OUTPUT_PATH.absolute())

# Output the stubs for comparison/review, but not actually used.
OUTPUT_STUBS = str((_GIT_REPO_ROOT_PATH / "build/stubs").absolute())