Skip to content

Commit

Permalink
Add a python path field to the Omni UI (#463)
Browse files Browse the repository at this point in the history
Co-authored-by: Mario Ostieri <107915956+mariostieriansys@users.noreply.github.com>
  • Loading branch information
david-bremer and mariostieriansys committed Oct 18, 2024
1 parent d0099fc commit 52b0df9
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,15 @@ def time_scale(self) -> float:
def time_scale(self, value: float) -> None:
self._time_scale = value

@property
def interpreter(self) -> str:
"""Fully qualified path to the python.exe or .bat wrapper in which pyensight is installed."""
return self._interpreter

@interpreter.setter
def interpreter(self, value: str) -> None:
self._interpreter = value

@classmethod
def get_instance(cls) -> Optional["AnsysToolsOmniverseCoreServerExtension"]:
return cls._service_instance
Expand Down Expand Up @@ -257,11 +266,10 @@ def _find_ensight_cpython(self) -> Optional[str]:
# ways, we'll add that one too, just in case.
dirs_to_check.append(os.path.join(env_inst, "CEI"))

# Look for most recent Ansys install
# Look for most recent Ansys install, 25.1 or later
awp_roots = []
for env_name in dict(os.environ).keys():
# TODO: do not allow earlier than 251
if env_name.startswith("AWP_ROOT"):
if env_name.startswith("AWP_ROOT") and int(env_name[len("AWP_ROOT") :]) >= 251:
awp_roots.append(env_name)
awp_roots.sort(reverse=True)
for env_name in awp_roots:
Expand All @@ -271,8 +279,9 @@ def _find_ensight_cpython(self) -> Optional[str]:
for install_dir in dirs_to_check:
launch_file = os.path.join(install_dir, "bin", cpython)
if os.path.isfile(launch_file):
return launch_file
return None
if self.validate_interpreter(launch_file):
return launch_file
return ""

def on_startup(self, ext_id: str) -> None:
"""
Expand All @@ -295,6 +304,21 @@ def on_shutdown(self) -> None:
self.shutdown()
AnsysToolsOmniverseCoreServerExtension._service_instance = None

def validate_interpreter(self, launch_file: str) -> bool:
if len(launch_file) == 0:
return False
has_ov_module = False
try:
cmd = [launch_file, "-m", "ansys.pyensight.core.utils.omniverse_cli", "-h"]
env_vars = os.environ.copy()
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, env=env_vars)
proc.wait(timeout=60)
has_ov_module = proc.communicate()[0].decode("utf-8").startswith("usage: omniverse_cli")
except Exception as error:
self.warning(f"Exception thrown while testing python {str(launch_file)}: {str(error)}")
has_ov_module = False
return has_ov_module

def dsg_export(self) -> None:
"""
Use the oneshot feature of the pyensight omniverse_cli to push the current
Expand Down
4 changes: 3 additions & 1 deletion exts/ansys.tools.omniverse.core/config/extension.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
# Semantic Versioning is used: https://semver.org/
version = "0.8.11"
version = "0.8.12"

# Lists people or organizations that are considered the "authors" of the package.
authors = ["ANSYS"]
Expand Down Expand Up @@ -57,3 +57,5 @@ exts."ansys.tools.omniverse.core".temporal = "0"
exts."ansys.tools.omniverse.core".vrmode = "0"
exts."ansys.tools.omniverse.core".normalizeGeometry = "0"
exts."ansys.tools.omniverse.core".timeScale = "1.0"
exts."ansys.tools.omniverse.core".interpreter = ""

3 changes: 3 additions & 0 deletions exts/ansys.tools.omniverse.core/docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [0.8.12] - 2024-10-17
- Update to let the path to the python installation be validated and edited

## [0.8.11] - 2024-09-17
- Update for new pyensight Omniverse interface

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def __init__(self, *args, **kwargs) -> None:
self._grpc = None
self._dsg_uri_w = None
self._dsg_token_w = None
self._interpreter_w = None
self._destination_w = None
self._temporal_w = None
self._vrmode_w = None
Expand All @@ -25,6 +26,7 @@ def __init__(self, *args, **kwargs) -> None:
self._connect_w = None
self._update_w = None
self._connected = False
self._error_msg = ""

@property
def service(self) -> Optional["AnsysToolsOmniverseDSGUIExtension"]:
Expand All @@ -44,6 +46,7 @@ def start_server(self) -> None:
return
self.service.dsg_uri = self._dsg_uri_w.model.as_string
self.service.security_token = self._dsg_token_w.model.as_string
self.service.interpreter = self._interpreter_w.model.as_string
self.service.destination = self._destination_w.model.as_string
self.service.temporal = self._temporal_w.model.as_bool
self.service.vrmode = self._vrmode_w.model.as_bool
Expand All @@ -68,7 +71,12 @@ def connect_cb(self) -> None:
if self._connected:
self.stop_server()
else:
self.start_server()
pypath = self._interpreter_w.model.as_string
if not self.service.validate_interpreter(pypath):
self._error_msg = ". Invalid Python path."
else:
self._error_msg = ""
self.start_server()
self.update_ui()

def update_cb(self) -> None:
Expand Down Expand Up @@ -104,7 +112,7 @@ def update_ui(self) -> None:
self._label_w.text = tmp
else:
self._connect_w.text = "Connect to DSG Server"
self._label_w.text = "No connected DSG server"
self._label_w.text = "No connected DSG server" + self._error_msg
self._update_w.enabled = self._connected and (status.get("status", "idle") == "idle")
self._connect_w.enabled = status.get("status", "idle") == "idle"
self._temporal_w.enabled = True
Expand All @@ -113,13 +121,14 @@ def update_ui(self) -> None:
self._time_scale_w.enabled = not self._connected
self._dsg_uri_w.enabled = not self._connected
self._dsg_token_w.enabled = not self._connected
self._interpreter_w.enabled = not self._connected
self._destination_w.enabled = not self._connected

def build_ui(self) -> None:
self._window = ui.Window(f"ANSYS Tools Omniverse DSG ({self.service.version})")
with self._window.frame:
with ui.VStack(height=0, spacing=5):
self._label_w = ui.Label("No connected DSG server")
self._label_w = ui.Label("No connected DSG server" + self._error_msg)

with ui.HStack(spacing=5):
ui.Label(
Expand All @@ -141,7 +150,16 @@ def build_ui(self) -> None:

with ui.HStack(spacing=5):
ui.Label(
"Omniverse URI:",
"Python path:",
alignment=ui.Alignment.RIGHT_CENTER,
width=0,
)
self._interpreter_w = ui.StringField()
self._interpreter_w.model.as_string = str(self.service.interpreter)

with ui.HStack(spacing=5):
ui.Label(
"Export directory:",
alignment=ui.Alignment.RIGHT_CENTER,
width=0,
)
Expand Down Expand Up @@ -184,6 +202,7 @@ def on_shutdown(self) -> None:
self._label_w = None
self._dsg_uri_w = None
self._dsg_token_w = None
self._interpreter_w = None
self._destination_w = None
self._temporal_w = None
self._vrmode_w = None
Expand Down
2 changes: 1 addition & 1 deletion exts/ansys.tools.omniverse.dsgui/config/extension.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
# Semantic Versioning is used: https://semver.org/
version = "0.8.11"
version = "0.8.12"

# Lists people or organizations that are considered the "authors" of the package.
authors = ["ANSYS"]
Expand Down
3 changes: 3 additions & 0 deletions exts/ansys.tools.omniverse.dsgui/docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [0.8.11] - 2024-10-17
- Add UI to view, edit, and validate the path to the python containing pyensight

## [0.8.11] - 2024-09-17
- Update for new pyensight Omniverse interface

Expand Down

0 comments on commit 52b0df9

Please sign in to comment.