Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions src/ansys/dpf/core/server_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -602,13 +602,6 @@ def get_server_type_from_config(
if config.protocol == CommunicationProtocols.gRPC and config.legacy:
return LegacyGrpcServer
elif config.protocol == CommunicationProtocols.gRPC and not config.legacy:
if ansys_path is None:
from ansys.dpf.core.misc import __ansys_version__

ansys_path = os.environ.get("AWP_ROOT" + str(__ansys_version__), None)
if ansys_path is not None:
sub_folders = os.path.join(ansys_path, _get_path_in_install())
os.environ["PATH"] += sub_folders
return GrpcServer
elif config.protocol == CommunicationProtocols.InProcess and not config.legacy:
return InProcessServer
Expand Down
26 changes: 18 additions & 8 deletions src/ansys/dpf/core/server_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import os
import socket
import subprocess
import sys
import time
import warnings
import traceback
Expand Down Expand Up @@ -927,14 +928,7 @@ def __init__(
# Forced to use ctypes to get the updated PATH due to sys.exec not the Python
# interpreter when running Python plugin test VS project
# The better solution would be to not need to update the path
windll.kernel32.GetEnvironmentVariableA.argtypes = (c_char_p, c_char_p, c_int)
windll.kernel32.GetEnvironmentVariableA.restype = c_int
name = "PATH"
b_name = name.encode("utf-8")
size = 32767
buffer = create_string_buffer(b"", size)
_ = windll.kernel32.GetEnvironmentVariableA(b_name, buffer, size)
os.environ["PATH"] = buffer.value.decode("utf-8")
os.environ["PATH"] = get_system_path()

@property
def version(self):
Expand Down Expand Up @@ -977,6 +971,22 @@ def config(self):
return server_factory.AvailableServerConfigs.InProcessServer


def get_system_path() -> str:
"""Return the current PATH environment variable value of the system."""
if not os.name == "posix":
windll.kernel32.GetEnvironmentVariableA.argtypes = (c_char_p, c_char_p, c_int)
windll.kernel32.GetEnvironmentVariableA.restype = c_int
name = "PATH"
b_name = name.encode("utf-8")
size = 32767
buffer = create_string_buffer(b"", size)
_ = windll.kernel32.GetEnvironmentVariableA(b_name, buffer, size)
return buffer.value.decode("utf-8")
else:
return sys.path



class LegacyGrpcServer(BaseServer):
"""Provides an instance of the DPF server using InProcess gRPC.
Kept for backward-compatibility with dpf servers <0.5.0.
Expand Down
7 changes: 7 additions & 0 deletions tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@ def test_start_local_server(self, server_config):
assert has_local_server()
shutdown_all_session_servers()

def test_server_env_path_cleanup(self, server_config):
"""Test that running and stopping servers does not pollute the system PATH."""
from ansys.dpf.core.server_types import get_system_path
path_len_init = len(get_system_path())
_ = dpf.core.start_local_server(config=server_config)
assert len(get_system_path()) == path_len_init

def test_start_local_server_with_config(self, server_config):
set_server_configuration(None)
shutdown_all_session_servers()
Expand Down