-
Notifications
You must be signed in to change notification settings - Fork 3
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
Doc strings. #50
Merged
Merged
Doc strings. #50
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,221 @@ | ||
from enum import IntEnum | ||
from typing import Any, Optional | ||
|
||
from docutils.statemachine import StringList | ||
from sphinx.application import Sphinx | ||
from sphinx.ext.autodoc import ClassDocumenter, bool_option | ||
|
||
|
||
class PostDocumenter(ClassDocumenter): | ||
objtype = "postdoc" | ||
directivetype = ClassDocumenter.objtype | ||
priority = 10 + ClassDocumenter.priority | ||
option_spec = dict(ClassDocumenter.option_spec) | ||
option_spec["hex"] = bool_option | ||
|
||
@classmethod | ||
def can_document_member( | ||
cls, member: Any, membername: str, isattr: bool, parent: Any | ||
) -> bool: | ||
try: | ||
return issubclass(member, IntEnum) | ||
except TypeError: | ||
return False | ||
|
||
def add_directive_header(self, sig: str) -> None: | ||
self.add_line(f".. _post_{self.object.__name__}:", self.get_sourcename()) | ||
self.add_line(" ", self.get_sourcename()) | ||
super().add_directive_header(sig) | ||
self.add_line(" ", self.get_sourcename()) | ||
|
||
def add_content( | ||
self, more_content: Optional[StringList], no_docstring: bool = False | ||
) -> None: | ||
|
||
super().add_content(more_content, no_docstring) | ||
|
||
source_name = self.get_sourcename() | ||
object = self.object | ||
self.add_line("", source_name) | ||
|
||
data_dicts = {} | ||
|
||
def _update(clss, obj_name, parent_name=None, parent_path=None): | ||
if not data_dicts.get(obj_name): | ||
data_dicts[obj_name] = {} | ||
data_dicts[obj_name]["parent"] = parent_name | ||
data_dicts[obj_name]["path"] = ( | ||
parent_path + "_" + obj_name if parent_path else obj_name | ||
) | ||
data_dicts[obj_name]["obj"] = clss | ||
data_dicts[obj_name]["attr"] = {"Member": "Summary"} | ||
data_dicts[obj_name]["cmd"] = {"Command": "Summary"} | ||
data_dicts[obj_name]["include"] = {"Parent": "Summary"} | ||
dic = data_dicts[obj_name] | ||
if parent_path: | ||
dic["include"][ | ||
f":ref:`{parent_name} <post_{parent_path}>`" | ||
] = f"{parent_name}'s child" | ||
|
||
for the_member_name in dir(clss): | ||
if the_member_name.startswith("_"): | ||
continue | ||
cls = getattr(clss, the_member_name) | ||
the_member_value = cls.__doc__.split("\n")[0] | ||
if cls.__class__.__name__ in ( | ||
"PyLocalPropertyMeta", | ||
"PyLocalObjectMeta", | ||
): | ||
if cls.__class__.__name__ == "PyLocalObjectMeta": | ||
dic["attr"][ | ||
f":ref:`{the_member_name} <post_{dic['path']}_{the_member_name}>`" # noqa: E501 | ||
] = the_member_value | ||
else: | ||
dic["attr"][the_member_name] = the_member_value | ||
attrs = getattr(cls, "attributes", None) | ||
if attrs: | ||
for attr in attrs: | ||
dic["attr"][ | ||
f"{the_member_name}.{attr}" | ||
] = f"``{the_member_name}`` {' '.join(attr.split('_'))}." # noqa: E501 | ||
|
||
elif callable(cls): | ||
dic["cmd"][the_member_name] = the_member_value | ||
|
||
for name in dir(clss): | ||
cls = getattr(clss, name) | ||
if cls.__class__.__name__ in ("PyLocalObjectMeta",): | ||
_update(cls, name, obj_name, data_dicts[obj_name]["path"]) | ||
for base_class in clss.__bases__: | ||
_update(base_class, obj_name, parent_name) | ||
|
||
_update(object, object.__name__) | ||
key_max = 0 | ||
val_max = 0 | ||
for obj_name, obj_dic in data_dicts.items(): | ||
o = obj_dic["obj"] | ||
parent = obj_dic["parent"] | ||
for item in ["attr", "cmd", "include"]: | ||
dic = obj_dic[item] | ||
if len(dic) > 1: | ||
key_max = max(key_max, len(max(dic.keys(), key=len))) | ||
val_max = max(val_max, len(max(dic.values(), key=len))) | ||
|
||
for obj_name, obj_dic in data_dicts.items(): | ||
o = obj_dic["obj"] | ||
parent = obj_dic["parent"] | ||
dic = obj_dic["attr"] | ||
if len(dic) > 1: | ||
col_gap = 3 | ||
total = key_max + val_max + col_gap | ||
# Top border | ||
if o != object: | ||
self.add_line(f".. _post_{obj_dic['path']}:", source_name) | ||
self.add_line("", source_name) | ||
self.add_line( | ||
f".. rubric:: {o.__module__}.{o.__qualname__}", source_name | ||
) | ||
self.add_line("", source_name) | ||
# self.add_line( | ||
# f".. autoclass:: {o.__module__}.{o.__qualname__}", source_name | ||
# ) | ||
self.add_line(f".. rubric:: Attributes", source_name) | ||
self.add_line("", source_name) | ||
self.add_line(f'{"="*key_max}{" "*col_gap}{"="*val_max}', source_name) | ||
header = True | ||
for key, value in dic.items(): | ||
if header: | ||
# Write header and border | ||
self.add_line( | ||
f'{key}{" "*(total-len(key)-len(value))}{value}', | ||
source_name, | ||
) | ||
self.add_line( | ||
f'{"="*key_max}{" "*col_gap}{"="*val_max}', source_name | ||
) | ||
header = False | ||
else: | ||
# actual data | ||
self.add_line( | ||
f'{key}{" "*(total-len(key)-len(value))}{value}', | ||
source_name, | ||
) | ||
# Bottom border | ||
self.add_line(f'{"="*key_max}{" "*col_gap}{"="*val_max}', source_name) | ||
self.add_line("", source_name) | ||
|
||
dic = obj_dic["cmd"] | ||
if "update" in dic: | ||
del dic["update"] | ||
if len(dic) > 1: | ||
col_gap = 3 | ||
total = key_max + val_max + col_gap | ||
|
||
self.add_line(f".. rubric:: Commands", source_name) | ||
self.add_line("", source_name) | ||
self.add_line(f'{"="*key_max}{" "*col_gap}{"="*val_max}', source_name) | ||
header = True | ||
for key, value in dic.items(): | ||
if header: | ||
# Write header and border | ||
self.add_line( | ||
f'{key}{" "*(total-len(key)-len(value))}{value}', | ||
source_name, | ||
) | ||
self.add_line( | ||
f'{"="*key_max}{" "*col_gap}{"="*val_max}', source_name | ||
) | ||
header = False | ||
else: | ||
# actual data | ||
self.add_line( | ||
f'{key}{" "*(total-len(key)-len(value))}{value}', | ||
source_name, | ||
) | ||
# Bottom border | ||
self.add_line("", source_name) | ||
self.add_line(f'{"="*key_max}{" "*col_gap}{"="*val_max}', source_name) | ||
self.add_line("", source_name) | ||
self.add_line("", source_name) | ||
|
||
if parent: | ||
dic = obj_dic["include"] | ||
col_gap = 3 | ||
total = key_max + val_max + col_gap | ||
|
||
self.add_line(f".. rubric:: Included in", source_name) | ||
self.add_line(" ", source_name) | ||
self.add_line(f'{"="*key_max}{" "*col_gap}{"="*val_max}', source_name) | ||
self.add_line(" ", source_name) | ||
header = True | ||
for key, value in dic.items(): | ||
if header: | ||
# Write header and border | ||
self.add_line( | ||
f'{key}{" "*(total-len(key)-len(value))}{value}', | ||
source_name, | ||
) | ||
self.add_line( | ||
f'{"="*key_max}{" "*col_gap}{"="*val_max}', source_name | ||
) | ||
header = False | ||
else: | ||
# actual data | ||
self.add_line( | ||
f'{key}{" "*(total-len(key)-len(value))}{value}', | ||
source_name, | ||
) | ||
# Bottom border | ||
self.add_line("", source_name) | ||
self.add_line(f'{"="*key_max}{" "*col_gap}{"="*val_max}', source_name) | ||
self.add_line("", source_name) | ||
self.add_line("", source_name) | ||
|
||
|
||
def setup(app: Sphinx) -> None: | ||
app.setup_extension("sphinx.ext.autodoc") # Require autodoc extension | ||
app.add_autodocumenter(PostDocumenter) | ||
return { | ||
"parallel_read_safe": True, | ||
"parallel_write_safe": True, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{{ fullname | escape | underline}} | ||
|
||
.. currentmodule:: {{ module }} | ||
|
||
.. autoclass:: {{ objname }} | ||
:members: | ||
:inherited-members: | ||
|
||
.. {% block methods %} | ||
.. .. automethod:: __init__ | ||
|
||
.. {% if methods %} | ||
.. .. rubric:: {{ _('Methods') }} | ||
|
||
.. .. autosummary:: | ||
.. {% for item in methods %} | ||
.. ~{{ name }}.{{ item }} | ||
.. {%- endfor %} | ||
.. {% endif %} | ||
.. {% endblock %} | ||
|
||
{% block attributes %} | ||
{% if attributes %} | ||
.. rubric:: {{ _('Attributes') }} | ||
|
||
.. autosummary:: | ||
{% for item in attributes %} | ||
~{{ name }}.{{ item }} | ||
{%- endfor %} | ||
{% endif %} | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
{{ name | escape | underline}} | ||
|
||
.. automodule:: {{ fullname }} | ||
|
||
{% block attributes %} | ||
{% if attributes %} | ||
.. rubric:: {{ _('Module Attributes') }} | ||
|
||
.. autosummary:: | ||
:toctree: | ||
{% for item in attributes %} | ||
{{ item }} | ||
{%- endfor %} | ||
{% endif %} | ||
{% endblock %} | ||
|
||
{% block functions %} | ||
{% if functions %} | ||
.. rubric:: {{ _('Functions') }} | ||
|
||
.. autosummary:: | ||
:toctree: | ||
{% for item in functions %} | ||
{{ item }} | ||
{%- endfor %} | ||
{% endif %} | ||
{% endblock %} | ||
|
||
{% block classes %} | ||
{% if classes %} | ||
.. rubric:: {{ _('Classes') }} | ||
|
||
.. autosummary:: | ||
:toctree: | ||
:template: custom-class.rst | ||
{% for item in classes %} | ||
{{ item }} | ||
{%- endfor %} | ||
{% endif %} | ||
{% endblock %} | ||
|
||
{% block exceptions %} | ||
{% if exceptions %} | ||
.. rubric:: {{ _('Exceptions') }} | ||
|
||
.. autosummary:: | ||
{% for item in exceptions %} | ||
{{ item }} | ||
{%- endfor %} | ||
{% endif %} | ||
{% endblock %} | ||
|
||
{% block modules %} | ||
{% if modules %} | ||
.. rubric:: Modules | ||
|
||
.. autosummary:: | ||
:toctree: | ||
:template: custom-module.rst | ||
:recursive: | ||
{% for item in modules %} | ||
{{ item }} | ||
{%- endfor %} | ||
{% endif %} | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.. _ref_contour: | ||
|
||
Contour | ||
======= | ||
|
||
.. autopostdoc:: ansys.fluent.visualization.pyvista.pyvista_objects.Contour |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
.. _ref_graphics: | ||
|
||
Graphics | ||
======== | ||
|
||
.. autopostdoc:: ansys.fluent.visualization.pyvista.pyvista_objects.Graphics | ||
|
||
In the following example, a Graphics object is instantiated with a Fluent session as its context. The Graphics object is used to create mesh, contour, vector and surface objects. | ||
|
||
.. code-block:: python | ||
|
||
from ansys.fluent.visualization.pyvista import Graphics | ||
graphics_session = Graphics(session) | ||
|
||
#Create object | ||
mesh1 = graphics_session.Meshes["mesh-1"] | ||
contour1 = graphics_session.Contours["contour-1"] | ||
vector1 = graphics_session.Vectors["vector-1"] | ||
surface1 = graphics_session.Surfaces["surface-1"] | ||
|
||
#Delete object | ||
del graphics_session.Contours["contour-1"] | ||
|
||
.. toctree:: | ||
:maxdepth: 2 | ||
:hidden: | ||
|
||
mesh | ||
surface | ||
contour | ||
vector |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@seanpearsonuk Fixed the issue.