@@ -27,6 +27,7 @@ def __init__(self,
2727 ignored_dirs : List [str ] = None ,
2828 build_directory : str = "build" ,
2929 other_files_needed : List [str ] = None ,
30+ other_dirs_needed : List [str ] = None ,
3031 ignored_files : List [str ] = None ,
3132 project_name : str = "" ,
3233 project_author : str = "author" ,
@@ -38,6 +39,7 @@ def __init__(self,
3839 :param ignored_dirs: list[str] -> a list of directories to ignore while building for example the env variables.
3940 :param build_directory: path to the build output directory.
4041 :param other_files_needed: files to copy to the build directory like the env file or manage.py script.
42+ :param other_dirs_needed: dirs to copy to the build directory like the static dir and media dir.
4143 :param c_dir: a path to the C files output.
4244 """
4345 if ignored_dirs is None :
@@ -46,10 +48,13 @@ def __init__(self,
4648 ignored_files = []
4749 if other_files_needed is None :
4850 other_files_needed = []
51+ if other_dirs_needed is None :
52+ other_dirs_needed = []
4953 self .ignored_dirs = ignored_dirs
5054 self .ignored_files = ignored_files
5155 self .build_directory = build_directory
5256 self .other_files_needed = other_files_needed
57+ self .other_dirs_needed = other_dirs_needed
5358 self .project_name = project_name
5459 self .project_author = project_author
5560 self .project_version = project_version
@@ -115,9 +120,33 @@ def copy_migrations_to_build(self):
115120 print (f"building migration file { migration_path } " )
116121 shutil .copytree (f"{ dir_path } " , migration_path )
117122
118- def inital_python_modules (self ):
123+ def copy_needed_dirs (self , dirs : list = None ):
124+ if dirs is None :
125+ dirs = self .other_dirs_needed
126+ print ("#################### Copy Needed Dirs ####################" )
127+ for dir_path in dirs :
128+ build_dir_path : str = f"./{ self .build_directory } /{ dir_path } "
129+ if self .check_ignored_dirs (path_name = dir_path ):
130+ continue
131+ try :
132+ shutil .copytree (f"{ dir_path } " , build_dir_path , dirs_exist_ok = True )
133+ print (f"Copy dir { dir_path } to build" )
134+ except FileNotFoundError as e :
135+ print (f"Couldn't copy directory { dir_path } to build directory" )
136+
137+ def python_modules_rules (self , path_name ):
138+ ignore_build_dir = path_name .endswith (f"/{ self .build_directory } " )
139+ ignore_temp_dirs = f"./{ self .build_directory } /temp." in f"{ path_name } /"
140+ for dir in self .other_dirs_needed :
141+ ignore_other_needed_dirs = f"./{ self .build_directory } /{ dir } " in f"{ path_name } /"
142+ if ignore_build_dir or ignore_temp_dirs or ignore_other_needed_dirs :
143+ return True
144+ return False
145+
146+ def initial_python_modules (self ):
147+ print ("#################### Initial Python Modules ####################" )
119148 for path , subdirs , files in os .walk (f"./{ self .build_directory } " ):
120- if path . endswith ( f"/ { self .build_directory } " ) or f"./ { self . build_directory } /temp." in path :
149+ if self .python_modules_rules ( path ) :
121150 continue
122151 f = open (f"{ path } /__init__.py" , "w" )
123152 f .close ()
@@ -128,18 +157,17 @@ def copy_needed_files(self, files: list = None):
128157 files = self .other_files_needed
129158 for file in files :
130159 try :
131- shutil .copy (file , f"./{ self .build_directory } " )
160+ shutil .copy (file , f"./{ self .build_directory } / { file } " )
132161 except FileNotFoundError :
133162 print (f"file { file } not found" )
134163 except FileExistsError :
135164 print (f"file { file } already copied" )
136165
137- def compile_project (self , ext_modules : Set [Extension ] = None ,
166+ def compile_modules (self , ext_modules : Set [Extension ] = None ,
138167 cython_dir : str = "cython" ,
139- compiler_directives : dict = None
140- ) -> None :
168+ compiler_directives : dict = None ) -> None :
141169 """
142- A function that compiles the django project
170+ A method that compile the python modules
143171 :param ext_modules: set[Extension]: not required -> files that should be compiled
144172 :param cython_dir: str -> the C files output dir.
145173 :param compiler_directives: dict -> extra compiler option [like the lanugae]
@@ -158,8 +186,27 @@ def compile_project(self, ext_modules: Set[Extension] = None,
158186 ext_modules = cythonize (ext_modules , build_dir = cython_dir ,
159187 compiler_directives = compiler_directives ,
160188 ),
161-
162189 )
190+
191+ def compile_project (self ) -> None :
192+ """
193+ A method that compiles the django project
194+ the method runs:
195+ compile_modules()
196+
197+ copy_migrations_to_build()
198+
199+ initial_python_modules()
200+
201+ copy_needed_files()
202+
203+ copy_needed_dirs()
204+
205+ methods
206+ :return: None
207+ """
208+ self .compile_modules ()
163209 self .copy_migrations_to_build ()
164- self .inital_python_modules ()
210+ self .initial_python_modules ()
165211 self .copy_needed_files ()
212+ self .copy_needed_dirs ()
0 commit comments