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/3817.miscellaneous.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
feat: inject additional MAPDL command line arguments through an env var
34 changes: 34 additions & 0 deletions src/ansys/mapdl/core/launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -1437,6 +1437,12 @@
cleanup_on_exit=args["cleanup_on_exit"], version=args["version"]
)

########################################
# Additional switches injection
# -----------------------------
#
args = inject_additional_switches(args)

########################################
# SLURM settings
# --------------
Expand Down Expand Up @@ -2893,3 +2899,31 @@
start_parm.pop(each)

return start_parm


def inject_additional_switches(args: dict[str, Any]) -> dict[str, Any]:
"""Inject additional switches to the command line

Parameters
----------
args : Dict[str, Any]
Arguments dictionary

Returns
-------
Dict[str, Any]
Arguments dictionary with the additional switches injected
"""
envvaras = os.environ.get("PYMAPDL_ADDITIONAL_SWITCHES")

if envvaras:
if args.get("additional_switches"):
args["additional_switches"] += f" {envvaras}"
else:
args["additional_switches"] = envvaras

Check warning on line 2923 in src/ansys/mapdl/core/launcher.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/mapdl/core/launcher.py#L2923

Added line #L2923 was not covered by tests

LOG.debug(
f"Injecting additional switches from 'PYMAPDL_ADDITIONAL_SWITCHES' env var: {envvaras}"
)

return args
14 changes: 14 additions & 0 deletions tests/test_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
get_slurm_options,
get_start_instance,
get_version,
inject_additional_switches,
is_running_on_slurm,
kill_job,
launch_grpc,
Expand Down Expand Up @@ -2079,3 +2080,16 @@ def test_create_queue_for_std_no_queue():
from ansys.mapdl.core.launcher import _create_queue_for_std

assert _create_queue_for_std(None) == (None, None)


def test_inject_additional_switches(monkeypatch):
"""
Test the inject_additional_switches function.
"""
envvar = "-my-add=switch --other_switch -b"
monkeypatch.setenv("PYMAPDL_ADDITIONAL_SWITCHES", envvar)
args = {"additional_switches": "-my_add=switch --other_switch -b"}

new_args = inject_additional_switches(args)
assert args["additional_switches"] in new_args["additional_switches"]
assert envvar in new_args["additional_switches"]