Skip to content

Commit 8b40e24

Browse files
committed
cli: Add --runtime-type parameter
Required by kernelci/kernelci-pipeline#1396 Signed-off-by: Denys Fedoryshchenko <denys.f@collabora.com>
1 parent ccfd6a1 commit 8b40e24

File tree

1 file changed

+48
-11
lines changed

1 file changed

+48
-11
lines changed

kernelci/context/__init__.py

Lines changed: 48 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class KContext:
3737
config_paths: List of paths to configuration files/directories
3838
secrets_path: Path to the secrets TOML file
3939
runtimes: List of runtimes from CLI arguments
40+
runtime_types: List of runtime types from CLI arguments
4041
cli_args: Parsed CLI arguments if parse_cli=True was used
4142
"""
4243

@@ -61,8 +62,9 @@ def __init__( # pylint: disable=too-many-arguments
6162
if parse_cli:
6263
args = self._parse_cli_args()
6364

64-
# Initialize runtime list
65+
# Initialize runtime list and runtime types
6566
self.runtimes = []
67+
self.runtime_types = []
6668
self.cli_args = args if parse_cli else None
6769

6870
# Extract values from CLI arguments if provided
@@ -77,6 +79,8 @@ def __init__( # pylint: disable=too-many-arguments
7779
program_name = getattr(args, "name", None) or program_name
7880
# Handle --runtimes parameter
7981
self.runtimes = getattr(args, "runtimes", [])
82+
# Handle --runtime-type parameter
83+
self.runtime_types = getattr(args, "runtime_type", []) or []
8084

8185
# Set default paths if not provided
8286
if not config_paths:
@@ -117,30 +121,54 @@ def _parse_cli_args(self) -> argparse.Namespace:
117121
# Create a copy of sys.argv to avoid modifying the original
118122
argv = sys.argv[1:].copy() # Skip program name and make a copy
119123
runtimes = []
124+
runtime_types = []
120125

121126
# Find --runtimes and collect its values without modifying argv
122127
i = 0
128+
# Known commands that might appear after --runtimes in pipeline services
129+
# These are extracted from cmd_* class names found via:
130+
# grep "^class cmd_" kernelci-pipeline/src/*.py
131+
# Currently used: cmd_loop (scheduler.py), cmd_run (other services)
132+
# Keep this in sync if new command classes are added
133+
known_commands = {'loop', 'run'}
123134
while i < len(argv):
124135
if argv[i] == "--runtimes":
125-
runtime_idx = i
126136
i += 1
127137
# Collect values until we hit another option or end
128138
while i < len(argv):
129-
# Stop at next option (starts with --) or certain known commands
139+
# Stop at next option (starts with --)
130140
if argv[i].startswith("--"):
131141
break
132-
# Also check if this looks like a command rather than a runtime
133-
# Common commands: loop, run, start, stop, etc.
134-
# For now, we'll just check if it contains common runtime patterns
135-
if "." in argv[i] or "-" in argv[i] or argv[i].startswith("k8s"):
136-
runtimes.append(argv[i])
137-
i += 1
138-
else:
139-
# This looks like a command, stop here
142+
# Stop if we encounter a known command
143+
if argv[i] in known_commands:
140144
break
145+
# Otherwise it's a runtime name, add it
146+
runtimes.append(argv[i])
147+
i += 1
141148
break
142149
i += 1
143150

151+
# Find --runtime-type and collect its values
152+
i = 0
153+
while i < len(argv):
154+
if argv[i] == "--runtime-type":
155+
i += 1
156+
# Collect values until we hit another option or end
157+
while i < len(argv):
158+
if argv[i].startswith("--"):
159+
break
160+
if argv[i] in known_commands:
161+
break
162+
# Valid runtime types: lava, kubernetes, docker, shell, pull_labs
163+
runtime_types.append(argv[i])
164+
i += 1
165+
break
166+
elif argv[i].startswith("--runtime-type="):
167+
runtime_types.append(argv[i].split("=", 1)[1])
168+
i += 1
169+
else:
170+
i += 1
171+
144172
# Create a custom namespace to store our values without consuming arguments
145173
args = argparse.Namespace()
146174

@@ -151,6 +179,7 @@ def _parse_cli_args(self) -> argparse.Namespace:
151179
args.config = None
152180
args.name = None
153181
args.runtimes = runtimes
182+
args.runtime_type = runtime_types
154183

155184
# Look for our specific arguments in argv
156185
i = 0
@@ -417,6 +446,14 @@ def get_runtimes(self) -> List[str]:
417446
"""
418447
return self.runtimes
419448

449+
def get_runtime_types(self) -> List[str]:
450+
"""Get list of runtime types from CLI arguments
451+
452+
Returns:
453+
List of runtime types (e.g., 'lava', 'kubernetes', 'docker', 'shell')
454+
"""
455+
return self.runtime_types
456+
420457
def get_cli_args(self) -> Optional[argparse.Namespace]:
421458
"""Get parsed CLI arguments if parse_cli was used
422459

0 commit comments

Comments
 (0)