Skip to content

Conversation

@germa89
Copy link
Collaborator

@germa89 germa89 commented Oct 20, 2025

Description

Fix open_gui method.

  • Add env_vars to start_parm in launch_mapdl so environment vars are carried in generated start parameters.
  • Replace import from ansys.mapdl.core.launcher with package-level get_mapdl_path to prevent circular imports.
  • Update MapdlGrpc._launch signature to accept an optional start_parm, use it when provided, and call _connect() without passing the port explicitly.

Issue linked

Close #3993
Close #4269

Checklist

- Add typed exec_file parameter to open_gui and document its behavior.
- Defer importing get_mapdl_path and only attempt to resolve the MAPDL
  executable when ansys.mapdl.core ATP helper is available.
- Use start_parm exec_file if provided, otherwise try get_mapdl_path; raise
  a clear MapdlRuntimeError if no executable path can be determined.
- Minor docstring/format tweaks.
…mport, and make MapdlGrpc._launch accept start_parm

- Add env_vars to start_parm in launch_mapdl so environment vars are carried in generated start parameters.
- Replace import from ansys.mapdl.core.launcher with package-level get_mapdl_path to prevent circular imports.
- Update MapdlGrpc._launch signature to accept an optional start_parm, use it when provided, and call _connect() without passing the port explicitly.
@germa89 germa89 requested a review from a team as a code owner October 20, 2025 16:36
@germa89 germa89 self-assigned this Oct 20, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes the open_gui method by ensuring environment variables are properly propagated and preventing circular import issues.

Key Changes:

  • Environment variables are now added to start parameters in launch_mapdl
  • Import path changed to use package-level get_mapdl_path to avoid circular imports
  • MapdlGrpc._launch signature updated to accept optional start parameters

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/ansys/mapdl/core/launcher.py Adds env_vars to start_parm dictionary to preserve environment variables
src/ansys/mapdl/core/mapdl_grpc.py Updates _launch method signature to accept optional start_parm and removes explicit port parameter from _connect call
src/ansys/mapdl/core/mapdl_core.py Adds exec_file parameter to open_gui, replaces import to avoid circular dependency, and adds error handling for missing executable path

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@github-actions github-actions bot added the bug Issue, problem or error in PyMAPDL label Oct 20, 2025
@germa89 germa89 requested a review from mikerife October 20, 2025 16:37
@germa89 germa89 enabled auto-merge (squash) October 20, 2025 16:38
@codecov
Copy link

codecov bot commented Oct 20, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.37%. Comparing base (0a510cf) to head (3fbca2f).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4270      +/-   ##
==========================================
+ Coverage   91.05%   91.37%   +0.31%     
==========================================
  Files         193      193              
  Lines       15720    15721       +1     
==========================================
+ Hits        14314    14365      +51     
+ Misses       1406     1356      -50     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

…apdlGrpc._launch and open_gui flow

Add unit tests to verify:
- env_vars are propagated into start_parm when launching MAPDL
- SLURM-specific bootstrap vars are injected when launching on HPC (replace_env_vars)
- MapdlGrpc._launch prefers a provided start_parm over the instance _start_parm
- open_gui invokes the correct executable and flags (mocking subprocess.call)
- complete open_gui flow calls expected lifecycle methods and reconnects via _launch

These tests exercise env propagation, command building, and reconnection behavior for launcher and gRPC flows.
- add MagicMock and Mock imports used across tests
- update test_env_vars_with_slurm_bootstrap to call launch_mapdl(...) with replace_env_vars and remove unused assignment
- remove duplicate/unnecessary imports in tests
- correctly bind MapdlGrpc._launch when testing provided start_parm
- simplify exception handlers (avoid unused exception variable)
- add assertion to ensure _cache_routine() is called during open_gui reconnection flow
…mapdl lifecycle methods and using ExitStack to manage patches
… call

- remove @requires("local") from open_gui tests so they don't depend on local env
- mock mapdl._local, pathlib.Path.is_file and ansys.mapdl.core.mapdl_core.call (instead of subprocess.call)
- use ExitStack / nested context managers to manage patches and keep test isolation
- ensure original mapdl._launch is restored after the test
Add # nosec B703 to broad except handlers in tests to silence bandit warnings.
Remove redundant MagicMock imports and eliminate unused "run_location" keys
from test payloads to clean up and simplify test_launcher.py.
@germa89
Copy link
Collaborator Author

germa89 commented Oct 23, 2025

@pyansys-ci-bot LGTM.

Copy link
Contributor

@pyansys-ci-bot pyansys-ci-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Approving this PR because germa89 said so in here 😬

LGTM

@germa89 germa89 merged commit a9b1394 into main Oct 23, 2025
87 of 88 checks passed
@germa89 germa89 deleted the fix/open_gui branch October 23, 2025 16:52
clatapie pushed a commit that referenced this pull request Oct 27, 2025
* feat(core): add exec_file param to open_gui and improve execable lookup

