Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 8 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[flake8]
exclude = venv, doc/_build, src/ansys/api/fluent/v0/*, src/ansys/fluent/core/meshing/tui.py, src/ansys/fluent/core/solver/tui.py, src/ansys/fluent/core/solver/settings/*, src/ansys/fluent/core/datamodel/*
max-line-length = 88
count = True
max-complexity = 10
statistics = True
select = W191 W291 W293 W391 E115 E117 E122 E124 E125 E225 E231 E301 E303 F401 F403 N801 N802 N803 N804 N805 N806
extend-ignore = E203, E501
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ repos:
hooks:
- id: black
args: [
--line-length, "79",
--force-exclude, src/ansys/api/fluent/v0/|src/ansys/fluent/core/meshing/tui.py|src/ansys/fluent/core/solver/tui.py|src/ansys/fluent/core/solver/settings.py|src/ansys/fluent/core/datamodel,
--force-exclude, src/ansys/api/fluent/v0/|src/ansys/fluent/core/meshing/tui.py|src/ansys/fluent/core/solver/tui.py|src/ansys/fluent/core/solver/settings/|src/ansys/fluent/core/datamodel,
src/ansys, codegen, doc, examples, tests
]

Expand All @@ -25,11 +24,11 @@ repos:
--profile, black,
--skip, src/ansys/fluent/core/meshing/tui.py,
--skip, src/ansys/fluent/core/solver/tui.py,
--skip, src/ansys/fluent/core/solver/settings.py,
--skip-glob, src/ansys/api/fluent/v0/*,
--skip-glob, src/ansys/fluent/core/datamodel/*,
--skip-glob, src/ansys/fluent/core/solver/settings/*,
--force-sort-within-sections,
--line-length, "79",
--line-length, "88",
--section-default, THIRDPARTY,
--filter-files,
--project, ansys,
Expand All @@ -50,7 +49,8 @@ repos:
--count,
--statistics,
--max-complexity, "10",
--max-line-length, "79",
--max-line-length, "88",
--extend-ignore, E203 E501,
ansys, codegen, doc, examples, tests
]

Expand Down
33 changes: 8 additions & 25 deletions codegen/datamodelgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ def _build_parameter_docstring(name: str, t: str):

def _build_command_docstring(name: str, info: Any):
return_type = _PY_TYPE_BY_DM_TYPE[info.returntype]
arg_strings = [
arg.name + ": " + _PY_TYPE_BY_DM_TYPE[arg.type] for arg in info.args
]
arg_strings = [arg.name + ": " + _PY_TYPE_BY_DM_TYPE[arg.type] for arg in info.args]
arg_string = ", ".join(arg_strings)
return name + "(" + arg_string + ") -> " + return_type

Expand Down Expand Up @@ -72,9 +70,7 @@ def __init__(self):
"workflow": DataModelStaticInfo("workflow", "meshing"),
"meshing": DataModelStaticInfo("meshing", "meshing"),
"PartManagement": DataModelStaticInfo("PartManagement", "meshing"),
"PMFileManagement": DataModelStaticInfo(
"PMFileManagement", "meshing"
),
"PMFileManagement": DataModelStaticInfo("PMFileManagement", "meshing"),
}
self._delete_generated_files()
self._populate_static_info()
Expand All @@ -98,23 +94,17 @@ def _populate_static_info(self):
session = pyfluent.launch_fluent(meshing_mode=True)
for _, info in self._static_info.items():
if info.mode == "meshing":
info.static_info = self._get_static_info(
info.rules, session
)
info.static_info = self._get_static_info(info.rules, session)
session.exit()

if run_solver_mode:
session = pyfluent.launch_fluent()
for _, info in self._static_info.items():
if info.mode == "solver":
info.static_info = self._get_static_info(
info.rules, session
)
info.static_info = self._get_static_info(info.rules, session)
session.exit()

def _write_static_info(
self, name: str, info: Any, f: FileIO, level: int = 0
):
def _write_static_info(self, name: str, info: Any, f: FileIO, level: int = 0):
indent = " " * level * 4
f.write(f"{indent}class {name}(PyMenu):\n")
f.write(f'{indent} """\n')
Expand Down Expand Up @@ -144,14 +134,9 @@ def _write_static_info(
f.write(f"{indent} super().__init__(service, rules, path)\n\n")
for k in info.namedobjects:
f.write(f"{indent} class {k}(PyNamedObjectContainer):\n")
self._write_static_info(
f"_{k}", info.namedobjects[k], f, level + 2
)
self._write_static_info(f"_{k}", info.namedobjects[k], f, level + 2)
# Specify the concrete named object type for __getitem__
f.write(
f"{indent} def __getitem__(self, key: str) -> "
f"_{k}:\n"
)
f.write(f"{indent} def __getitem__(self, key: str) -> " f"_{k}:\n")
f.write(f"{indent} return super().__getitem__(key)\n\n")
for k in info.singletons:
self._write_static_info(k, info.singletons[k], f, level + 1)
Expand Down Expand Up @@ -182,9 +167,7 @@ def write_static_info(self) -> None:
f.write("# This is an auto-generated file. DO NOT EDIT!\n")
f.write("#\n")
f.write("# pylint: disable=line-too-long\n\n")
f.write(
"from ansys.fluent.core.services.datamodel_se import (\n"
)
f.write("from ansys.fluent.core.services.datamodel_se import (\n")
f.write(" PyMenu,\n")
f.write(" PyNamedObjectContainer,\n")
f.write(" PyCommand\n")
Expand Down
4 changes: 1 addition & 3 deletions codegen/pyprotogen.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ def build_python_grpc(
proto_glob = os.path.join(protos_path, "*.proto")
files = glob.glob(proto_glob, recursive=True)
if not files:
raise FileNotFoundError(
f"Unable locate any *.proto files at {protos_path}"
)
raise FileNotFoundError(f"Unable locate any *.proto files at {protos_path}")

shutil.rmtree(out_path, ignore_errors=True)
Path.mkdir(Path(out_path), parents=True, exist_ok=True)
Expand Down
40 changes: 10 additions & 30 deletions codegen/settingsgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@ def _populate_hash_dict(name, info, cls):
for child in getattr(cls, "child_names", None):
child_cls = getattr(cls, child)
if cname == child_cls.fluent_name:
children_hash.append(
_populate_hash_dict(cname, cinfo, child_cls)
)
children_hash.append(_populate_hash_dict(cname, cinfo, child_cls))
break
else:
children_hash = None
Expand All @@ -69,9 +67,7 @@ def _populate_hash_dict(name, info, cls):
for command in getattr(cls, "command_names", None):
command_cls = getattr(cls, command)
if cname == command_cls.fluent_name:
commands_hash.append(
_populate_hash_dict(cname, cinfo, command_cls)
)
commands_hash.append(_populate_hash_dict(cname, cinfo, command_cls))
break
else:
commands_hash = None
Expand Down Expand Up @@ -176,9 +172,7 @@ def _populate_classes(parent_dir):
) in hash_dict.items():
file_name = files_dict.get(key)
cls_name = cls.__name__
filepath = os.path.normpath(
os.path.join(parent_dir, file_name + ".py")
)
filepath = os.path.normpath(os.path.join(parent_dir, file_name + ".py"))
with open(filepath, "w") as f:
# disclaimer to py file
f.write("#\n")
Expand All @@ -191,29 +185,21 @@ def _populate_classes(parent_dir):
if children_hash:
for child in children_hash:
pchild_name = hash_dict.get(child)[0].__name__
f.write(
f"from .{files_dict.get(child)} import {pchild_name}\n"
)
f.write(f"from .{files_dict.get(child)} import {pchild_name}\n")

if commands_hash:
for child in commands_hash:
pchild_name = hash_dict.get(child)[0].__name__
f.write(
f"from .{files_dict.get(child)} import {pchild_name}\n"
)
f.write(f"from .{files_dict.get(child)} import {pchild_name}\n")

if arguments_hash:
for child in arguments_hash:
pchild_name = hash_dict.get(child)[0].__name__
f.write(
f"from .{files_dict.get(child)} import {pchild_name}\n"
)
f.write(f"from .{files_dict.get(child)} import {pchild_name}\n")

if object_hash:
pchild_name = hash_dict.get(object_hash)[0].__name__
f.write(
f"from .{files_dict.get(object_hash)} import {pchild_name}\n\n"
)
f.write(f"from .{files_dict.get(object_hash)} import {pchild_name}\n\n")

# class name
f.write(
Expand All @@ -237,9 +223,7 @@ def _populate_classes(parent_dir):
if child_names:
f.write(f"{istr1}child_names = \\\n")
strout = io.StringIO()
pprint.pprint(
child_names, stream=strout, compact=True, width=70
)
pprint.pprint(child_names, stream=strout, compact=True, width=70)
mn = ("\n" + istr2).join(strout.getvalue().strip().split("\n"))
f.write(f"{istr2}{mn}\n\n")

Expand All @@ -254,9 +238,7 @@ def _populate_classes(parent_dir):
if command_names:
f.write(f"{istr1}command_names = \\\n")
strout = io.StringIO()
pprint.pprint(
command_names, stream=strout, compact=True, width=70
)
pprint.pprint(command_names, stream=strout, compact=True, width=70)
mn = ("\n" + istr2).join(strout.getvalue().strip().split("\n"))
f.write(f"{istr2}{mn}\n\n")

Expand Down Expand Up @@ -284,9 +266,7 @@ def _populate_classes(parent_dir):
# write object type
child_object_type = getattr(cls, "child_object_type", None)
if child_object_type:
f.write(
f"{istr1}child_object_type: {pchild_name} = {pchild_name}\n"
)
f.write(f"{istr1}child_object_type: {pchild_name} = {pchild_name}\n")
f.write(f'{istr1}"""\n')
f.write(f"{istr1}child_object_type of {cls_name}.")
f.write(f'\n{istr1}"""\n')
Expand Down
24 changes: 6 additions & 18 deletions codegen/tuigen.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ def _populate_xml_helpstrings():
tree = ET.parse(_XML_HELP_FILE)
root = tree.getroot()
help_contents_node = root.find(".//*[@id='flu_tui_help_contents']")
field_help_node = help_contents_node.find(
".//*[@id='fluent_tui_field_help']"
)
field_help_node = help_contents_node.find(".//*[@id='fluent_tui_field_help']")

for node in field_help_node.findall("sect2"):
k = node.find("h3").text
Expand Down Expand Up @@ -150,9 +148,7 @@ def _write_menu_to_tui_file(self, menu: _TUIMenu, indent: int = 0):
for line in doc_lines:
self._write_code_to_tui_file(f"{line}\n", indent)
self._write_code_to_tui_file('"""\n', indent)
self._write_code_to_tui_file(
"def __init__(self, path, service):\n", indent
)
self._write_code_to_tui_file("def __init__(self, path, service):\n", indent)
indent += 1
self._write_code_to_tui_file("self.path = path\n", indent)
self._write_code_to_tui_file("self.service = service\n", indent)
Expand All @@ -163,14 +159,10 @@ def _write_menu_to_tui_file(self, menu: _TUIMenu, indent: int = 0):
f'(path + [("{v.tui_name}", None)], service)\n',
indent,
)
self._write_code_to_tui_file(
"super().__init__(path, service)\n", indent
)
self._write_code_to_tui_file("super().__init__(path, service)\n", indent)
indent -= 1

command_names = [
v.name for _, v in menu.children.items() if v.is_command
]
command_names = [v.name for _, v in menu.children.items() if v.is_command]
if command_names:
for command in command_names:
self._write_code_to_tui_file(
Expand All @@ -197,14 +189,10 @@ def generate(self) -> None:
with open(self._tui_file, "w", encoding="utf8") as self.__writer:
self._populate_menu(self._main_menu)
if self._tui_file == _SOLVER_TUI_FILE:
self._write_code_to_tui_file(
'"""Fluent Solver TUI Commands"""\n'
)
self._write_code_to_tui_file('"""Fluent Solver TUI Commands"""\n')
self._main_menu.doc = "Fluent solver main menu."
else:
self._write_code_to_tui_file(
'"""Fluent Meshing TUI Commands"""\n'
)
self._write_code_to_tui_file('"""Fluent Meshing TUI Commands"""\n')
self._main_menu.doc = "Fluent meshing main menu."
self._write_code_to_tui_file(
"#\n"
Expand Down
48 changes: 14 additions & 34 deletions doc/settings_rstgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,18 +116,14 @@ def _populate_rst_from_settings(rst_dir, cls):
rstpath = os.path.normpath(os.path.join(rst_dir, file_name + ".rst"))
has_children = hasattr(cls, "child_names") and len(cls.child_names) > 0
has_commands = hasattr(cls, "command_names") and len(cls.command_names) > 0
has_arguments = (
hasattr(cls, "argument_names") and len(cls.argument_names) > 0
)
has_arguments = hasattr(cls, "argument_names") and len(cls.argument_names) > 0
has_named_object = hasattr(cls, "child_object_type")
with open(rstpath, "w") as r:
# Populate initial rst
r.write(f".. _{file_name}:\n\n")
r.write(f"{cls_name}\n")
r.write(f'{"="*(len(cls_name))}\n\n')
r.write(
f".. currentmodule:: ansys.fluent.core.solver.settings.{file_name}\n\n"
)
r.write(f".. currentmodule:: ansys.fluent.core.solver.settings.{file_name}\n\n")
r.write(f".. autoclass:: {cls_name}\n")
r.write(f"{istr1}:show-inheritance:\n")
r.write(f"{istr1}:undoc-members:\n")
Expand All @@ -147,12 +143,8 @@ def _populate_rst_from_settings(rst_dir, cls):
data_dict["Child"] = "Summary"
for child in cls.child_names:
child_cls = getattr(cls, child)
ref_string = (
f":ref:`{child} <{child_cls.__module__.split('.')[-1]}>`"
)
data_dict[ref_string] = child_cls.__doc__.strip("\n").split(
"\n"
)[0]
ref_string = f":ref:`{child} <{child_cls.__module__.split('.')[-1]}>`"
data_dict[ref_string] = child_cls.__doc__.strip("\n").split("\n")[0]
_generate_table_for_rst(r, data_dict)

if has_commands:
Expand All @@ -161,12 +153,8 @@ def _populate_rst_from_settings(rst_dir, cls):
data_dict["Command"] = "Summary"
for child in cls.command_names:
child_cls = getattr(cls, child)
ref_string = (
f":ref:`{child} <{child_cls.__module__.split('.')[-1]}>`"
)
data_dict[ref_string] = child_cls.__doc__.strip("\n").split(
"\n"
)[0]
ref_string = f":ref:`{child} <{child_cls.__module__.split('.')[-1]}>`"
data_dict[ref_string] = child_cls.__doc__.strip("\n").split("\n")[0]
_generate_table_for_rst(r, data_dict)

if has_arguments:
Expand All @@ -175,21 +163,17 @@ def _populate_rst_from_settings(rst_dir, cls):
data_dict["Argument"] = "Summary"
for child in cls.argument_names:
child_cls = getattr(cls, child)
ref_string = (
f":ref:`{child} <{child_cls.__module__.split('.')[-1]}>`"
)
data_dict[ref_string] = child_cls.__doc__.strip("\n").split(
"\n"
)[0]
ref_string = f":ref:`{child} <{child_cls.__module__.split('.')[-1]}>`"
data_dict[ref_string] = child_cls.__doc__.strip("\n").split("\n")[0]
_generate_table_for_rst(r, data_dict)

if has_named_object:
child_cls = getattr(cls, "child_object_type")
ref_string = f":ref:`{child_cls.__name__} <{child_cls.__module__.split('.')[-1]}>`"
ref_string = (
f":ref:`{child_cls.__name__} <{child_cls.__module__.split('.')[-1]}>`"
)
data_dict = {}
data_dict[ref_string] = child_cls.__doc__.strip("\n").split("\n")[
0
]
data_dict[ref_string] = child_cls.__doc__.strip("\n").split("\n")[0]
r.write(f".. rubric:: Named object type\n\n")
r.write(f"{ref_string}\n\n\n")

Expand All @@ -200,9 +184,7 @@ def _populate_rst_from_settings(rst_dir, cls):
for parent in parents_dict.get(file_name):
parent_file = parent.__module__.split(".")[-1]
ref_string = f":ref:`{parent.__name__} <{parent_file}>`"
data_dict[ref_string] = parent.__doc__.strip("\n").split("\n")[
0
]
data_dict[ref_string] = parent.__doc__.strip("\n").split("\n")[0]
_generate_table_for_rst(r, data_dict)

if not rstpath in rst_list:
Expand All @@ -220,9 +202,7 @@ def _populate_rst_from_settings(rst_dir, cls):
_populate_rst_from_settings(rst_dir, getattr(cls, child))

if has_named_object:
_populate_rst_from_settings(
rst_dir, getattr(cls, "child_object_type")
)
_populate_rst_from_settings(rst_dir, getattr(cls, "child_object_type"))


if __name__ == "__main__":
Expand Down
4 changes: 1 addition & 3 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@
pyvista.rcParams["window_size"] = np.array([1024, 768])

# Save figures in specified directory
pyvista.FIGURE_PATH = os.path.join(
os.path.abspath("./images/"), "auto-generated/"
)
pyvista.FIGURE_PATH = os.path.join(os.path.abspath("./images/"), "auto-generated/")
if not os.path.exists(pyvista.FIGURE_PATH):
os.makedirs(pyvista.FIGURE_PATH)

Expand Down
Loading