Skip to content

Commit

Permalink
Merge branch 'main' into feat/selection-commands-returning-ids
Browse files Browse the repository at this point in the history
  • Loading branch information
moe-ad authored Jan 8, 2025
2 parents 33a7ea9 + 3df7801 commit 0a824bb
Show file tree
Hide file tree
Showing 23 changed files with 256 additions and 153 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ env:
ON_CI: True
PYTEST_ARGUMENTS: '-vvv -rxXsa --color=yes --durations=10 --random-order --random-order-bucket=class --maxfail=10 --reruns 3 --reruns-delay 4 --cov=ansys.mapdl.core --cov-report=html --timeout=180'


BUILD_CHEATSHEET: True
PYMAPDL_DEBUG_TESTING: True

Expand Down Expand Up @@ -63,7 +64,6 @@ permissions:

jobs:


update-changelog:
name: "Update CHANGELOG (on release)"
if: github.event_name == 'push' && contains(github.ref, 'refs/tags')
Expand Down
2 changes: 1 addition & 1 deletion doc/changelog.d/3247.fixed.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
fix: not deleting temporary file when ``remove_temp_dir_on_exit``=True
fix: not deleting temporary file when ``remove_temp_dir_on_exit`` =True
1 change: 1 addition & 0 deletions doc/changelog.d/3577.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
refactor: small improvements to test settings
1 change: 1 addition & 0 deletions doc/changelog.d/3630.dependencies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build: bump pyfakefs from 5.7.2 to 5.7.3
1 change: 1 addition & 0 deletions doc/changelog.d/3631.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
refactor: Iterate over the dictionary directly instead of using .keys().
1 change: 1 addition & 0 deletions doc/changelog.d/3638.maintenance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ci: fix safety issue
1 change: 1 addition & 0 deletions doc/changelog.d/3640.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fix: changelog
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ tests = [
"matplotlib==3.10.0",
"pandas==2.2.3",
"pyansys-tools-report==0.8.1",
"pyfakefs==5.7.2",
"pyfakefs==5.7.3",
"pyiges[full]==0.3.1",
"pytest-cov==6.0.0",
"pytest-pyvista==0.1.9",
Expand Down
4 changes: 2 additions & 2 deletions src/ansys/mapdl/core/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -847,8 +847,8 @@ def bc_colnames(self) -> Optional[List[str]]:

title = self._get_body()[0]

_bcType = [i for i in bc_type.keys() if i in title]
_entity = [i for i in entity.keys() if i in title]
_bcType = [i for i in bc_type if i in title]
_entity = [i for i in entity if i in title]

if _bcType and _entity:

Expand Down
5 changes: 3 additions & 2 deletions src/ansys/mapdl/core/database/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,9 @@ def stop(self):

self._mapdl._log.debug("Closing the connection with the MAPDL DB Server")
self._stop()
self._channel.close()
self._channel = None
if self._channel:
self._channel.close()
self._channel = None
self._stub = None
self._state = None

Expand Down
6 changes: 3 additions & 3 deletions src/ansys/mapdl/core/launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ def version_from_path(*args, **kwargs):
"additional_switches",
"cleanup_on_exit",
"clear_on_connect",
"running_on_hpc",
"exec_file",
"force_intel" "ip",
"ip",
Expand All @@ -125,6 +124,7 @@ def version_from_path(*args, **kwargs):
"remove_temp_dir_on_exit",
"replace_env_vars",
"run_location",
"running_on_hpc",
"scheduler_options",
"set_no_abort",
"start_instance",
Expand Down Expand Up @@ -554,7 +554,7 @@ def check_mapdl_launch(
MAPDL did not start.
"""
LOG.debug("Generating queue object for stdout")
stdout_queue, _ = _create_queue_for_std(process.stdout)
stdout_queue, thread = _create_queue_for_std(process.stdout)

# Checking connection
try:
Expand Down Expand Up @@ -2876,7 +2876,7 @@ def submitter(
stdout=stdout,
stderr=stderr,
env=env_vars,
) # nosec B603 B607
)


def check_console_start_parameters(start_parm):
Expand Down
4 changes: 3 additions & 1 deletion src/ansys/mapdl/core/mapdl_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1400,7 +1400,8 @@ def __init__(self, parent):
self._parent = weakref.ref(parent)

def __enter__(self):
self._parent()._log.debug("Entering non-interactive mode")
self._parent()._log.debug("Entering in non-interactive mode")
self._parent().com("Entering in non_interactive mode")
self._parent()._store_commands = True

def __exit__(self, *args):
Expand Down Expand Up @@ -2287,6 +2288,7 @@ def run(
self._before_run(command)

short_cmd = parse_to_short_cmd(command)
self._log.debug(f"Running (verbose: {verbose}, mute={mute}): '{command}'")
text = self._run(command, verbose=verbose, mute=mute)

if (
Expand Down
19 changes: 11 additions & 8 deletions src/ansys/mapdl/core/mapdl_grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1334,7 +1334,12 @@ def _cache_pids(self):
pids = set(re.findall(r"-9 (\d+)", raw))
self._pids = [int(pid) for pid in pids]

if not self._pids:
if not self._pids and not self._mapdl_process:
self._log.debug(
f"MAPDL process is not provided. PIDs could not be retrieved."
)
return
elif not self._pids:
# For the cases where the cleanup file is not generated,
# we relay on the process.
parent_pid = self._mapdl_process.pid
Expand Down Expand Up @@ -2941,7 +2946,7 @@ def _mat_data(self, pname, raw=False):

@property
def locked(self):
"""Instance is in use within a pool"""
"""Instance is in use within a pool."""
return self._locked

@locked.setter
Expand Down Expand Up @@ -2987,7 +2992,7 @@ def _generate_iges(self):

@property
def _distributed_result_file(self):
"""Path of the distributed result file"""
"""Path of the distributed result file."""
if not self._distributed:
return

Expand Down Expand Up @@ -3022,7 +3027,7 @@ def _distributed_result_file(self):

@property
def thermal_result(self):
"""The thermal result object"""
"""The thermal result object."""
self._prioritize_thermal = True
result = self.result
self._prioritize_thermal = False
Expand All @@ -3045,7 +3050,7 @@ def list_error_file(self):
return open(os.path.join(self.directory, error_file)).read()
elif self._exited:
raise MapdlExitedError(
"Cannot list error file when MAPDL Service has " "exited"
"Cannot list error file when MAPDL Service has exited"
)

return self._download_as_raw(error_file).decode("latin-1")
Expand All @@ -3060,9 +3065,7 @@ def cmatrix(
capname="",
**kwargs,
):
"""Run CMATRIX in non-interactive mode and return the response
from file.
"""
"""Run CMATRIX in non-interactive mode and return the response from file."""

# The CMATRIX command needs to run in non-interactive mode
if not self._store_commands:
Expand Down
7 changes: 4 additions & 3 deletions src/ansys/mapdl/core/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,9 +571,10 @@ def wrapper(self, *args, **kwargs):
# assuming you want to select nothing because you supplied an empty list/tuple/array
return original_sel_func(self, "none")

self._perform_entity_list_selection(
entity, original_sel_func, type_, item, comp, vmin, kabs
)
with self.non_interactive: # to speed up
self._perform_entity_list_selection(
entity, original_sel_func, type_, item, comp, vmin, kabs
)

if kwargs.pop("Used_P", False):
# we want to return the
Expand Down
2 changes: 1 addition & 1 deletion src/ansys/mapdl/core/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ def _get_parameter_array(self, parm_name, shape):
f"that could not be read using '{format_str}'."
)

arr_flat = np.fromstring(output, sep="\n").reshape(shape)
arr_flat = np.fromstring(output.strip(), sep="\n").reshape(shape)

if len(shape) == 3:
if shape[2] == 1:
Expand Down
6 changes: 4 additions & 2 deletions src/ansys/mapdl/core/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -614,8 +614,10 @@ def run():
try:
self._exiting_i += 1
instance.exit()
except Exception as e:
LOG.error("Failed to close instance", exc_info=True)
except Exception:
LOG.error(
f"Failed to close instance due to:\n{e}", exc_info=True
)
self._exiting_i -= 1

else:
Expand Down
34 changes: 29 additions & 5 deletions src/ansys/mapdl/core/post.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,37 @@ def _mapdl(self):
@supress_logging
def __repr__(self):
info = "PyMAPDL PostProcessing Instance\n"
info += "\tActive Result File: %s\n" % self.filename
info += "\tNumber of result sets: %d\n" % self.nsets
info += "\tCurrent load step: %d\n" % self.load_step
info += "\tCurrent sub step: %d\n" % self.sub_step
info += f"\tActive Result File: {self.filename}\n"

# If there is no result file, this fails.
try:
nsets = int(self.nsets)
except MapdlRuntimeError as error:
self._mapdl.logger.debug(
f"Error when obtaining the number of sets:\n{error}"
)
nsets = "NA"

info += f"\tNumber of result sets: {nsets}\n"
info += f"\tCurrent load step: {self.load_step}\n"
info += f"\tCurrent sub step: {self.sub_step}\n"

if self._mapdl.parameters.routine == "POST1":
info += "\n\n" + self._mapdl.set("LIST")
try:
nlist = self._mapdl.set("LIST")
except MapdlRuntimeError as err:
if (
"An error occurred while attempting to open the results file"
in str(err)
):
self._mapdl.logger.debug(
f"List of steps could not be obtained due to error:\n{err}"
)
nlist = "Results file is not available"
else:
raise err

info += "\n\n" + nlist
else:
info += "\n\nEnable routine POST1 to see a table of available results"

Expand Down
7 changes: 6 additions & 1 deletion tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,10 @@ def is_exited(mapdl: Mapdl):

# we cannot connect.
# Kill the instance
mapdl.exit()
try:
mapdl.exit()
except Exception as e:
LOG.error(f"An error occurred when killing the instance:\n{str(e)}")

# Relaunching MAPDL
mapdl = launch_mapdl(
Expand All @@ -285,6 +288,8 @@ def is_exited(mapdl: Mapdl):
log_apdl=log_apdl(),
)

LOG.info("Successfully re-connected to MAPDL")

# Restoring the local configuration
mapdl._local = local_
mapdl._exited = False
Expand Down
13 changes: 8 additions & 5 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,9 @@ def requires_dependency(dependency: str):

# the following files are also generated by MAPDL gRPC:
# - "pymapdl.apdl": The APDL commands sent to MAPDL by PyMAPDL
# - "apdl.out" : MAPDL console output. Very likely only contains the output until connected.
# - "apdl.out" : MAPDL console output. Very likely only contains the output
# until connected.

################################################################
#
# Importing packages
Expand Down Expand Up @@ -230,14 +232,12 @@ def requires_dependency(dependency: str):

viz_interface.TESTING_MODE = True


################################################################
#
# Pytest configuration
# --------------------
#


# check if the user wants to permit pytest to start MAPDL
START_INSTANCE = get_start_instance()

Expand Down Expand Up @@ -558,7 +558,10 @@ def mapdl_console(request):
)

mapdl = launch_mapdl(
console_path, mode="console", log_apdl="pymapdl.apdl" if DEBUG_TESTING else None
console_path,
mode="console",
log_apdl="pymapdl.apdl" if DEBUG_TESTING else None,
loglevel="DEBUG" if DEBUG_TESTING else "ERROR",
)
from ansys.mapdl.core.mapdl_console import MapdlConsole

Expand Down Expand Up @@ -604,7 +607,7 @@ def mapdl(request, tmpdir_factory):
if ON_CI:
mapdl._local = ON_LOCAL # CI: override for testing

if mapdl.is_local:
if ON_LOCAL and mapdl.is_local:
assert Path(mapdl.directory) == Path(run_path)

# using yield rather than return here to be able to test exit
Expand Down
Loading

0 comments on commit 0a824bb

Please sign in to comment.