Skip to content

Commit efb0696

Browse files
Gryfenfer97pre-commit-ci[bot]pyansys-ci-bot
committed
feat: Add an inprocess backend to pymapdl (#3198)
* add an inprocess backend to pymapdl --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: pyansys-ci-bot <[email protected]>
1 parent 09de71f commit efb0696

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed

doc/changelog.d/3198.added.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
feat: Add an inprocess backend to pymapdl

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ omit = [
150150
# ignore legacy interfaces
151151
"ansys/mapdl/core/mapdl_console.py",
152152
"ansys/mapdl/core/jupyter.py",
153+
# ignore non exposed interfaces
154+
"ansys/mapdl/core/mapdl_inprocess.py",
153155
]
154156

155157
[tool.coverage.report]
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Copyright (C) 2024 ANSYS, Inc. and/or its affiliates.
2+
# SPDX-License-Identifier: MIT
3+
#
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy
6+
# of this software and associated documentation files (the "Software"), to deal
7+
# in the Software without restriction, including without limitation the rights
8+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
# copies of the Software, and to permit persons to whom the Software is
10+
# furnished to do so, subject to the following conditions:
11+
#
12+
# The above copyright notice and this permission notice shall be included in all
13+
# copies or substantial portions of the Software.
14+
#
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
# SOFTWARE.
22+
23+
from typing import Optional, Protocol
24+
25+
from ansys.mapdl.core.mapdl import MapdlBase
26+
27+
28+
class _Backend(Protocol):
29+
def run_command(self) -> str: ...
30+
31+
32+
class MapdlInProcess(MapdlBase):
33+
def __init__(self, backend: _Backend):
34+
super().__init__(
35+
loglevel="WARNING", use_vtk=False, log_apdl=None, print_com=False
36+
)
37+
self._backend = backend
38+
self._cleanup: bool = True
39+
self._name: str = "MapdlInProcess"
40+
self._session_id: Optional[str] = None
41+
self._mute: bool = False
42+
43+
def _run(self, command: str, verbose: bool = False, mute: bool = False) -> str:
44+
if not command.strip():
45+
raise ValueError("Empty commands not allowed")
46+
47+
if len(command) > 639:
48+
raise ValueError("Maximum command length mut be less than 640 characters")
49+
50+
return self._backend.run_command(command, verbose, mute).strip()
51+
52+
@property
53+
def name(self) -> str:
54+
return self._name
55+
56+
@name.setter
57+
def name(self, name) -> None:
58+
self._name = name
59+
60+
def _check_session_id(self) -> None:
61+
pass
62+
63+
def __repr__(self):
64+
info = super().__repr__()
65+
return info

0 commit comments

Comments
 (0)