diff --git a/doc/changelog.d/4039.miscellaneous.md b/doc/changelog.d/4039.miscellaneous.md new file mode 100644 index 00000000000..ed4ec67ae3e --- /dev/null +++ b/doc/changelog.d/4039.miscellaneous.md @@ -0,0 +1 @@ +Refactor: moving parse_ip_route to misc \ No newline at end of file diff --git a/src/ansys/mapdl/core/launcher.py b/src/ansys/mapdl/core/launcher.py index 6aa539c6533..e3dde28efae 100644 --- a/src/ansys/mapdl/core/launcher.py +++ b/src/ansys/mapdl/core/launcher.py @@ -69,6 +69,7 @@ check_valid_ip, check_valid_port, create_temp_dir, + parse_ip_route, ) from ansys.mapdl.core.misc import threaded # type: ignore from ansys.mapdl.core.plotting import GraphicsBackend @@ -2025,7 +2026,7 @@ def set_license_switch(license_type: str | None, additional_switches: str) -> st def _get_windows_host_ip() -> str | None: output = _run_ip_route() if output: - return _parse_ip_route(output) + return parse_ip_route(output) def _run_ip_route() -> str | None: @@ -2045,13 +2046,6 @@ def _run_ip_route() -> str | None: return p.stdout.decode() -def _parse_ip_route(output: str) -> str | None: - match = re.findall(r"(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}).*", output) - - if match: - return match[0] - - def get_slurm_options( args: Dict[str, Any], kwargs: Dict[str, Any], diff --git a/src/ansys/mapdl/core/misc.py b/src/ansys/mapdl/core/misc.py index 79063054277..d81f4b72029 100644 --- a/src/ansys/mapdl/core/misc.py +++ b/src/ansys/mapdl/core/misc.py @@ -385,6 +385,13 @@ def check_valid_ip(ip: str) -> None: socket.inet_aton(ip) +def parse_ip_route(output: str) -> str | None: + match = re.findall(r"(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}).*", output) + + if match: + return match[0] + + def check_valid_port( port: int, lower_bound: int = 1000, high_bound: int = 60000 ) -> None: diff --git a/tests/test_launcher.py b/tests/test_launcher.py index c1d4445bc41..10d8c0e626d 100644 --- a/tests/test_launcher.py +++ b/tests/test_launcher.py @@ -46,7 +46,6 @@ _HAS_ATP, LOCALHOST, _is_ubuntu, - _parse_ip_route, check_mapdl_launch_on_hpc, check_mode, force_smp_in_student, @@ -77,7 +76,7 @@ update_env_vars, ) from ansys.mapdl.core.licensing import LICENSES -from ansys.mapdl.core.misc import check_has_mapdl, stack +from ansys.mapdl.core.misc import check_has_mapdl, parse_ip_route, stack from conftest import ( ON_LOCAL, PATCH_MAPDL, @@ -589,13 +588,13 @@ def test__parse_ip_route(): output = """default via 172.25.192.1 dev eth0 proto kernel <<<=== this 172.25.192.0/20 dev eth0 proto kernel scope link src 172.25.195.101 <<<=== not this""" - assert "172.25.192.1" == _parse_ip_route(output) + assert "172.25.192.1" == parse_ip_route(output) output = """ default via 172.23.112.1 dev eth0 proto kernel 172.23.112.0/20 dev eth0 proto kernel scope link src 172.23.121.145""" - assert "172.23.112.1" == _parse_ip_route(output) + assert "172.23.112.1" == parse_ip_route(output) def test_launched(mapdl, cleared):