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

Added readthedocs config for documentation #339

Merged
merged 37 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
017e304
readthedocs config added
rakesh9177 Dec 21, 2023
e1173e6
index.rst change
rakesh9177 Dec 21, 2023
370b41f
a
rakesh9177 Dec 21, 2023
a8c0ead
a
rakesh9177 Dec 21, 2023
43ce2c2
rst files
rakesh9177 Dec 21, 2023
0f2829e
a
rakesh9177 Dec 21, 2023
f4772a6
a
rakesh9177 Dec 21, 2023
4fe02e8
all
rakesh9177 Dec 21, 2023
324ff90
all
rakesh9177 Dec 21, 2023
10dfc7a
all
rakesh9177 Dec 21, 2023
ee8fc46
all
rakesh9177 Dec 21, 2023
6f106fc
all
rakesh9177 Dec 21, 2023
4bcb1df
all
rakesh9177 Dec 21, 2023
3ab878f
all
rakesh9177 Dec 21, 2023
30344fe
all
rakesh9177 Dec 21, 2023
1746ff3
all
rakesh9177 Dec 21, 2023
835aaa8
readthedocs configured
rakesh9177 Dec 21, 2023
7d9635c
reformatting using black
rakesh9177 Dec 23, 2023
26984e3
mypy updates
rakesh9177 Dec 26, 2023
6f84b65
mypy updates
rakesh9177 Dec 26, 2023
58e6c2e
doc update
rakesh9177 Dec 26, 2023
9cb9c23
doc update
rakesh9177 Dec 26, 2023
76fb80d
doc update
rakesh9177 Dec 26, 2023
ffa62f6
doc update
rakesh9177 Dec 26, 2023
b783101
doc update
rakesh9177 Dec 26, 2023
d970298
doc update
rakesh9177 Dec 26, 2023
ccc949c
doc update
rakesh9177 Dec 26, 2023
6e194a8
doc updates
rakesh9177 Dec 26, 2023
0065428
doc updatess
rakesh9177 Dec 26, 2023
bbbe59f
doc updates
rakesh9177 Dec 26, 2023
6e5749c
doc updates
rakesh9177 Dec 26, 2023
3157792
doc updates
rakesh9177 Dec 27, 2023
30c7788
black changes
rakesh9177 Dec 28, 2023
80d07d1
conf update
rakesh9177 Dec 31, 2023
8a38065
path updates to conf.py
rakesh9177 Dec 31, 2023
f8f8d79
module updates
rakesh9177 Dec 31, 2023
d62e9bc
conf update
rakesh9177 Jan 1, 2024
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 .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 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_file_name = package_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

# source_code_dir = os.path.join("..", "..", "fuse-med-ml") # causallib source code directory
rakesh9177 marked this conversation as resolved.
Show resolved Hide resolved
source_html_dir = "." # sphinx's docs source directory


"""
rakesh9177 marked this conversation as resolved.
Show resolved Hide resolved
INCLUDE_TEXT = ".. mdinclude:: "
# INCLUDE_TEXT += "../../"

README_FILE_NAME = "README.md"
------
for dir_name, subdir_list, file_names in os.walk(source_code_dir):
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:
try:
include_text = INCLUDE_TEXT + readme_file_path + "\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
Loading