diff --git a/aidge_core/export_utils/__init__.py b/aidge_core/export_utils/__init__.py index 72472eee0b6850ea76c70253e4fa953ac5785f84..a14fc63b1a3ba41f965e74c7f5f1e83d42c0633d 100644 --- a/aidge_core/export_utils/__init__.py +++ b/aidge_core/export_utils/__init__.py @@ -1,5 +1,5 @@ from .node_export import ExportNode, ExportNodeCpp -from .code_generation import generate_file, generate_str, copy_file +from .code_generation import generate_file, generate_str, copy_file, copy_folder from .export_registry import ExportLib from .scheduler_export import scheduler_export from .tensor_export import tensor_to_c, generate_input_file diff --git a/aidge_core/export_utils/code_generation.py b/aidge_core/export_utils/code_generation.py index 4f0f4634dd8ac09c8c0a86506dc52d420889b22a..42ae19f7937a3a45ace65ad708a44aac5a199405 100644 --- a/aidge_core/export_utils/code_generation.py +++ b/aidge_core/export_utils/code_generation.py @@ -44,10 +44,29 @@ def generate_str(template_path: Union[Path, str], **kwargs) -> str: return Environment(loader=FileSystemLoader( template_path.parent), undefined=StrictUndefined, keep_trailing_newline=True).get_template(template_path.name).render(kwargs) -def copy_file(filename, dst_folder): +def copy_file(filename, dst_folder, symlink=False): + """Copy the given file into the given dst path + The symlink arg allows to make a symbolic link instead of copying the file. + """ # If directory doesn't exist, create it if not os.path.exists(dst_folder): os.makedirs(dst_folder) - shutil.copy(filename, dst_folder) + if symlink: + dst_folder += "/" + os.path.basename(filename) + if not os.path.exists(dst_folder): + os.symlink(filename, dst_folder) + else: + shutil.copy(filename, dst_folder) + +def copy_folder(foldername, dst_folder, symlink=False): + """Copy the given folder into the given dst path + The symlink arg allows to make a symbolic link instead of copying the file. + """ + + if symlink: + os.symlink(foldername, dst_folder) + else: + shutil.copytree(foldername, dst_folder, dirs_exist_ok=True) + \ No newline at end of file diff --git a/aidge_core/export_utils/export_registry.py b/aidge_core/export_utils/export_registry.py index 8927ae5169978da81e39912ebd4e26e2655137ad..01329e6a5d1f771e8af1235e22d105b1e58db332 100644 --- a/aidge_core/export_utils/export_registry.py +++ b/aidge_core/export_utils/export_registry.py @@ -40,6 +40,9 @@ class ExportLib(aidge_core.OperatorImpl): # key: Path where static file is # Value: Path where to copy the file relative to the export root static_files: Dict[str, str] = {} + # key: Path where static folder is + # Value: Path where to copy the folder relative to the export root + static_folders: Dict[str, str] = {} # Main memory section mem_section = None # Custom forward generation jinja file diff --git a/aidge_core/export_utils/scheduler_export.py b/aidge_core/export_utils/scheduler_export.py index 8aaedc18d8622e243f237785fd9d3b7f907d65fd..aaca6b76ae082cf137fd21000d59f5a78feb91d9 100644 --- a/aidge_core/export_utils/scheduler_export.py +++ b/aidge_core/export_utils/scheduler_export.py @@ -2,7 +2,7 @@ import aidge_core import os import shutil from pathlib import Path -from aidge_core.export_utils import ExportLib, generate_file, copy_file +from aidge_core.export_utils import ExportLib, generate_file, copy_file, copy_folder from typing import List, Tuple @@ -208,4 +208,8 @@ def scheduler_export(scheduler, export_folder_path: str, export_lib: ExportLib = if export_lib is not None: # Copy all static files in the export for source, destination in export_lib.static_files.items(): - copy_file(source, str(export_folder / destination)) + copy_file(source, str(export_folder / destination), test_mode) + + # Copy all static folders in the export + for source, destination in export_lib.static_folders.items(): + copy_folder(source, str(export_folder / destination), test_mode)