Skip to content

Commit 8a01771

Browse files
RyanJWardrwardpyansys-ci-bot
authored
feat: set current working dir for linux (#2349)
Co-authored-by: rward <[email protected]> Co-authored-by: pyansys-ci-bot <[email protected]>
1 parent 3069acb commit 8a01771

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

doc/changelog.d/2349.added.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Set current working dir for linux

src/ansys/geometry/core/connection/product_instance.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ def prepare_and_start_backend(
191191
client_log_file: str = None,
192192
specific_minimum_version: int = None,
193193
product_version: int | None = None, # Deprecated, use `version` instead.
194+
cwd: str | Path | None = None, # New: working directory for subprocess
194195
) -> "Modeler":
195196
"""Start the requested service locally using the ``ProductInstance`` class.
196197
@@ -493,6 +494,7 @@ def prepare_and_start_backend(
493494
CORE_GEOMETRY_SERVICE_EXE.replace(".exe", ".dll"),
494495
)
495496
)
497+
cwd = root_service_folder # ensure working directory also for dotnet case
496498
else:
497499
# For Linux, we need to use the exe file to launch the Core Geometry Service
498500
args.append(
@@ -501,6 +503,7 @@ def prepare_and_start_backend(
501503
CORE_GEOMETRY_SERVICE_EXE.replace(".exe", ""),
502504
)
503505
)
506+
cwd = root_service_folder
504507
else:
505508
raise RuntimeError(
506509
f"Cannot connect to backend {backend_type.name} using ``prepare_and_start_backend()``"
@@ -510,7 +513,7 @@ def prepare_and_start_backend(
510513
LOG.debug(f"Args: {args}")
511514
LOG.debug(f"Environment variables: {env_copy}")
512515

513-
instance = ProductInstance(__start_program(args, env_copy).pid)
516+
instance = ProductInstance(__start_program(args, env_copy, cwd=cwd).pid)
514517

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

616619

617-
def __start_program(args: list[str], local_env: dict[str, str]) -> subprocess.Popen:
620+
def __start_program(
621+
args: list[str],
622+
local_env: dict[str, str],
623+
cwd: str | os.PathLike | None = None, # New parameter
624+
) -> subprocess.Popen:
618625
"""Start the program.
619626
620627
Parameters
@@ -624,6 +631,8 @@ def __start_program(args: list[str], local_env: dict[str, str]) -> subprocess.Po
624631
be the program path.
625632
local_env : dict[str,str]
626633
Environment variables to be passed to the program.
634+
cwd : str | Path, optional
635+
Working directory for the launched process.
627636
628637
Returns
629638
-------
@@ -641,6 +650,7 @@ def __start_program(args: list[str], local_env: dict[str, str]) -> subprocess.Po
641650
stdout=subprocess.DEVNULL,
642651
stderr=subprocess.DEVNULL,
643652
env=local_env,
653+
cwd=str(cwd) if cwd is not None else None,
644654
)
645655

646656

0 commit comments

Comments
 (0)