From d87f3dafba3c6586849fe24533ab11bdfc1ae92c Mon Sep 17 00:00:00 2001 From: Andrei Maslennikov Date: Fri, 20 Mar 2026 08:59:48 +0100 Subject: [PATCH] Do not run CommandShell check during object creation --- src/cloudai/systems/slurm/slurm_system.py | 2 +- src/cloudai/util/command_shell.py | 28 ++++------------------- 2 files changed, 6 insertions(+), 24 deletions(-) diff --git a/src/cloudai/systems/slurm/slurm_system.py b/src/cloudai/systems/slurm/slurm_system.py index 2ec73b6fb..296befa71 100644 --- a/src/cloudai/systems/slurm/slurm_system.py +++ b/src/cloudai/systems/slurm/slurm_system.py @@ -106,7 +106,7 @@ class SlurmSystem(System): cache_docker_images_locally: bool = False scheduler: str = "slurm" monitor_interval: int = 60 - cmd_shell: CommandShell = Field(default=CommandShell(), exclude=True) + cmd_shell: CommandShell = Field(default_factory=CommandShell, exclude=True) extra_srun_args: Optional[str] = None extra_sbatch_args: list[str] = Field(default_factory=list) supports_gpu_directives_cache: Optional[bool] = Field(default=None, exclude=True) diff --git a/src/cloudai/util/command_shell.py b/src/cloudai/util/command_shell.py index 86358498b..1fb2d5a42 100644 --- a/src/cloudai/util/command_shell.py +++ b/src/cloudai/util/command_shell.py @@ -1,5 +1,5 @@ # SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES -# Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# Copyright (c) 2024, 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: Apache-2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -27,32 +27,14 @@ class CommandShell: """ def __init__(self, executable: Path = Path("/bin/bash")): - """ - Initialize the CommandShell with a shell executable. - - Args: - executable (Path): The shell executable path. Defaults to Path("/bin/bash"). - - Raises: - FileNotFoundError: If the specified executable does not exist. - """ - if not executable.exists(): - raise FileNotFoundError(f"Executable '{executable}' not found.") + """Initialize the CommandShell with a shell executable.""" self.executable = executable def execute(self, command: str) -> subprocess.Popen: - """ - Execute a shell command and return its process. - - Args: - command (str): The command to be executed. - - Returns: - subprocess.Popen: The process object for the executed command. + """Execute a shell command and return its process.""" + if not self.executable.exists(): + raise FileNotFoundError(f"Executable '{self.executable}' not found.") - Raises: - subprocess.CalledProcessError: If command execution fails. - """ process = subprocess.Popen( command, shell=True,