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
38,265 changes: 0 additions & 38,265 deletions codegen/data/fluent_gui_help.xml

This file was deleted.

3 changes: 3 additions & 0 deletions codegen/data/fluent_gui_help_patch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
XML_HELP_PATCH = {
"flu_meshing_file_start_transcript": "Starts recording input and output in a file. A transcript file contains a complete record of all standard input to and output from Fluent (usually all keyboard and user interface input and all screen output).Start the transcription process with the file/start-transcript command, and end it with the file/stop-transcript command (or by exiting the program)."
Copy link
Contributor Author

@mkundu1 mkundu1 Jun 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This id has problematic docstring in the xml file, this is the clean version.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, so that's why you had modified it before. Maybe Stephen can clean this up.

}
16 changes: 16 additions & 0 deletions codegen/data/tui_menu_descriptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
MENU_DESCRIPTIONS = {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add custom descriptions here.

"solver.tui": """The PyFluent solver text user interface (TUI) API is provided to command the
Fluent solver using commands that are Pythonic versions of the TUI commands used
in the Fluent console. Much like Fluent's TUI the API provides a hierarchical
interface to the underlying procedural interface of the program.

The solver TUI API does not support Fluent TUI features such as aliases or
command abbreviation. As an alternative, using this API in an interactive
session is easier if you install a tool such as
`pyreadline3 <https://github.com/pyreadline3/pyreadline3>`_ which provides
both command line completion and history. You can also use Python standard
`help` and `dir` commands on any object in the API to inspect it further.

The TUI based examples in our gallery provide a guide for how to use this API.
"""
}
69 changes: 49 additions & 20 deletions codegen/tuigen.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,26 @@

import os
from pathlib import Path
import platform
import shutil
import string
import subprocess
from typing import Iterable
import xml.etree.ElementTree as ET

from data.fluent_gui_help_patch import XML_HELP_PATCH
from data.tui_menu_descriptions import MENU_DESCRIPTIONS

import ansys.fluent.core as pyfluent
from ansys.fluent.core import LOG
from ansys.fluent.core.launcher.launcher import FLUENT_VERSION, get_fluent_path
from ansys.fluent.core.services.datamodel_tui import (
DatamodelService,
PyMenu,
convert_path_to_grpc_path,
convert_tui_menu_to_func_name,
)
import docker

_THIS_DIRNAME = os.path.dirname(__file__)
_MESHING_TUI_FILE = os.path.normpath(
Expand Down Expand Up @@ -79,43 +87,63 @@
)
)

menu_descriptions = {
"solver.tui": """The PyFluent solver text user interface (TUI) API is provided to command the
Fluent solver using commands that are Pythonic versions of the TUI commands used
in the Fluent console. Much like Fluent's TUI the API provides a hierarchical
interface to the underlying procedural interface of the program.

The solver TUI API does not support Fluent TUI features such as aliases or
command abbreviation. As an alternative, using this API in an interactive
session is easier if you install a tool such as
`pyreadline3 <https://github.com/pyreadline3/pyreadline3>`_ which provides
both command line completion and history. You can also use Python standard
`help` and `dir` commands on any object in the API to inspect it further.

The TUI based examples in our gallery provide a guide for how to use this API.
"""
}

_XML_HELP_FILE = os.path.normpath(
os.path.join(_THIS_DIRNAME, "data", "fluent_gui_help.xml")
)
_XML_HELPSTRINGS = {}

_FLUENT_IMAGE_NAME = "ghcr.io/pyansys/pyfluent:latest"


def _copy_tui_help_xml_file():
if os.getenv("PYFLUENT_LAUNCH_CONTAINER") == "1":
client = docker.from_env()
container = client.containers.create(_FLUENT_IMAGE_NAME)
xml_source = f"/ansys_inc/v{FLUENT_VERSION.replace('.', '')}/commonfiles/help/en-us/fluent_gui_help/fluent_gui_help.xml"
is_linux = platform.system() == "Linux"
subprocess.run(
f"docker cp {container.name}:{xml_source} {_XML_HELP_FILE}", shell=is_linux
)
container.remove()

else:
xml_source = (
get_fluent_path()
/ ".."
/ "commonfiles"
/ "help"
/ "en-us"
/ "fluent_gui_help"
/ "fluent_gui_help.xml"
)
if xml_source.exists():
shutil.copy(str(xml_source), _XML_HELP_FILE)
else:
LOG.warning("fluent_gui_help.xml is not found.")


def _populate_xml_helpstrings():
if not Path(_XML_HELP_FILE).exists():
return

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']")

for node in field_help_node.findall("sect2"):
id = node.get("id")
k = node.find("h3").text
k = k.strip().strip("/")
path = k.split("/")
path = [c.rstrip("?").replace("-", "_") for c in path]
k = "/" + "/".join(path)
v = "".join(node.find("p").itertext())
_XML_HELPSTRINGS[k] = v
patched_doc = XML_HELP_PATCH.get(id)
if patched_doc:
_XML_HELPSTRINGS[k] = patched_doc
else:
v = "".join(node.find("p").itertext())
_XML_HELPSTRINGS[k] = v


class _TUIMenuGenerator:
Expand Down Expand Up @@ -253,7 +281,7 @@ def _write_doc_for_menu(self, menu, doc_dir: Path, heading, class_name) -> None:
heading_ = heading.replace("_", "\_")
f.write(f"{heading_}\n")
f.write(f"{'=' * len(heading_)}\n")
desc = menu_descriptions.get(heading)
desc = MENU_DESCRIPTIONS.get(heading)
if desc:
f.write(desc)
f.write("\n")
Expand Down Expand Up @@ -315,6 +343,7 @@ def generate(self) -> None:

def generate():
# pyfluent.set_log_level("WARNING")
_copy_tui_help_xml_file()
_populate_xml_helpstrings()
TUIGenerator(meshing=True).generate()
TUIGenerator(meshing=False).generate()
Expand Down
3 changes: 2 additions & 1 deletion requirements_codegen.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
grpcio-tools==1.30.0
grpcio-tools==1.30.0
docker>=5.0.3
12 changes: 10 additions & 2 deletions src/ansys/fluent/core/launcher/launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,15 @@
PIM_FLUENT_PRODUCT_VERSION = FLUENT_VERSION.replace(".", "")


def _get_fluent_path():
def get_fluent_path() -> Path:
"""Get the local Fluent installation path specified by PYFLUENT_FLUENT_ROOT
or AWP_ROOTXXX environment variable.

Returns
-------
str
Local Fluent installation path.
"""
if "PYFLUENT_FLUENT_ROOT" in os.environ:
path = os.environ["PYFLUENT_FLUENT_ROOT"]
return Path(path)
Expand All @@ -34,7 +42,7 @@ def _get_fluent_path():


def _get_fluent_exe_path():
exe_path = _get_fluent_path()
exe_path = get_fluent_path()
if platform.system() == "Windows":
exe_path = exe_path / "ntbin" / "win64" / "fluent.exe"
else:
Expand Down