From 7c62b7fbada6d07ec958642c35137722f7757ce0 Mon Sep 17 00:00:00 2001
From: Axel Farrugia <axel.farrugia@cea.fr>
Date: Wed, 5 Mar 2025 13:34:06 +0100
Subject: [PATCH] [Fix] copy_folder() function now create the parent directory
 before creating the symlink

---
 aidge_core/export_utils/code_generation.py | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/aidge_core/export_utils/code_generation.py b/aidge_core/export_utils/code_generation.py
index 42ae19f79..8b3bf65ed 100644
--- a/aidge_core/export_utils/code_generation.py
+++ b/aidge_core/export_utils/code_generation.py
@@ -44,7 +44,7 @@ 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, symlink=False):
+def copy_file(filename: Union[Path, str], dst_folder: Union[Path, str], 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.
     """
@@ -60,11 +60,16 @@ def copy_file(filename, dst_folder, symlink=False):
     else:
         shutil.copy(filename, dst_folder)
 
-def copy_folder(foldername, dst_folder, symlink=False):
+def copy_folder(foldername: Union[Path, str], dst_folder: Union[Path, str], 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 the parent directory doesn't exist, create it
+    parent_dir = Path(dst_folder).parent
+    if not os.path.exists(parent_dir):
+        os.makedirs(parent_dir)
+
     if symlink:
         os.symlink(foldername, dst_folder)
     else:
-- 
GitLab