Skip to content

Commit

Permalink
docs test
Browse files Browse the repository at this point in the history
  • Loading branch information
yusuke-takase committed Nov 8, 2024
1 parent 3fac86b commit 85aaede
Show file tree
Hide file tree
Showing 42 changed files with 453 additions and 90 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ notebooks/cmb/
.pytest_cache/
tests/__pycache__/
docs/build/
docs/source/_build/
docs/source/_static/
13 changes: 3 additions & 10 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,26 @@
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
import os
import sys
import toml

module_path = os.path.abspath(os.path.join('..','..','sbm'))
print("module_path: ", module_path)
sys.path.insert(0, module_path)
pyproject_path = os.path.abspath(os.path.join('..','..','pyproject.toml'))

with open(pyproject_path, 'r') as f:
pyproject_data = toml.load(f)

project = 'sbm'
copyright = '2024, Yusuke Takase'
author = "Yusuke Takase"
release = pyproject_data['tool']['poetry']['version']

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

templates_path = ['_templates']

extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.autosummary',
'sphinx.ext.viewcode',
'sphinx.ext.napoleon',
'sphinx.ext.intersphinx',
'sphinx.ext.autosectionlabel',
'nbsphinx',
'sphinx.ext.autosectionlabel',
'pydata_sphinx_theme'
]

Expand All @@ -42,9 +35,9 @@
autosectionlabel_prefix_document = True
autoclass_content = "class"

templates_path = ['_templates']
exclude_patterns = []


# -- Options for HTML output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output

Expand Down
117 changes: 117 additions & 0 deletions docs/source/generate_rst.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
import sbm
import inspect
import os

def escape_underscores(name):
return name.replace('_', '\\_')

def is_special_method(name):
return name.startswith('__') and name.endswith('__')

def get_classes_and_methods(module):
classes = inspect.getmembers(module, inspect.isclass)
for class_name, class_obj in classes:
escaped_class_name = escape_underscores(class_name)
class_filename = f"sbm.{class_name}.rst"
with open(class_filename, 'w') as class_file:
class_file.write(f"sbm.{escaped_class_name}\n")
class_file.write("=" * len(f"sbm.{escaped_class_name}") + "\n\n")
class_file.write(f".. currentmodule:: sbm\n\n")
class_file.write(f".. autoclass:: {class_name}\n\n")
class_file.write(f" .. automethod:: __init__\n\n")
class_file.write(f" .. rubric:: Methods\n\n")
class_file.write(f" .. autosummary::\n\n")

methods = inspect.getmembers(class_obj, inspect.isfunction)
for method_name, method_obj in methods:
if is_special_method(method_name):
continue
escaped_method_name = escape_underscores(method_name)
class_file.write(f" ~{class_name}.{method_name}\n")
method_filename = f"sbm.{class_name}.{method_name}.rst"
with open(method_filename, 'w') as method_file:
method_file.write(f"sbm.{escaped_class_name}.{escaped_method_name}\n")
method_file.write("=" * len(f"sbm.{escaped_class_name}.{escaped_method_name}") + "\n\n")
method_file.write(f".. currentmodule:: sbm\n\n")
method_file.write(f".. automethod:: {class_name}.{method_name}\n")

def get_functions(module):
functions = inspect.getmembers(module, inspect.isfunction)
for function_name, function_obj in functions:
if is_special_method(function_name):
continue
escaped_function_name = escape_underscores(function_name)
function_filename = f"sbm.{function_name}.rst"
with open(function_filename, 'w') as function_file:
function_file.write(f"sbm.{escaped_function_name}\n")
function_file.write("=" * len(f"sbm.{escaped_function_name}") + "\n\n")
function_file.write(f".. currentmodule:: sbm\n\n")
function_file.write(f".. autofunction:: {function_name}\n")

def generate_reference_rst(module, output_file):
with open(output_file, 'w') as f:
f.write("API Reference\n")
f.write("=============\n\n")

# Main functions
f.write("Main functions\n")
f.write("--------------\n\n")
f.write(".. toctree::\n")
f.write(".. autosummary::\n")
f.write(" :toctree: generated/\n\n")

functions = inspect.getmembers(module, inspect.isfunction)
for function_name, function_obj in functions:
if not is_special_method(function_name):
f.write(f" sbm.{function_name}\n")
f.write("\n")

# Classes
f.write("Classes\n")
f.write("-------\n\n")
f.write(".. toctree::\n")
f.write(" :maxdepth: 2\n\n")
f.write(".. autosummary::\n")
f.write(" :toctree: generated/\n\n")

classes = inspect.getmembers(module, inspect.isclass)
for class_name, class_obj in classes:
f.write(f" sbm.{class_name}\n")
f.write("\n")

# Methods
f.write("Methods\n")
f.write("-------\n\n")
f.write(".. toctree::\n")
f.write(" :maxdepth: 2\n\n")
f.write(".. autosummary::\n")
f.write(" :toctree: generated/\n")
f.write(" :recursive:\n\n")

for class_name, class_obj in classes:
methods = inspect.getmembers(class_obj, inspect.isfunction)
for method_name, method_obj in methods:
if not is_special_method(method_name):
f.write(f" sbm.{class_name}.{method_name}\n")
f.write("\n")

if __name__ == "__main__":
# Create output directory if it doesn't exist
output_dir = "generated"
if not os.path.exists(output_dir):
os.makedirs(output_dir)

output_file = "reference.rst"
generate_reference_rst(sbm, output_file)
print(f"{output_file} has been generated successfully.")

