Skip to content

Commit

Permalink
Added readthedocs documentation support (#339)
Browse files Browse the repository at this point in the history
* readthedocs config added

* index.rst change

* a

* a

* rst files

* a

* a

* all

* all

* all

* all

* all

* all

* all

* all

* all

* readthedocs configured

* reformatting using black

* mypy updates

* mypy updates

* doc update

* doc update

* doc update

* doc update

* doc update

* doc update

* doc update

* doc updates

* doc updatess

* doc updates

* doc updates

* doc updates

* black changes

* conf update

* path updates to conf.py

* module updates

* conf update
  • Loading branch information
rakesh9177 authored Jan 8, 2024
1 parent f6606be commit e91e0c5
Show file tree
Hide file tree
Showing 103 changed files with 2,844 additions and 39 deletions.
13 changes: 13 additions & 0 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: "2"

build:
os: "ubuntu-22.04"
tools:
python: "3.10"

python:
install:
- requirements: docs/requirements.txt

sphinx:
configuration: docs/source/conf.py
20 changes: 20 additions & 0 deletions 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)
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 = .
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=.
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
4 changes: 4 additions & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sphinx==7.1.2
sphinx-rtd-theme==1.3.0rc1
m2r2

186 changes: 186 additions & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
# Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# http://www.sphinx-doc.org/en/master/config

# -- Path setup --------------------------------------------------------------

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
import os
import sys

sys.path.insert(0, os.path.abspath(os.path.join("..", "..")))


# -- Project information -----------------------------------------------------


# Take from setup.py file
def grep_value_from_setup(key: str) -> str:
import re

setup_file = os.path.normpath(
os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "..", "setup.py")
)
with open(setup_file, "r") as setup_file:
for line in setup_file.readlines():
value = re.search(".*{key}=(.*),*".format(key=key), line)
if value:
value = value.group(1)
value = re.sub(r"^\W+", "", value) # lstrip non alphanumeric
value = re.sub(r"\W+$", "", value) # rstrip non alphanumeric
return value


project = grep_value_from_setup("name")
copyright = "2023"
author = grep_value_from_setup("author")

# The full version, including alpha/beta/rc tags

release = "latest"


# -- General configuration ---------------------------------------------------

# 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.doctest",
"sphinx.ext.coverage",
"sphinx.ext.viewcode",
"sphinx.ext.intersphinx", # link to other documentations
# 'nbsphinx', # work with jupyter notebook. requires pip install nbsphinx
# 'sphinx.ext.mathjax', # required for math in Jupyter Notebook
"m2r2", # work with markdown files. requires pip install m2r2
"sphinx.ext.napoleon", # parse Google/numpy docstring
# 'sphinx.ext.autosummary', # Automated index.rst toctreee
]

# autosummary_generate = True # create api docs with autosummary


intersphinx_mapping = {
"numpy": ("http://docs.scipy.org/doc/numpy/", None),
"scipy": ("http://docs.scipy.org/doc/scipy/reference/", None),
"pandas": ("https://pandas.pydata.org/pandas-docs/stable/", None),
"python": ("https://docs.python.org/{}.{}".format(*sys.version_info), None),
}

autoclass_content = "both"

numpydoc_show_class_members = False # Suppress sphinx warnings when building numpy-doc

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

# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
source_suffix = {
".rst": "restructuredtext",
".txt": "restructuredtext",
".md": "markdown",
}

# 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 = [
"*estimation.*_.rst", # estimation old files which kept locally
"*tests.*", # remove tests from documentation
]

# https://www.sphinx-doc.org/en/master/usage/configuration.html?highlight=master_doc#confval-master_doc
master_doc = "index" # what file includes the root toctree. Needed explicitly for readthedocs.org


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

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
on_rtd = os.environ.get("READTHEDOCS") == "True"
if on_rtd:
html_theme = "sphinx_rtd_theme"
else:
html_theme = "classic"

# 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 = ["_static"]

# # Add content to the navigation side bar:
html_sidebars = {
"**": ["localtoc.html", "sourcelink.html", "searchbox.html", "globaltoc.html"]
}


# -- Custom scripts -------------------------------------------------


# Add module's README for each module HTML page
def add_modules_readme() -> str:
def get_rst_file_name_from_package_source(package_source_path: str) -> str:
rst_source_path = os.path.relpath(package_source_path, os.getcwd())
rst_file_name = rst_source_path.split(os.sep)
rst_file_name = [
directory for directory in rst_file_name if not directory.startswith(".")
]
rst_file_name += ["rst"]
rst_file_name = ".".join(rst_file_name)
rst_file_name = os.path.join(source_html_dir, rst_file_name)
return rst_file_name

