Skip to content

Commit

Permalink
Merge branch 'main' into feat/checking-no-instances-are-left-after-ea…
Browse files Browse the repository at this point in the history
…ch-test
  • Loading branch information
germa89 authored Jul 10, 2024
2 parents 8a7ca1d + 6090584 commit bef97e8
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 30 deletions.
17 changes: 16 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -339,10 +339,25 @@ jobs:
- name: "Install Git and checkout project"
uses: actions/checkout@v4.1.7

- name: Get event type and user to check permissions.
id: get_user
env:
type_event: ${{ github.event.issue.pull_request }}
run: |
if [[ $type_event ]]; then
echo "Event type: $type_event"
echo "event_type=$( echo "$type_event" )" >> $GITHUB_OUTPUT
export user=${{ github.event.pull_request.user.login }}
else
export user=${{ github.actor }}
fi
echo "This PR has been opened by: $user"
echo "user=$( echo "$user" )" >> $GITHUB_OUTPUT
- uses: tspascoal/get-user-teams-membership@v3
id: is_organization_member
with:
username: ${{ github.actor }}
username: ${{ steps.get_user.outputs.user }}
organization: ansys
team: 'pymapdl-developers'
GITHUB_TOKEN: ${{ secrets.TOKEN_TEAMS_USER_READ }}
Expand Down
1 change: 1 addition & 0 deletions doc/changelog.d/3239.miscellaneous.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
feat: refactoring `create_temp_dir`
1 change: 1 addition & 0 deletions doc/changelog.d/3240.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fix: Raising `ValueError` when using ips within pool library
1 change: 1 addition & 0 deletions doc/changelog.d/3256.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ci: run extended array based on the person who open the PR
4 changes: 2 additions & 2 deletions doc/source/api/pool.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.. _ref_pool_api:

Local MAPDL pool
================
MAPDL pool
==========

.. currentmodule:: ansys.mapdl.core

Expand Down
13 changes: 12 additions & 1 deletion src/ansys/mapdl/core/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,17 @@ def wrapper(*args, **kwargs):
except:
class_name = ""

# trying to get "cmd" argument:
cmd = args[1] if len(args) >= 2 else ""
cmd = kwargs.get("cmd", cmd)

caller = func.__name__

if cmd:
msg_ = f"running:\n{cmd}\ncalled by:\n{caller}"
else:
msg_ = f"calling:{caller}\nwith the following arguments:\nargs: {list(*args)}\nkwargs: {list(**kwargs_)}"

if class_name == "MapdlGrpc":
mapdl = args[0]
elif hasattr(args[0], "_mapdl"):
Expand All @@ -317,7 +328,7 @@ def wrapper(*args, **kwargs):
# Must close unfinished processes
mapdl._close_process()
raise MapdlExitedError(
f"MAPDL server connection terminated with the following error\n{error}"
f"MAPDL server connection terminated unexpectedly while {msg_}\nwith the following error\n{error}"
) from None

if threading.current_thread().__class__.__name__ == "_MainThread":
Expand Down
3 changes: 2 additions & 1 deletion src/ansys/mapdl/core/launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -1467,6 +1467,7 @@ def launch_mapdl(
)
use_vtk = kwargs.pop("use_vtk", None)
just_launch = kwargs.pop("just_launch", None)
on_pool = kwargs.pop("on_pool", False)
_debug_no_launch = kwargs.pop("_debug_no_launch", None)

# Transferring MAPDL arguments to start_parameters:
Expand Down Expand Up @@ -1532,7 +1533,7 @@ def launch_mapdl(
if ON_WSL:
LOG.debug("On WSL: Allowing 'start_instance' and 'ip' arguments together.")
else:
if start_instance is True:
if start_instance is True and not on_pool:
raise ValueError(
"When providing a value for the argument 'ip', the argument "
"'start_instance' cannot be 'True'.\n"
Expand Down
40 changes: 17 additions & 23 deletions src/ansys/mapdl/core/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,33 +519,27 @@ def create_temp_dir(tmpdir=None, name=None):
"""Create a new unique directory at a given temporary directory"""
if tmpdir is None:
tmpdir = tempfile.gettempdir()
elif not os.path.isdir(tmpdir):
os.makedirs(tmpdir)

if not name:
random_name = True
letters_ = string.ascii_lowercase.replace("n", "")
name = "ansys_" + random_string(10, letters_)
else:
random_name = False
# Possible letters
letters_ = string.ascii_lowercase.replace("n", "")

# running into a rare issue with MAPDL on Windows with "\n" being
# treated literally.
path = os.path.join(tmpdir, name)
def get_name():
return random_string(10, letters_)

if random_name:
# in the *rare* case of a duplicate path
while os.path.isdir(path):
path = os.path.join(tempfile.gettempdir(), name)
name = name or get_name()
while os.path.exists(os.path.join(tmpdir, name)):
name = get_name()

if not os.path.exists(path):
try:
os.mkdir(path)
except:
raise MapdlRuntimeError(
"Unable to create temporary working "
f"directory {path}\nPlease specify 'run_location' argument"
)
# create dir:
path = os.path.join(tmpdir, name)

try:
os.mkdir(path)
except: # pragma: no cover
raise MapdlRuntimeError(
"Unable to create temporary working "
f"directory {path}.\nSpecify 'run_location' argument"
)

return path

Expand Down
4 changes: 2 additions & 2 deletions src/ansys/mapdl/core/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import os
import shutil
import socket
import tempfile
import time
from typing import Any, Dict, List, Optional, Union
import warnings
Expand Down Expand Up @@ -219,7 +218,7 @@ def __init__(
_debug_no_launch = kwargs.pop("_debug_no_launch", None)

if run_location is None:
run_location = tempfile.gettempdir()
run_location = create_temp_dir()
self._root_dir: str = run_location

kwargs["remove_temp_files"] = remove_temp_files
Expand Down Expand Up @@ -875,6 +874,7 @@ def _spawn_mapdl(
ip=ip,
override=True,
start_instance=start_instance,
on_pool=True,
**self._spawn_kwargs,
)

Expand Down
14 changes: 14 additions & 0 deletions tests/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"""Small or misc tests that don't fit in other test modules"""
import inspect
import os
import pathlib

import numpy as np
import pytest
Expand All @@ -37,6 +38,7 @@
check_valid_ip,
check_valid_port,
check_valid_routine,
create_temp_dir,
last_created,
load_file,
no_return,
Expand Down Expand Up @@ -376,3 +378,15 @@ def test_check_valid_routine():
assert check_valid_routine("begin level")
with pytest.raises(ValueError, match="Invalid routine"):
check_valid_routine("invalid")


@requires("local")
def test_create_temp_dir():

path = create_temp_dir()

path = pathlib.Path(path)
parent = path.parent
dir_ = path.parts[-1]

assert str(path) != create_temp_dir(parent, dir_)

0 comments on commit bef97e8

Please sign in to comment.