diff --git a/kernelci/context/__init__.py b/kernelci/context/__init__.py index a8e262de08..4742a89140 100644 --- a/kernelci/context/__init__.py +++ b/kernelci/context/__init__.py @@ -37,6 +37,7 @@ class KContext: config_paths: List of paths to configuration files/directories secrets_path: Path to the secrets TOML file runtimes: List of runtimes from CLI arguments + runtime_types: List of runtime types from CLI arguments cli_args: Parsed CLI arguments if parse_cli=True was used """ @@ -61,8 +62,9 @@ def __init__( # pylint: disable=too-many-arguments if parse_cli: args = self._parse_cli_args() - # Initialize runtime list + # Initialize runtime list and runtime types self.runtimes = [] + self.runtime_types = [] self.cli_args = args if parse_cli else None # Extract values from CLI arguments if provided @@ -77,6 +79,8 @@ def __init__( # pylint: disable=too-many-arguments program_name = getattr(args, "name", None) or program_name # Handle --runtimes parameter self.runtimes = getattr(args, "runtimes", []) + # Handle --runtime-type parameter + self.runtime_types = getattr(args, "runtime_type", []) or [] # Set default paths if not provided if not config_paths: @@ -117,12 +121,12 @@ def _parse_cli_args(self) -> argparse.Namespace: # Create a copy of sys.argv to avoid modifying the original argv = sys.argv[1:].copy() # Skip program name and make a copy runtimes = [] + runtime_types = [] # Find --runtimes and collect its values without modifying argv i = 0 while i < len(argv): if argv[i] == "--runtimes": - runtime_idx = i i += 1 # Collect values until we hit another option or end while i < len(argv): @@ -141,6 +145,25 @@ def _parse_cli_args(self) -> argparse.Namespace: break i += 1 + # Find --runtime-type and collect its values + i = 0 + while i < len(argv): + if argv[i] == "--runtime-type": + i += 1 + # Collect values until we hit another option or end + while i < len(argv): + if argv[i].startswith("--"): + break + # Valid runtime types: lava, kubernetes, docker, shell, pull_labs + runtime_types.append(argv[i]) + i += 1 + break + elif argv[i].startswith("--runtime-type="): + runtime_types.append(argv[i].split("=", 1)[1]) + i += 1 + else: + i += 1 + # Create a custom namespace to store our values without consuming arguments args = argparse.Namespace() @@ -151,6 +174,7 @@ def _parse_cli_args(self) -> argparse.Namespace: args.config = None args.name = None args.runtimes = runtimes + args.runtime_type = runtime_types # Look for our specific arguments in argv i = 0 @@ -417,6 +441,14 @@ def get_runtimes(self) -> List[str]: """ return self.runtimes + def get_runtime_types(self) -> List[str]: + """Get list of runtime types from CLI arguments + + Returns: + List of runtime types (e.g., 'lava', 'kubernetes', 'docker', 'shell') + """ + return self.runtime_types + def get_cli_args(self) -> Optional[argparse.Namespace]: """Get parsed CLI arguments if parse_cli was used