Skip to content

Commit 28b6fa5

Browse files
authored
Merge pull request #152 from ArnauMiro/149-update_docs
149 update docs
2 parents e7d4658 + 4dfa2c2 commit 28b6fa5

File tree

7 files changed

+119
-11
lines changed

7 files changed

+119
-11
lines changed

Diff for: docs/source/_ext/module_alias.py

+107
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# This extension will rewrite the modules vmmath and inp_out (at the moment) with their alias
2+
import os
3+
import re
4+
5+
def modify_rst_before_build(app, config):
6+
rst_dir = os.path.join(app.confdir, 'api')
7+
8+
# Mapping of actual module names to desired documentation names
9+
module_aliases = {
10+
'pyLOM.vmmath': 'pyLOM.math',
11+
'pyLOM.inp_out': 'pyLOM.io'
12+
}
13+
14+
try:
15+
for filename in os.listdir(rst_dir):
16+
if filename.endswith('.rst'):
17+
filepath = os.path.join(rst_dir, filename)
18+
19+
# Check if this file needs to be renamed
20+
for original, alias in module_aliases.items():
21+
if filename == f"{original}.rst":
22+
# Rename the file
23+
new_filepath = os.path.join(rst_dir, f"{alias}.rst")
24+
os.rename(filepath, new_filepath)
25+
filepath = new_filepath
26+
break
27+
28+
with open(filepath, 'r') as f:
29+
content = f.read()
30+
31+
# Replace module names in the content
32+
for original, alias in module_aliases.items():
33+
# Replace module name in automodule directive
34+
content = re.sub(
35+
rf'(.. automodule:: ){original}(\n)',
36+
fr'\1{alias}\2',
37+
content
38+
)
39+
40+
# Replace all occurrences of the original module name
41+
content = content.replace(original, alias)
42+
43+
# Replace module name in headings and other references
44+
content = content.replace(
45+
f"{original.split('.')[-1]}",
46+
f"{alias.split('.')[-1]}"
47+
)
48+
content = content.replace(
49+
f"module {original}",
50+
f"module {alias}"
51+
)
52+
53+
with open(filepath, 'w') as f:
54+
f.write(content)
55+
56+
except Exception as e:
57+
print(f"Error modifying RST files: {e}")
58+
59+
def modify_html_files(app, exception):
60+
if exception is not None:
61+
return
62+
63+
# Mapping of actual module names to desired documentation names
64+
module_aliases = {
65+
'pyLOM.vmmath': 'pyLOM.math',
66+
'pyLOM.inp_out': 'pyLOM.io'
67+
}
68+
69+
# Directory where HTML files are generated
70+
html_dir = os.path.join(app.outdir)
71+
72+
try:
73+
for root, dirs, files in os.walk(html_dir):
74+
for filename in files:
75+
if filename.endswith('.html'):
76+
filepath = os.path.join(root, filename)
77+
78+
with open(filepath, 'r', encoding='utf-8') as f:
79+
content = f.read()
80+
81+
modified = False
82+
83+
# Replace module names in the content
84+
for original, alias in module_aliases.items():
85+
if original in content:
86+
content = content.replace(original, alias)
87+
modified = True
88+
89+
# Write back if modified
90+
if modified:
91+
with open(filepath, 'w', encoding='utf-8') as f:
92+
f.write(content)
93+
except Exception as e:
94+
print(f"Error modifying HTML files: {e}")
95+
96+
def setup(app):
97+
# Connect to the config-inited event to modify RST files before build
98+
app.connect('config-inited', modify_rst_before_build)
99+
100+
# Connect to the build-finished event to modify HTML files
101+
app.connect('build-finished', modify_html_files)
102+
103+
return {
104+
'version': '0.1',
105+
'parallel_read_safe': True,
106+
'parallel_write_safe': True,
107+
}

Diff for: docs/source/api/pyLOM.inp_out.rst renamed to docs/source/api/pyLOM.io.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ pyLOM.inp\_out
44
Module contents
55
---------------
66

7-
.. automodule:: pyLOM.inp_out
7+
.. automodule:: pyLOM.io
88
:members:
99
:undoc-members:
1010
:show-inheritance:
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
pyLOM.vmmath
1+
pyLOM.math
22
============
33

44
Module contents
55
---------------
66

7-
.. automodule:: pyLOM.vmmath
7+
.. automodule:: pyLOM.math
88
:members:
99
:undoc-members:
1010
:show-inheritance:

Diff for: docs/source/api/pyLOM.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ Subpackages
1414
pyLOM.NN
1515
pyLOM.POD
1616
pyLOM.SPOD
17-
pyLOM.inp_out
17+
pyLOM.io
1818
pyLOM.utils
19-
pyLOM.vmmath
19+
pyLOM.math
2020

2121
Module contents
2222
---------------

Diff for: docs/source/conf.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,28 @@
22
import os
33
import sys
44
sys.path.insert(0, os.path.abspath('../..'))
5-
# import pyLOM
5+
sys.path.insert(0, os.path.abspath('_ext'))
6+
import pyLOM
67
# -- Project information -----------------------------------------------------
78
project = 'pyLOM'
89
copyright = '2023-2025'
910
author = 'pyLOM developers'
10-
# TODO: ask to add pyLOM.__version__ to avoid this hardcoded variable
11-
version = '2.1.0' # pyLOM.__version__ is not defined
11+
version = pyLOM.__version__
1212

1313
# -- General configuration ---------------------------------------------------
1414
extensions = [
1515
'sphinx.ext.duration',
1616
'sphinx.ext.doctest',
1717
'sphinx.ext.autodoc',
18+
'module_alias',
1819
'sphinx.ext.autosummary',
1920
'sphinx.ext.napoleon',
2021
'sphinx.ext.viewcode',
2122
'sphinx.ext.intersphinx',
2223
'sphinx_copybutton',
2324
'sphinx.ext.mathjax',
2425
'sphinx_design',
25-
'nbsphinx'
26+
'nbsphinx',
2627
]
2728

2829
# Set the default syntax highlighter

Diff for: docs/source/installation/installation_pypi.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ A GPU-supported version of the tool can be installed directly from PyPI using th
2121
Note that the ``cuda12x`` can be exchanged by:
2222

2323
- ``cuda``: Triggers the non-compiled version of ``cupy`` so that it builds specifically for your system.
24-
- ``rocm-4-0``: Deploys a version of ``cupy`` tailored for AMD GPUs using ROCM.
24+
- ``rocm-4-0``: in order to deploy a version of ``cupy`` tailored for AMD GPUs using ROCM. ROCM is still experimental. Please be aware that the CUDA/ROCM version should match the ones in your system.
2525

2626
Optional Modules
2727
----------------

Diff for: docs/source/notebook_examples/NN/KAN_training.ipynb

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"cell_type": "markdown",
55
"metadata": {},
66
"source": [
7-
"# How to train an MLP using the Pipeline"
7+
"# How to train an KAN using the Pipeline"
88
]
99
},
1010
{

0 commit comments

Comments
 (0)