-
Notifications
You must be signed in to change notification settings - Fork 136
feat: First tentative for Plugin Mapdl Mechanism python API #3627
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
Open
FredAns
wants to merge
19
commits into
main
Choose a base branch
from
feat/plugins
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 8 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
7a8a716
First tentative for plugin mapdl mechanism
FredAns 538936d
ci: auto fixes from pre-commit.com hooks.
pre-commit-ci[bot] 35bcf88
chore: adding changelog file 3627.miscellaneous.md [dependabot-skip]
pyansys-ci-bot 2dea3bc
ci: auto fixes from pre-commit.com hooks.
pre-commit-ci[bot] a1d7ee2
ci: auto fixes from pre-commit.com hooks.
pre-commit-ci[bot] 57e2de6
Merge branch 'main' into feat/plugins
germa89 cd63cc8
Merge branch 'main' into feat/plugins
germa89 1d2d4d5
chore: merge remote-tracking branch 'origin/main' into feat/plugins
germa89 4afa907
feat: add plugin error handling classes and improve plugin loading/un…
germa89 16c744d
test: adding plugin tests
germa89 6eaf391
Merge branch 'main' into feat/plugins
germa89 83997de
ci: auto fixes from pre-commit.com hooks.
pre-commit-ci[bot] ff30eae
chore: adding changelog file 3627.miscellaneous.md [dependabot-skip]
pyansys-ci-bot fec2b24
feat: rename plugin to plugins. Enhance plugin functionality with com…
germa89 f4e9ef5
feat: add plugin property to _MapdlCore and remove from MapdlGrpc
germa89 302ecc1
fix: streamline command replacement in ansPlugin class
germa89 6dc488f
Update tests/test_plugin.py
germa89 d1e8471
fix: update plugin response handling to return an empty list and add …
germa89 3c25fe9
Merge branch 'feat/plugins' of https://github.com/ansys/pymapdl into …
germa89 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 hidden or 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 @@ | ||
feat: First tentative for Plugin Mapdl Mechanism python API |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,141 @@ | ||
# Copyright (C) 2016 - 2025 ANSYS, Inc. and/or its affiliates. | ||
# SPDX-License-Identifier: MIT | ||
# | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the "Software"), to deal | ||
# in the Software without restriction, including without limitation the rights | ||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
# copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included in all | ||
# copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
# SOFTWARE. | ||
|
||
"""Contains the ansPlugin class.""" | ||
import json | ||
import pathlib | ||
import weakref | ||
|
||
from ansys.api.mapdl.v0 import mapdl_pb2 | ||
|
||
from .common_grpc import ANSYS_VALUE_TYPE | ||
from .errors import MapdlRuntimeError | ||
from .misc import random_string | ||
germa89 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
class ansPlugin: | ||
""" | ||
ANSYS MAPDL Plugin Manager. | ||
|
||
Examples | ||
-------- | ||
>>> from ansys.mapdl.core import launch_mapdl | ||
>>> mapdl = launch_mapdl() | ||
>>> plugin = mapdl.plugin | ||
|
||
Load a plugin in the MAPDL Session | ||
""" | ||
|
||
def __init__(self, mapdl): | ||
"""Initialize the class.""" | ||
from ansys.mapdl.core.mapdl_grpc import MapdlGrpc | ||
|
||
if not isinstance(mapdl, MapdlGrpc): # pragma: no cover | ||
raise TypeError("Must be initialized using MapdlGrpc class") | ||
germa89 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
self._mapdl_weakref = weakref.ref(mapdl) | ||
self._filename = None | ||
self._open = False | ||
|
||
@property | ||
def _mapdl(self): | ||
"""Return the weakly referenced instance of mapdl.""" | ||
return self._mapdl_weakref() | ||
|
||
def load(self, plugin_name: str, feature: str = "CMD") -> str: | ||
germa89 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
""" | ||
Loads a plugin into MAPDL. | ||
|
||
Parameters | ||
---------- | ||
plugin_name : str | ||
Name of the plugin to load. | ||
feature : str | ||
Feature or module to activate in the plugin. | ||
|
||
Returns | ||
------- | ||
str | ||
Confirmation message about the loaded plugin. | ||
|
||
Raises | ||
------ | ||
PluginLoadError | ||
If the plugin fails to load. | ||
germa89 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
""" | ||
|
||
command = f"*PLUG,LOAD,{plugin_name},{feature}" | ||
response = self._mapdl.run(command) | ||
if "error" in response.lower(): | ||
raise PluginLoadError( | ||
germa89 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
f"Failed to load plugin '{plugin_name}' with feature '{feature}'." | ||
) | ||
return f"Plugin '{plugin_name}' with feature '{feature}' loaded successfully." | ||
germa89 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
def unload(self, plugin_name: str) -> str: | ||
""" | ||
Unloads a plugin from MAPDL. | ||
|
||
Parameters | ||
---------- | ||
plugin_name : str | ||
Name of the plugin to unload. | ||
|
||
Returns | ||
------- | ||
str | ||
Confirmation message about the unloaded plugin. | ||
|
||
Raises | ||
------ | ||
PluginUnloadError | ||
If the plugin fails to unload. | ||
""" | ||
|
||
command = f"*PLUG,UNLOAD,{plugin_name}" | ||
response = self._mapdl.run(command) | ||
if "error" in response.lower(): | ||
raise PluginUnloadError(f"Failed to unload plugin '{plugin_name}'.") | ||
return f"Plugin '{plugin_name}' unloaded successfully." | ||
germa89 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
def list(self) -> list: | ||
""" | ||
Lists all currently loaded plugins in MAPDL. | ||
|
||
Returns | ||
------- | ||
list | ||
A list of loaded plugin names. | ||
|
||
Raises | ||
------ | ||
RuntimeError | ||
If the plugin list cannot be retrieved. | ||
""" | ||
|
||
command = "*PLUG,LIST" | ||
response = self._mapdl.run(command) | ||
if "error" in response.lower(): | ||
raise RuntimeError("Failed to retrieve the list of loaded plugins.") | ||
germa89 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# Parse response and extract plugin names (assuming response is newline-separated text) | ||
plugins = [line.strip() for line in response.splitlines() if line.strip()] | ||
germa89 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return plugins | ||
germa89 marked this conversation as resolved.
Show resolved
Hide resolved
|
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.
Uh oh!
There was an error while loading. Please reload this page.