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
1 change: 1 addition & 0 deletions doc/changelog.d/2349.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Set current working dir for linux
14 changes: 12 additions & 2 deletions src/ansys/geometry/core/connection/product_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ def prepare_and_start_backend(
client_log_file: str = None,
specific_minimum_version: int = None,
product_version: int | None = None, # Deprecated, use `version` instead.
cwd: str | Path | None = None, # New: working directory for subprocess
) -> "Modeler":
"""Start the requested service locally using the ``ProductInstance`` class.

Expand Down Expand Up @@ -493,6 +494,7 @@ def prepare_and_start_backend(
CORE_GEOMETRY_SERVICE_EXE.replace(".exe", ".dll"),
)
)
cwd = root_service_folder # ensure working directory also for dotnet case
else:
# For Linux, we need to use the exe file to launch the Core Geometry Service
args.append(
Expand All @@ -501,6 +503,7 @@ def prepare_and_start_backend(
CORE_GEOMETRY_SERVICE_EXE.replace(".exe", ""),
)
)
cwd = root_service_folder
else:
raise RuntimeError(
f"Cannot connect to backend {backend_type.name} using ``prepare_and_start_backend()``"
Expand All @@ -510,7 +513,7 @@ def prepare_and_start_backend(
LOG.debug(f"Args: {args}")
LOG.debug(f"Environment variables: {env_copy}")

instance = ProductInstance(__start_program(args, env_copy).pid)
instance = ProductInstance(__start_program(args, env_copy, cwd=cwd).pid)

# Verify that the backend is ready to accept connections
# before returning the Modeler instance.
Expand Down Expand Up @@ -614,7 +617,11 @@ def _manifest_path_provider(
raise RuntimeError(msg)


def __start_program(args: list[str], local_env: dict[str, str]) -> subprocess.Popen:
def __start_program(
args: list[str],
local_env: dict[str, str],
cwd: str | os.PathLike | None = None, # New parameter
) -> subprocess.Popen:
"""Start the program.

Parameters
Expand All @@ -624,6 +631,8 @@ def __start_program(args: list[str], local_env: dict[str, str]) -> subprocess.Po
be the program path.
local_env : dict[str,str]
Environment variables to be passed to the program.
cwd : str | Path, optional
Working directory for the launched process.

Returns
-------
Expand All @@ -641,6 +650,7 @@ def __start_program(args: list[str], local_env: dict[str, str]) -> subprocess.Po
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
env=local_env,
cwd=str(cwd) if cwd is not None else None,
)


Expand Down
Loading