Skip to content

Commit a35c784

Browse files
fix(slurm): make get_slurm_options astype optional and preserve default type. (#4267)
* fix(slurm): make get_slurm_options astype optional and preserve default type. * chore: adding changelog file 4267.fixed.md [dependabot-skip] * fix(slurm): allow non-integer SLURM option values by trying float then falling back to str --------- Co-authored-by: pyansys-ci-bot <[email protected]>
1 parent 0a510cf commit a35c784

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

doc/changelog.d/4267.fixed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Make get_slurm_options astype optional and preserve default type.

src/ansys/mapdl/core/launcher.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2066,7 +2066,7 @@ def get_value(
20662066
variable: str,
20672067
kwargs: Dict[str, str],
20682068
default: Optional[Union[str, int, float]] = 1,
2069-
astype: Optional[Callable[[Any], Any]] = int,
2069+
astype: Optional[Callable[[Any], Any]] = None,
20702070
) -> str | int | float:
20712071
value_from_env_vars = os.environ.get(variable)
20722072
value_from_kwargs = kwargs.pop(variable, None)
@@ -2077,8 +2077,13 @@ def get_value(
20772077

20782078
if astype and value:
20792079
return astype(value)
2080+
elif default is not None:
2081+
return type(default)(value)
20802082
else:
2081-
return value
2083+
try:
2084+
return float(value)
2085+
except ValueError:
2086+
return str(value)
20822087

20832088
## Getting env vars
20842089
SLURM_NNODES = get_value("SLURM_NNODES", kwargs)
@@ -2112,7 +2117,7 @@ def get_value(
21122117
LOG.info(f"SLURM_MEM_PER_NODE: {SLURM_MEM_PER_NODE}")
21132118

21142119
SLURM_NODELIST = str(
2115-
get_value("SLURM_NODELIST", kwargs, default="") # type: ignore
2120+
get_value("SLURM_NODELIST", kwargs, default="", astype=str) # type: ignore
21162121
).lower() # type: ignore
21172122
LOG.info(f"SLURM_NODELIST: {SLURM_NODELIST}")
21182123

0 commit comments

Comments
 (0)