os.chdir(output_dir)

print("Generating documentation files for sbm module...")

get_classes_and_methods(sbm)
get_functions(sbm)



print("Documentation files generated successfully.")
18 changes: 18 additions & 0 deletions docs/source/generated/sbm.Configlation.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
sbm.Configlation
================

.. currentmodule:: sbm

.. autoclass:: Configlation


.. automethod:: __init__


.. rubric:: Methods

.. autosummary::

~Configlation.__init__


6 changes: 6 additions & 0 deletions docs/source/generated/sbm.Field.conj.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
sbm.Field.conj
==============

.. currentmodule:: sbm

.. automethod:: Field.conj
19 changes: 19 additions & 0 deletions docs/source/generated/sbm.Field.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
sbm.Field
=========

.. currentmodule:: sbm

.. autoclass:: Field


.. automethod:: __init__


.. rubric:: Methods

.. autosummary::

~Field.__init__
~Field.conj


6 changes: 6 additions & 0 deletions docs/source/generated/sbm.ScanFields.create_covmat.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
sbm.ScanFields.create\_covmat
=============================

.. currentmodule:: sbm

.. automethod:: ScanFields.create_covmat
6 changes: 6 additions & 0 deletions docs/source/generated/sbm.ScanFields.generate_noise.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
sbm.ScanFields.generate\_noise
==============================

.. currentmodule:: sbm

.. automethod:: ScanFields.generate_noise
6 changes: 6 additions & 0 deletions docs/source/generated/sbm.ScanFields.generate_noise_pdf.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
sbm.ScanFields.generate\_noise\_pdf
===================================

.. currentmodule:: sbm

.. automethod:: ScanFields.generate_noise_pdf
6 changes: 3 additions & 3 deletions docs/source/generated/sbm.ScanFields.get_xlink.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
sbm.ScanFields.get_xlink
======================
sbm.ScanFields.get\_xlink
=========================

.. currentmodule:: sbm

.. automethod:: ScanFields.get_xlink
.. automethod:: ScanFields.get_xlink
6 changes: 6 additions & 0 deletions docs/source/generated/sbm.ScanFields.initialize.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
sbm.ScanFields.initialize
=========================

.. currentmodule:: sbm

.. automethod:: ScanFields.initialize
6 changes: 6 additions & 0 deletions docs/source/generated/sbm.ScanFields.map_make.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
sbm.ScanFields.map\_make
========================

.. currentmodule:: sbm

.. automethod:: ScanFields.map_make
21 changes: 16 additions & 5 deletions docs/source/generated/sbm.ScanFields.rst
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
sbm.ScanFields
=================
sbm.ScanFields
==============

.. currentmodule:: sbm

.. autoclass:: ScanFields


.. automethod:: __init__


.. rubric:: Methods

.. autosummary::

~ScanFields.__init__
~ScanFields.create_covmat
~ScanFields.generate_noise
~ScanFields.generate_noise_pdf
~ScanFields.get_xlink
~ScanFields.initialize
~ScanFields.load_channel
~ScanFields.load_det
~ScanFields.load_full_FPU
~ScanFields.map_make
~ScanFields.t2b


6 changes: 6 additions & 0 deletions docs/source/generated/sbm.ScanFields.t2b.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
sbm.ScanFields.t2b
==================

.. currentmodule:: sbm

.. automethod:: ScanFields.t2b
6 changes: 6 additions & 0 deletions docs/source/generated/sbm.SignalFields.abs_pointing_field.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
sbm.SignalFields.abs\_pointing\_field
=====================================

.. currentmodule:: sbm

.. automethod:: SignalFields.abs_pointing_field
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
sbm.SignalFields.build\_linear\_system
======================================

.. currentmodule:: sbm

.. automethod:: SignalFields.build_linear_system
6 changes: 6 additions & 0 deletions docs/source/generated/sbm.SignalFields.diff_gain_field.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
sbm.SignalFields.diff\_gain\_field
==================================

.. currentmodule:: sbm

.. automethod:: SignalFields.diff_gain_field
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
sbm.SignalFields.diff\_pointing\_field
======================================

.. currentmodule:: sbm

.. automethod:: SignalFields.diff_pointing_field
6 changes: 6 additions & 0 deletions docs/source/generated/sbm.SignalFields.get_coupled_field.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
sbm.SignalFields.get\_coupled\_field
====================================

.. currentmodule:: sbm

.. automethod:: SignalFields.get_coupled_field
6 changes: 6 additions & 0 deletions docs/source/generated/sbm.SignalFields.get_field.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
sbm.SignalFields.get\_field
===========================

.. currentmodule:: sbm

.. automethod:: SignalFields.get_field
6 changes: 6 additions & 0 deletions docs/source/generated/sbm.SignalFields.hwp_ip_field.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
sbm.SignalFields.hwp\_ip\_field
===============================

.. currentmodule:: sbm

.. automethod:: SignalFields.hwp_ip_field
25 changes: 25 additions & 0 deletions docs/source/generated/sbm.SignalFields.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
sbm.SignalFields
================

.. currentmodule:: sbm

.. autoclass:: SignalFields


.. automethod:: __init__


.. rubric:: Methods

.. autosummary::

~SignalFields.__init__
~SignalFields.abs_pointing_field
~SignalFields.build_linear_system
~SignalFields.diff_gain_field
~SignalFields.diff_pointing_field
~SignalFields.get_coupled_field
~SignalFields.get_field
~SignalFields.hwp_ip_field


Loading

0 comments on commit 85aaede

Please sign in to comment.