33
44import investing_algorithm_framework
55from investing_algorithm_framework .core .exceptions import ImproperlyConfigured
6- from investing_algorithm_framework .configuration .setup .template_creator import TemplateCreator
6+ from investing_algorithm_framework .configuration .setup .template_creator \
7+ import TemplateCreator
78
89
910class DefaultProjectCreator (TemplateCreator ):
@@ -15,24 +16,32 @@ def configure(self) -> None:
1516 bot_dir = os .path .join (self ._bot_project_directory , self ._bot_name )
1617
1718 if os .path .exists (bot_dir ):
18- raise ImproperlyConfigured ("Project destination directory {} already exists" .format (self ._bot_name ))
19+ raise ImproperlyConfigured ("Project destination directory {} "
20+ "already exists" .format (self ._bot_name ))
1921
2022 def create (self ) -> None :
2123
2224 # Find the default template directory
23- template_dir = os .path .join (investing_algorithm_framework .__path__ [0 ], self .TEMPLATE_ROOT_DIR )
25+ template_dir = os .path .join (
26+ investing_algorithm_framework .__path__ [0 ], self .TEMPLATE_ROOT_DIR
27+ )
2428
2529 for root , dirs , files in os .walk (template_dir ):
2630
2731 # Get the last part of the path
2832 # This is used as the basis for the copying
2933 path_rest = root [len (template_dir ) + 1 :]
3034
31- # Replace template investing_algorithm_framework directory with given investing_algorithm_framework name
32- path_rest = path_rest .replace (self .PROJECT_TEMPLATE_DIR_NAME , self ._bot_name )
35+ # Replace template investing_algorithm_framework directory with
36+ # given investing_algorithm_framework name
37+ path_rest = path_rest .replace (
38+ self .PROJECT_TEMPLATE_DIR_NAME , self ._bot_name
39+ )
3340
3441 # Create the directories if they don't exist
35- destination_dir = os .path .join (self ._bot_project_directory , path_rest )
42+ destination_dir = os .path .join (
43+ self ._bot_project_directory , path_rest
44+ )
3645 os .makedirs (destination_dir , exist_ok = True )
3746
3847 for dirname in dirs [:]:
@@ -54,14 +63,17 @@ def create(self) -> None:
5463 for old_suffix , new_suffix in self .rewrite_template_suffixes :
5564
5665 if destination_path .endswith (old_suffix ):
57- destination_path = destination_path [:- len (old_suffix )] + new_suffix
66+ destination_path = \
67+ destination_path [:- len (old_suffix )] + new_suffix
5868 break # Only rewrite once
5969
6070 if os .path .exists (destination_path ):
61- raise ImproperlyConfigured (
71+ raise ImproperlyConfigured (
6272 "{} already exists. Overlaying {} {} into an existing "
6373 "directory won't replace conflicting "
64- "files." .format (destination_path , filename , destination_path )
74+ "files." .format (
75+ destination_path , filename , destination_path
76+ )
6577 )
6678
6779 copyfile (template_path , destination_path )
@@ -72,20 +84,29 @@ def create(self) -> None:
7284 except OSError :
7385 raise ImproperlyConfigured (
7486 "Notice: Couldn't set permission bits on {}. You're "
75- "probably using an uncommon filesystem setup." .format (destination_path )
87+ "probably using an uncommon filesystem setup." .format (
88+ destination_path
89+ )
7690 )
7791
7892 # Format placeholders in file if needed
79- if filename in ['manage.py-template' , 'settings.py-template' , 'context.py-template' ]:
93+ if filename in [
94+ 'manage.py-template' ,
95+ 'settings.py-template' ,
96+ 'context.py-template'
97+ ]:
8098
8199 # Read the file
82100 with open (destination_path , 'r' ) as file :
83101
84102 file_data = file .read ()
85103
86- # Replace the placeholder with the investing_algorithm_framework name
87- file_data = file_data .replace (self .PROJECT_NAME_PLACEHOLDER , self ._bot_name )
104+ # Replace the placeholder with the
105+ # investing_algorithm_framework name
106+ file_data = file_data .replace (
107+ self .PROJECT_NAME_PLACEHOLDER , self ._bot_name
108+ )
88109
89110 # Write the file out again
90111 with open (destination_path , 'w' ) as file :
91- file .write (file_data )
112+ file .write (file_data )
0 commit comments