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

Issue #17: Sphinx documentation #98

Merged
merged 4 commits into from
Jan 30, 2024
Merged
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
42 changes: 42 additions & 0 deletions .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Documentation

on:
push:
branches:
- develop

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: write
pages: write
id-token: write


jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
with:
python-version: '3.10'
- name: Mock Basilisk
run: |
cp docs/sitecustomize.py $(python -c 'import site; print(site.getsitepackages()[0])')/sitecustomize.py
- name: Install dependencies
run: |
pip install -e .
# skip finish install steps
- name: Sphinx build
run: |
cd docs
make html
cd ..
- name: Deploy
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./docs/build/html
force_orphan: true


4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ wheels/
.installed.cfg
*.egg


# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
Expand Down Expand Up @@ -68,6 +69,8 @@ instance/

# Sphinx documentation
docs/_build/
docs/source/API Reference
docs/source/Examples

# Pickles
*.pkl
Expand All @@ -81,7 +84,6 @@ target/
# PDFs and Images
*.pdf
*.jpg
*.png

# pyenv
.python-version
Expand Down
19 changes: 19 additions & 0 deletions CITATION.cff
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
cff-version: 1.2.0
message: "If you use this software, please cite it as below."
authors:
- family-names: "Stephenson"
given-names: "Mark"
orcid: "https://orcid.org/0009-0004-3438-8127"
- family-names: "Mantovani"
given-names: "Lorenzzo"
orcid: "https://orcid.org/0000-0001-7244-7491"
- family-names: "Herrmann"
given-names: "Adam"
orcid: "https://orcid.org/0000-0001-6179-7728"
- family-names: "Schaub"
given-names: "Hanspeter"
orcid: "https://orcid.org/0000-0003-0002-6035"
title: "BSK-RL"
version: 0.0.0
date-released: 2023
url: "https://github.com/AVSLab/bsk_rl/"
28 changes: 28 additions & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# 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 = source
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)

clean:
rm -rf "source/Examples" "source/API Reference"


view:
# works on macOS
open build/html/index.html
35 changes: 35 additions & 0 deletions docs/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=source
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
45 changes: 45 additions & 0 deletions docs/sitecustomize.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import ast
import os
import pkgutil
import sys
from unittest.mock import MagicMock

"""
Copy this file to the site-packages directory of your virtual environment to mock
Basilisk for generating documentation without Basilisk installed
"""

os.environ["PYTHON_MOCK_BASILISK"] = "1"

bsk_rl_package_path = (
pkgutil.get_loader("bsk_rl").get_filename().split("__init__.py")[0]
)
print(bsk_rl_package_path)

# Find all imports from Basilisk within bsk_rl package
all_basilisk_imports = set()
for root, _, files in os.walk(bsk_rl_package_path):
for file in files:
if file.endswith(".py"):
file_path = os.path.join(root, file)
with open(file_path, "r") as f:
try:
tree = ast.parse(f.read(), filename=file)
for node in ast.walk(tree):
if isinstance(node, ast.Import):
for alias in node.names:
if alias.name.startswith("Basilisk"):
all_basilisk_imports.add(alias.name)
elif isinstance(node, ast.ImportFrom):
if node.module and node.module.startswith("Basilisk"):
all_basilisk_imports.add(node.module)
except Exception as e:
print(f"Error parsing {file_path}: {e}")

# Mock those imports
for submodule_name in all_basilisk_imports:
sys.modules[submodule_name] = MagicMock()

# Mock some other imports that might cause issues
sys.modules["Basilisk"].__path__ = "not/a/real/path"
sys.modules["chebpy"] = MagicMock()
Binary file added docs/source/_images/static/Basilisk-Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading