Skip to content

support launching pywb on linux#209

Merged
franknli merged 26 commits into
mainfrom
fli/launch_wb_on_linux
May 15, 2025
Merged

support launching pywb on linux#209
franknli merged 26 commits into
mainfrom
fli/launch_wb_on_linux

Conversation

@franknli

Copy link
Copy Markdown
Collaborator

No description provided.

@franknli
franknli requested a review from a team as a code owner April 24, 2025 22:05
@franknli
franknli requested a review from asawas April 24, 2025 22:05
# 'wmi' cannot be imported
self._wmi = None

if not self._wmi:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

this line will be run also on Windows when it fails to load the wmi.
I think we should raise an exception after line 54 to clearly state the issue.
The current message at line 64 is confusing.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Good point. Adjusted the code so it branches based on platform. @asawas

):
raise Exception("Invalid ANSYS version: " + version)

if host and not self._wmi:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The host could be the "localhost" or "127.0.0.1" which should be valid on Linux, right?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@asawas User is required to not specify the host argument if launching wb on local machine. So we are good here.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The parameter description does not clearly state that. Users may make such mistake since using "localhost" or "127.0.0.1" is a common practice to specify the local machine.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

we could include the host value in the error message for easier troubleshooting.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yes, that makes sense. Added host value in the message for failed connection to the host.

@franknli
franknli requested a review from PipKat as a code owner May 7, 2025 17:40
@github-actions github-actions Bot added the documentation Improvements or additions to documentation label May 7, 2025
Comment thread doc/source/cheatsheet/cheatsheet.qmd Outdated

## Connect to a remote Workbench server

Execute the steps below to link PyWorkbench with a remote session:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
Execute the steps below to link PyWorkbench with a remote session:
Execute the following steps to link PyWorkbench with a remote session:

Google dev doc style guide says not to use placement locators like above and below but rather use preceding and following.

