@@ -163,14 +163,15 @@ def get_active_network(namespace):
163
163
164
164
@click .command (context_settings = {"ignore_unknown_options" : True })
165
165
@click .argument ("scenario_file" , type = click .Path (exists = True , file_okay = True , dir_okay = False ))
166
+ @click .option ("--source_dir" , type = click .Path (exists = True , file_okay = False , dir_okay = True ), required = False )
166
167
@click .argument ("additional_args" , nargs = - 1 , type = click .UNPROCESSED )
167
- def run (scenario_file : str , additional_args : tuple [str ]):
168
+ def run (scenario_file : str , source_dir , additional_args : tuple [str ]):
168
169
"""
169
170
Run a scenario from a file.
170
171
Pass `-- --help` to get individual scenario help
171
172
"""
172
173
scenario_path = Path (scenario_file ).resolve ()
173
- scenario_dir = scenario_path .parent
174
+ scenario_dir = scenario_path .parent if not source_dir else Path ( source_dir ). resolve ()
174
175
scenario_name = scenario_path .stem
175
176
176
177
if additional_args and ("--help" in additional_args or "-h" in additional_args ):
@@ -203,15 +204,24 @@ def run(scenario_file: str, additional_args: tuple[str]):
203
204
def filter (path ):
204
205
if any (needle in str (path ) for needle in [".pyc" , ".csv" , ".DS_Store" ]):
205
206
return False
206
- return any (
207
- needle in str (path ) for needle in ["commander.py" , "test_framework" , scenario_name ]
208
- )
209
-
207
+ if any (needle in str (path ) for needle in ["__init__.py" , "commander.py" , "test_framework" , scenario_path .name ]):
208
+ print (f"Including: { path } " )
209
+ return True
210
+ return False
211
+
212
+ # In case the scenario file is not in the root of the archive directory,
213
+ # we need to specify its relative path as a submodule
214
+ # First get the path of the file relative to the source directory
215
+ relative_path = scenario_path .relative_to (scenario_dir )
216
+ # Remove the '.py' extension
217
+ relative_name = relative_path .with_suffix ("" )
218
+ # Replace path separators with dots and pray the user included __init__.py
219
+ module_name = "." .join (relative_name .parts )
210
220
# Compile python archive
211
221
zipapp .create_archive (
212
222
source = scenario_dir ,
213
223
target = archive_buffer ,
214
- main = f"{ scenario_name } :main" ,
224
+ main = f"{ module_name } :main" ,
215
225
compressed = True ,
216
226
filter = filter ,
217
227
)
0 commit comments