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

POC of using sphinx + pydantic #614

Closed
wants to merge 1 commit into from
Closed
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
13 changes: 13 additions & 0 deletions scripts/generate_sphix_docs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import subprocess;
from pathlib import Path
import os

try:
import sphinxcontrib.autodoc_pydantic # type: ignore
except ImportError as e:
import sys
print("You need to install 'autodoc_pydantic'. Try running \npip install autodoc_pydantic", file=sys.stdout)
exit(1)

os.chdir(Path(__file__).parent.parent)
_ = subprocess.run(["sphinx-build", "-M", "html", "sphinx_docs/source", "sphinx_docs/build/"])
20 changes: 20 additions & 0 deletions sphinx_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 sphinx_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
32 changes: 32 additions & 0 deletions sphinx_docs/source/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# 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 = 'bioimage-spec'
copyright = '2024, Fynn B., Tomaz V.'
author = 'Fynn B., Tomaz V.'

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

extensions = [
'sphinx.ext.duration',
'sphinx.ext.doctest',
'sphinx.ext.autodoc',
'sphinxcontrib.autodoc_pydantic',
]

templates_path = ['_templates']
exclude_patterns = []



# -- 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']
34 changes: 34 additions & 0 deletions sphinx_docs/source/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
.. bioimage-spec documentation master file, created by
sphinx-quickstart on Thu Jun 13 14:39:20 2024.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.

Welcome to bioimage-spec's documentation!
=========================================

Check out the :doc:`usage` section for further information.


This is an exmaple of embedding the documentation for a particular pydantic model into a Sphix document:

.. autopydantic_model:: bioimageio.spec.model.v0_5.DataDependentSize
:model-show-json: True
:model-show-config-summary: False

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

Contents
--------

.. toctree::

usage

Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
11 changes: 11 additions & 0 deletions sphinx_docs/source/usage.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Usage
=====

Installation
------------

To use bioimg core, install it with conda:

.. code-block:: console

(.venv) $ conda install bla
Loading