Comment thread doc/source/cheatsheet/cheatsheet.qmd Outdated
workbench.download_file("*.out")
```

Use the ``{download_project_archive()}`` function to save, archive, and download the current Workbench project from the server to the client:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should the brackets be in the function tagged entity? I've never seen this before.


self._wmi = wmi
if not self._wmi:
raise Exception("Required Python module WMI does not exist or not loading properly")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
raise Exception("Required Python module WMI does not exist or not loading properly")
raise Exception("Required Python module WMI does not exist or is not loading properly.")

Messages should be complete sentences and concluding punctuation.

self._libc = None
if not self._libc:
raise Exception(
"Required Python module ctypes does not exist or not loading libc.so.6 properly"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
"Required Python module ctypes does not exist or not loading libc.so.6 properly"
"Required Python module ctypes do not exist or 'libc.so.6' is not loading properly."

Parameters
----------
version : str
Workbench version to launch. It must be a 3-digit version that is "242" or later.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
Workbench version to launch. It must be a 3-digit version that is "242" or later.
Workbench version to launch. It must be a three-digit version, such as ``242`` or later.

version : str
Workbench version to launch. It must be a 3-digit version that is "242" or later.
show_gui : bool, default: True
Weather to launch Workbench in UI mode.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
Weather to launch Workbench in UI mode.
Whether to launch Workbench in UI mode.

show_gui : bool, default: True
Weather to launch Workbench in UI mode.
server_workdir : str, default: None
Path to a writable directory on the server computer. The default is ``None``,

@PipKat PipKat May 8, 2025

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
Path to a writable directory on the server computer. The default is ``None``,
Path to a writable directory on the server. The default is ``None``,

I've not seen any other Ansys library use "server computer" but only "server" instead.

Comment on lines +89 to +90
Server computer's name or IP address. The default is ``None`` for launching on the
local computer.

@PipKat PipKat May 8, 2025

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
Server computer's name or IP address. The default is ``None`` for launching on the
local computer.
Name or IP address of the server. The default is ``None``, which launches
Workbench on the local computer.

Assuming it is launching Workbench but perhaps this and subsequent changes should be PyWorkbench?

Comment on lines +92 to +93
User's login name on the server computer. The default is ``None`` for launching on
the local computer.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
User's login name on the server computer. The default is ``None`` for launching on
the local computer.
User's login name on the server. The default is ``None``, which launches
Workbench on the local computer.

Comment on lines +95 to +96
User's password on the server computer. The default is ``None`` for launching on
the local computer.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
User's password on the server computer. The default is ``None`` for launching on
the local computer.
User's password on the server. The default is ``None``, which launches
Workbench on the local computer.

Comment on lines +102 to +103
If wmi service is not available for remote launching
If the host is given but username or password is missing.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
If wmi service is not available for remote launching
If the host is given but username or password is missing.
If the wmi service is not available for remote launching.
If the host is given but the username or password is missing.

raise Exception("Invalid ANSYS version: " + version)

if host and not self._wmi:
raise Exception("Launching PyWorkbench on a remote machine from Linux is not supported")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
raise Exception("Launching PyWorkbench on a remote machine from Linux is not supported")
raise Exception("Launching PyWorkbench on a remote machine from Linux is not supported.")

or version[0] not in ["2", "3"]
or version[2] not in ["1", "2"]
):
raise Exception("Invalid ANSYS version: " + version)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
raise Exception("Invalid ANSYS version: " + version)
raise Exception("Invalid Ansys version: " + version)

raise Exception(
"Launching PyWorkbench on a remote machine failed. "
"Make sure that the remote host is a Windows machine and that "
"correct credential is used."

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
"correct credential is used."
"the correct credential is used."

Adding the article "the" to improve readability.

self._process_id = process.pid
self._process = process
if successful:
logging.info("Workbench launched on the host with process id: " + str(self._process_id))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
logging.info("Workbench launched on the host with process id: " + str(self._process_id))
logging.info("Workbench launched on the host with process ID: " + str(self._process_id))

if not port or int(port) <= 0:
logging.error("Failed to retrieve the port used by Workbench service.")
return 0
logging.info("Workbench service uses port " + port)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Concluding period or add a colon after port (and before + port)?

if value:
value = value.decode("utf-8")
else:
raise Exception("unexpected code path")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
raise Exception("unexpected code path")
raise Exception("Code path is unexpected.")

pass

"""
# terminate related processes bottom-up

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
# terminate related processes bottom-up
# terminate related processes from the bottom up

@PipKat PipKat left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Performed doc review, leaving some minor comments.

raise Exception("Ansys installation is not found.")

args = []
if platform.system() == "Windows":

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think we should abstract the host machine to get rid of such if/else conditions, and self._wmi checks.
Probably, having three classes: Local Windows, Local Linux, and Remote Windows.

command_line = " ".join(args)

successful = False
if self._wmi:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

code can be simpler via host machine abstraction

self._process_id = -1
self._process = None

def __collect_process_tree(self):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is a Windows only method. Abstracting the host machine will move it to the appropriate class.

or version[2] not in ["1", "2"]
):
raise Exception("Invalid ANSYS version: " + version)
raise Exception("Invalid Ansys version: " + version)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This version validation logic does not enforce the version to be >= 242

):
raise Exception("Invalid ANSYS version: " + version)

if host and not self._wmi:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The parameter description does not clearly state that. Users may make such mistake since using "localhost" or "127.0.0.1" is a common practice to specify the local machine.

):
raise Exception("Invalid ANSYS version: " + version)

if host and not self._wmi:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

we could include the host value in the error message for easier troubleshooting.

p.Terminate()
except Exception:
pass
"""

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Remove the commented code.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

also the unused method __collect_process_tree should be removed

@github-actions github-actions Bot added the testing Anything related to tests label May 15, 2025
@franknli
franknli merged commit 3818a1a into main May 15, 2025
@franknli
franknli deleted the fli/launch_wb_on_linux branch May 15, 2025 03:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation testing Anything related to tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants