Create a python module from a list of files by copying them to the destination directory. Args: file_list (List[str]): List of relative file paths to be copied. file_prefix (str): Path prefix for each file in file_list. module_name (str): Name of the module. Re
(file_list, file_prefix, module_name)
| 340 | |
| 341 | |
| 342 | def create_module_from_files(file_list, file_prefix, module_name): |
| 343 | """ |
| 344 | Create a python module from a list of files by copying them to the destination directory. |
| 345 | |
| 346 | Args: |
| 347 | file_list (List[str]): List of relative file paths to be copied. |
| 348 | file_prefix (str): Path prefix for each file in file_list. |
| 349 | module_name (str): Name of the module. |
| 350 | |
| 351 | Returns: |
| 352 | None |
| 353 | """ |
| 354 | |
| 355 | def create_empty_file(file_path): |
| 356 | with open(file_path, 'w') as _: |
| 357 | pass |
| 358 | |
| 359 | dest_dir = os.path.join(BASE_MODULE_DIR, module_name) |
| 360 | for file_path in file_list: |
| 361 | file_dir = os.path.dirname(file_path) |
| 362 | target_dir = os.path.join(dest_dir, file_dir) |
| 363 | os.makedirs(target_dir, exist_ok=True) |
| 364 | init_file = os.path.join(target_dir, '__init__.py') |
| 365 | if not os.path.exists(init_file): |
| 366 | create_empty_file(init_file) |
| 367 | |
| 368 | target_file = os.path.join(target_dir, os.path.basename(file_path)) |
| 369 | src_file = os.path.join(file_prefix, file_path) |
| 370 | if not os.path.exists(target_file) or not filecmp.cmp( |
| 371 | src_file, target_file): |
| 372 | shutil.copyfile(src_file, target_file) |
| 373 | |
| 374 | importlib.invalidate_caches() |
| 375 | |
| 376 | |
| 377 | def import_module_from_model_dir(model_dir): |
no test coverage detected
searching dependent graphs…