- Add typed exec_file parameter to open_gui and document its behavior.
- Defer importing get_mapdl_path and only attempt to resolve the MAPDL
  executable when ansys.mapdl.core ATP helper is available.
- Use start_parm exec_file if provided, otherwise try get_mapdl_path; raise
  a clear MapdlRuntimeError if no executable path can be determined.
- Minor docstring/format tweaks.

* fix(core): propagate env_vars into start parameters, avoid circular import, and make MapdlGrpc._launch accept start_parm

- Add env_vars to start_parm in launch_mapdl so environment vars are carried in generated start parameters.
- Replace import from ansys.mapdl.core.launcher with package-level get_mapdl_path to prevent circular imports.
- Update MapdlGrpc._launch signature to accept an optional start_parm, use it when provided, and call _connect() without passing the port explicitly.
clatapie pushed a commit that referenced this pull request Nov 5, 2025
* feat(core): add exec_file param to open_gui and improve execable lookup

- Add typed exec_file parameter to open_gui and document its behavior.
- Defer importing get_mapdl_path and only attempt to resolve the MAPDL
  executable when ansys.mapdl.core ATP helper is available.
- Use start_parm exec_file if provided, otherwise try get_mapdl_path; raise
  a clear MapdlRuntimeError if no executable path can be determined.
- Minor docstring/format tweaks.

* fix(core): propagate env_vars into start parameters, avoid circular import, and make MapdlGrpc._launch accept start_parm

- Add env_vars to start_parm in launch_mapdl so environment vars are carried in generated start parameters.
- Replace import from ansys.mapdl.core.launcher with package-level get_mapdl_path to prevent circular imports.
- Update MapdlGrpc._launch signature to accept an optional start_parm, use it when provided, and call _connect() without passing the port explicitly.
clatapie pushed a commit that referenced this pull request Nov 18, 2025
* feat(core): add exec_file param to open_gui and improve execable lookup

- Add typed exec_file parameter to open_gui and document its behavior.
- Defer importing get_mapdl_path and only attempt to resolve the MAPDL
  executable when ansys.mapdl.core ATP helper is available.
- Use start_parm exec_file if provided, otherwise try get_mapdl_path; raise
  a clear MapdlRuntimeError if no executable path can be determined.
- Minor docstring/format tweaks.

* fix(core): propagate env_vars into start parameters, avoid circular import, and make MapdlGrpc._launch accept start_parm

- Add env_vars to start_parm in launch_mapdl so environment vars are carried in generated start parameters.
- Replace import from ansys.mapdl.core.launcher with package-level get_mapdl_path to prevent circular imports.
- Update MapdlGrpc._launch signature to accept an optional start_parm, use it when provided, and call _connect() without passing the port explicitly.
clatapie pushed a commit that referenced this pull request Nov 21, 2025
* feat(core): add exec_file param to open_gui and improve execable lookup

- Add typed exec_file parameter to open_gui and document its behavior.
- Defer importing get_mapdl_path and only attempt to resolve the MAPDL
  executable when ansys.mapdl.core ATP helper is available.
- Use start_parm exec_file if provided, otherwise try get_mapdl_path; raise
  a clear MapdlRuntimeError if no executable path can be determined.
- Minor docstring/format tweaks.

* fix(core): propagate env_vars into start parameters, avoid circular import, and make MapdlGrpc._launch accept start_parm

- Add env_vars to start_parm in launch_mapdl so environment vars are carried in generated start parameters.
- Replace import from ansys.mapdl.core.launcher with package-level get_mapdl_path to prevent circular imports.
- Update MapdlGrpc._launch signature to accept an optional start_parm, use it when provided, and call _connect() without passing the port explicitly.
clatapie pushed a commit that referenced this pull request Nov 21, 2025
* feat(core): add exec_file param to open_gui and improve execable lookup

- Add typed exec_file parameter to open_gui and document its behavior.
- Defer importing get_mapdl_path and only attempt to resolve the MAPDL
  executable when ansys.mapdl.core ATP helper is available.
- Use start_parm exec_file if provided, otherwise try get_mapdl_path; raise
  a clear MapdlRuntimeError if no executable path can be determined.
- Minor docstring/format tweaks.

* fix(core): propagate env_vars into start parameters, avoid circular import, and make MapdlGrpc._launch accept start_parm

- Add env_vars to start_parm in launch_mapdl so environment vars are carried in generated start parameters.
- Replace import from ansys.mapdl.core.launcher with package-level get_mapdl_path to prevent circular imports.
- Update MapdlGrpc._launch signature to accept an optional start_parm, use it when provided, and call _connect() without passing the port explicitly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Issue, problem or error in PyMAPDL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

get_mapdl_path not found in open_gui open_gui() blocks Python console and doesn't return control after GUI is closed

3 participants