def get_edited_rast_file(
rst_source_path: str, include_text: str, remove_original_header: bool = True
) -> str:
with open(rst_source_path, "r") as fh:
rst_source_lines = fh.read().splitlines()
if not any([include_text in line for line in rst_source_lines]):
# Add link to readme only if not already exists
rst_source_lines.insert(3, include_text)
if remove_original_header:
rst_source_lines = rst_source_lines[2:] # remove existing header

return rst_source_lines

INCLUDE_TEXT = ".. mdinclude:: "

README_FILE_NAME = "README.md"

# source_code_dir = os.path.join("..", "..", "fuse-med-ml")
source_html_dir = os.getcwd() + "/docs/source/" # sphinx's docs source directory

for dir_name, subdir_list, file_names in os.walk(os.getcwd()):
if README_FILE_NAME in file_names: # Current dir has a readme file
# Get README file path:
# source_path = os.path.relpath(dir_name, os.path.join(source_code_dir, ".."))
source_path = os.path.normpath(dir_name)

readme_file_path = os.path.join(source_path, README_FILE_NAME)

# Construct the corresponding module rst file:
rst_source_file = get_rst_file_name_from_package_source(source_path)

# Edit the rst file to include the path to the readme:
path_to_be_added = os.path.relpath(readme_file_path, os.getcwd())

try:
include_text = INCLUDE_TEXT + "../../" + path_to_be_added + "\n"
content = get_edited_rast_file(rst_source_file, include_text, True)

with open(rst_source_file, "w") as f:
for line in content:
f.write("{}\n".format(line))

except FileNotFoundError:
print("Could not find file {}".format(rst_source_file))


add_modules_readme()
37 changes: 37 additions & 0 deletions docs/source/fuse.data.datasets.caching.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
fuse.data.datasets.caching package
==================================

Subpackages
-----------

.. toctree::
:maxdepth: 4

fuse.data.datasets.caching.tests

Submodules
----------

fuse.data.datasets.caching.object\_caching\_handlers module
-----------------------------------------------------------

.. automodule:: fuse.data.datasets.caching.object_caching_handlers
:members:
:undoc-members:
:show-inheritance:

fuse.data.datasets.caching.samples\_cacher module
-------------------------------------------------

.. automodule:: fuse.data.datasets.caching.samples_cacher
:members:
:undoc-members:
:show-inheritance:

Module contents
---------------

.. automodule:: fuse.data.datasets.caching
:members:
:undoc-members:
:show-inheritance:
21 changes: 21 additions & 0 deletions docs/source/fuse.data.datasets.caching.tests.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
fuse.data.datasets.caching.tests package
========================================

Submodules
----------

fuse.data.datasets.caching.tests.test\_sample\_caching module
-------------------------------------------------------------

.. automodule:: fuse.data.datasets.caching.tests.test_sample_caching
:members:
:undoc-members:
:show-inheritance:

Module contents
---------------

.. automodule:: fuse.data.datasets.caching.tests
:members:
:undoc-members:
:show-inheritance:
54 changes: 54 additions & 0 deletions docs/source/fuse.data.datasets.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
fuse.data.datasets package
==========================

Subpackages
-----------

.. toctree::
:maxdepth: 4

fuse.data.datasets.caching
fuse.data.datasets.tests

Submodules
----------

fuse.data.datasets.dataset\_base module
---------------------------------------

.. automodule:: fuse.data.datasets.dataset_base
:members:
:undoc-members:
:show-inheritance:

fuse.data.datasets.dataset\_default module
------------------------------------------

.. automodule:: fuse.data.datasets.dataset_default
:members:
:undoc-members:
:show-inheritance:

fuse.data.datasets.dataset\_wrap\_seq\_to\_dict module
------------------------------------------------------

.. automodule:: fuse.data.datasets.dataset_wrap_seq_to_dict
:members:
:undoc-members:
:show-inheritance:

fuse.data.datasets.sample\_caching\_audit module
------------------------------------------------

.. automodule:: fuse.data.datasets.sample_caching_audit
:members:
:undoc-members:
:show-inheritance:

Module contents
---------------

.. automodule:: fuse.data.datasets
:members:
:undoc-members:
:show-inheritance:
Loading

0 comments on commit e91e0c5

Please sign in to comment.