Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Nov 10, 2023
1 parent 221470d commit de238a3
Show file tree
Hide file tree
Showing 5 changed files with 173 additions and 156 deletions.
75 changes: 46 additions & 29 deletions capsul/sphinxext/layoutdocgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@


class LayoutHelperWriter:
""" A basic class to create sphinx layout and associated index.
"""
"""A basic class to create sphinx layout and associated index."""

def __init__(self, module_names, root_module_name, rst_extension=".rst"):
""" Initialize the LayoutHelperWriter class
"""Initialize the LayoutHelperWriter class
Parameters
----------
Expand All @@ -34,10 +34,10 @@ def __init__(self, module_names, root_module_name, rst_extension=".rst"):
self.module_names = module_names
self.rst_extension = rst_extension
self.root_module_name = root_module_name
self.rst_section_levels = ['*', '=', '-', '~', '^']
self.rst_section_levels = ["*", "=", "-", "~", "^"]

def generate_index_entry(self, module_name, indent=4):
""" Make autodoc documentation of pilots
"""Make autodoc documentation of pilots
Parameters
----------
Expand All @@ -58,8 +58,7 @@ def generate_index_entry(self, module_name, indent=4):
except ImportError:
exc_info = sys.exc_info()
logging.error("".join(traceback.format_exception(*exc_info)))
logging.error(
"Can't load module {0}".format(full_module_name))
logging.error("Can't load module {0}".format(full_module_name))
module = sys.modules[full_module_name]
description = module.__doc__

Expand All @@ -71,15 +70,16 @@ def generate_index_entry(self, module_name, indent=4):
ad += spacer + "</a></h2>\n"
ad += spacer + "<blockquote>\n"
if description is not None:
ad += spacer + "{0}\n".format(("\n" + spacer).join(
self.rst2html(description).splitlines()))
ad += spacer + "{0}\n".format(
("\n" + spacer).join(self.rst2html(description).splitlines())
)
ad += spacer + "</blockquote>\n"
ad += spacer + "</div>\n"

return ad

def title_for(self, title):
""" Create a title from a underscore-separated string.
"""Create a title from a underscore-separated string.
Parameters
----------
Expand All @@ -94,7 +94,7 @@ def title_for(self, title):
return title.replace("_", " ").capitalize()

def rst2html(self, rst):
""" Convert a rst formatted string to an html string.
"""Convert a rst formatted string to an html string.
Parameters
----------
Expand Down Expand Up @@ -123,51 +123,63 @@ def write_layout(self, outdir):

# Get the layout template
layout_file = os.path.join(
os.path.dirname(__file__), "resources", "layout.html")
os.path.dirname(__file__), "resources", "layout.html"
)

# Top selection panel
indices = [
"""<li><a href="{{{{ pathto('generated/{0}/index') }}}}">"""
"""{1}</a></li>""".format(x, self.title_for(x))
for x in self.module_names]
for x in self.module_names
]

# Project description
try:
__import__(self.root_module_name)
except ImportError:
exc_info = sys.exc_info()
logging.error("".join(traceback.format_exception(*exc_info)))
logging.error(
"Can't load module {0}".format(self.root_module_name))
logging.error("Can't load module {0}".format(self.root_module_name))
module = sys.modules[self.root_module_name]
release_info = {}
exec(compile(open(os.path.join(module.__path__[0], "info.py"), "rb").read(), os.path.join(module.__path__[0], "info.py"), 'exec'), release_info)
exec(
compile(
open(os.path.join(module.__path__[0], "info.py"), "rb").read(),
os.path.join(module.__path__[0], "info.py"),
"exec",
),
release_info,
)

# Carousel items
carousel_items_path = os.path.join(
module.__path__[0], os.pardir, "doc", "source", "_static",
"carousel")
module.__path__[0], os.pardir, "doc", "source", "_static", "carousel"
)
carousel_items = [item for item in os.listdir(carousel_items_path)]
images = []
indicators = []
for cnt, item in enumerate(carousel_items):
if cnt == 0:
indicators.append(
"<li data-target='#examples_carousel' data-slide-to='0' "
"class='active'></li>")
"class='active'></li>"
)
images.append(
"<div class=\"active item\">"
'<div class="active item">'
"<a href=\"{{pathto('index')}}\">"
"<img src=\"{{ pathto('_static/carousel/%s', 1) }}\">"
"</div></a>" % item)
"</div></a>" % item
)
else:
indicators.append(
"<li data-target='#examples_carousel' data-slide-to='{0}' "
"</li>".format(cnt))
"</li>".format(cnt)
)
images.append(
"<div class=\"item\"><a href=\"{{pathto('index')}}\">"
'<div class="item"><a href="{{pathto(\'index\')}}">'
"<img src=\"{{ pathto('_static/carousel/%s', 1) }}\">"
"</a></div>" % item)
"</a></div>" % item
)

# Create correspondence mapping
layout_info = {
Expand Down Expand Up @@ -211,12 +223,16 @@ def write_installation(self, outdir):

# Get the layout template
layout_file = os.path.join(
os.path.dirname(__file__), "resources", "installation.rst")
os.path.dirname(__file__), "resources", "installation.rst"
)

# Generate title
title = "Installing `{0}`".format(self.root_module_name.upper())
title = [self.rst_section_levels[1] * len(title), title,
self.rst_section_levels[1] * len(title)]
title = [
self.rst_section_levels[1] * len(title),
title,
self.rst_section_levels[1] * len(title),
]

# Create correspondence mapping
layout_info = {
Expand All @@ -243,7 +259,7 @@ def write_installation(self, outdir):
idx.close()

def write_index(self, outdir, froot="index", rst_extension=".rst"):
""" Make a reST API index file from python modules
"""Make a reST API index file from python modules
Parameters
----------
Expand Down Expand Up @@ -271,7 +287,8 @@ def write_index(self, outdir, froot="index", rst_extension=".rst"):
w(".. raw:: html\n\n")
w(" <div class='container-index'>\n\n")
title = "Documentation of the {0} Pipelines\n".format(
self.root_module_name.upper())
self.root_module_name.upper()
)
w(title)
w(self.rst_section_levels[1] * len(title) + "\n\n")

Expand Down
Loading

0 comments on commit de238a3

Please sign in to comment.