Skip to content

Commit 6088bdb

Browse files
committed
refactor: move get_mapdl_instances and get_ansys_process_from_port to helpers.py
1 parent d170f1b commit 6088bdb

File tree

3 files changed

+6
-9
lines changed

3 files changed

+6
-9
lines changed
Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
This module avoids importing heavy dependencies like pandas, numpy, etc.
2626
"""
2727

28-
import getpass
29-
import platform
3028
from typing import Any, Dict, List
3129

3230
import psutil
@@ -49,6 +47,9 @@ def can_access_process(proc):
4947
bool
5048
True if we can safely access the process
5149
"""
50+
import getpass
51+
import platform
52+
5253
try:
5354
# Check if we can access basic process info and if it belongs to current user
5455
current_user = getpass.getuser()
@@ -146,10 +147,6 @@ def get_mapdl_instances() -> List[Dict[str, Any]]:
146147
def get_ansys_process_from_port(port: int):
147148
import socket
148149

149-
import psutil
150-
151-
from ansys.mapdl.core.cli.core import is_alive_status, is_valid_ansys_process_name
152-
153150
# Filter by name first
154151
potential_procs = []
155152
for proc in psutil.process_iter(attrs=["name"]):

src/ansys/mapdl/core/cli/list_instances.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def list_instances(instances, long, cmd, location) -> None:
7272
def _list_instances(instances, long, cmd, location):
7373
from tabulate import tabulate
7474

75-
from ansys.mapdl.core.cli.core import get_mapdl_instances
75+
from ansys.mapdl.core.cli.helpers import get_mapdl_instances
7676

7777
# Assuming all ansys processes have -grpc flag
7878
mapdl_instances = get_mapdl_instances()

tests/test_cli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
import psutil
3232
import pytest
3333

34-
import ansys.mapdl.core.cli.core as core_module
35-
from ansys.mapdl.core.cli.core import get_ansys_process_from_port
34+
import ansys.mapdl.core.cli.helpers as core_module
35+
from ansys.mapdl.core.cli.helpers import get_ansys_process_from_port
3636
from ansys.mapdl.core.plotting import GraphicsBackend
3737
from conftest import VALID_PORTS, requires
3838

0 commit comments

Comments
 (0)