Skip to content

Commit

Permalink
Initialize Sphinx
Browse files Browse the repository at this point in the history
Signed-off-by: GitHub <[email protected]>
  • Loading branch information
shenanigansd authored Jul 29, 2023
1 parent bbd1e76 commit b2b7fa6
Show file tree
Hide file tree
Showing 8 changed files with 548 additions and 485 deletions.
52 changes: 52 additions & 0 deletions .github/workflows/publish-docs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: "GitHub Pages - Python Sphinx"

on:
push:
pull_request:

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

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: "Checkout repository"
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3

- name: "Setup PDM"
uses: pdm-project/setup-pdm@c287ac6f97f5fa767aa06946c7f55f40100b78c1 # v3.3
with:
python-version: "3.11"
cache: true

- name: "Install dependencies"
run: pdm install --group docs

- name: "Build docs"
run: |
cd docs
make dirhtml
- name: "Upload artifact"
uses: actions/upload-pages-artifact@a753861a5debcf57bf8b404356158c8e1e33150c # v2.0.0
with:
path: ./docs/build/dirhtml

deploy:
if: ${{ github.ref == 'refs/heads/main' }}
environment:
name: "github-pages"
url: ${{ steps.deployment.outputs.page_url }}

runs-on: ubuntu-latest

needs: build
steps:
- name: "Deploy to GitHub Pages"
id: deployment
uses: actions/deploy-pages@12ab2b16cf43a7a061fe99da74b6f8f11fb77f5b # v2.0.3
20 changes: 20 additions & 0 deletions docs/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 = 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)
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
5 changes: 5 additions & 0 deletions docs/source/changelog.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.. See docs for details on formatting your entries
https://releases.readthedocs.io/en/latest/concepts.html
Changelog
=========
95 changes: 95 additions & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
"""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
"""

from importlib.metadata import metadata

project_metadata = metadata("dragonfly-mainframe")
project: str = project_metadata["Name"]
release: str = project_metadata["Version"]
REPO_LINK: str = project_metadata["Project-URL"].replace("repository, ", "")
copyright: str = "Let's build a ..." # noqa: A001
author: str = "Let's build a ... community"

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named "sphinx.ext.*") or your custom
# ones.
extensions = [
"sphinx.ext.autodoc",
"sphinx.ext.linkcode",
"sphinx.ext.intersphinx",
"sphinx.ext.napoleon",
"autoapi.extension",
"releases",
]

autoapi_type: str = "python"
autoapi_dirs: list[str] = ["../../src"]

intersphinx_mapping = {"python": ("https://docs.python.org/3", None)}

# Add any paths that contain templates here, relative to this directory.
templates_path: list[str] = ["_templates"]

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns: list[str] = ["_build", "Thumbs.db", ".DS_Store"]

# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
html_theme: str = "furo"

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path: list[str] = ["_static"]

releases_github_path = REPO_LINK.removeprefix("https://github.com/")
releases_release_uri = f"{REPO_LINK}/releases/tag/v%s"


def linkcode_resolve(domain, info):
"""linkcode_resolve"""
if domain != "py":
return None
if not info["module"]:
return None

import importlib # pylint: disable=import-outside-toplevel
import inspect # pylint: disable=import-outside-toplevel
import types # pylint: disable=import-outside-toplevel

mod = importlib.import_module(info["module"])

val = mod
for k in info["fullname"].split("."):
val = getattr(val, k, None)
if val is None:
break

filename = info["module"].replace(".", "/") + ".py"

if isinstance(
val,
(
types.ModuleType,
types.MethodType,
types.FunctionType,
types.TracebackType,
types.FrameType,
types.CodeType,
),
):
try:
lines, first = inspect.getsourcelines(val)
last = first + len(lines) - 1
filename += f"#L{first}-L{last}"
except (OSError, TypeError):
pass

return f"{REPO_LINK}/blob/main/src/{filename}"
25 changes: 25 additions & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Dragonfly Mainframe
==================

The Mainframe for Dragonfly

Module Index
------------

.. toctree::
:maxdepth: 1

autoapi/index

.. toctree::
:caption: Other:
:hidden:

changelog

Extras
------

* :ref:`genindex`
* :ref:`search`
* :doc:`changelog`
Loading

0 comments on commit b2b7fa6

Please sign in to comment.