3
3
4
4
import investing_algorithm_framework
5
5
from 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
7
8
8
9
9
10
class DefaultProjectCreator (TemplateCreator ):
@@ -15,24 +16,32 @@ def configure(self) -> None:
15
16
bot_dir = os .path .join (self ._bot_project_directory , self ._bot_name )
16
17
17
18
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 ))
19
21
20
22
def create (self ) -> None :
21
23
22
24
# 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
+ )
24
28
25
29
for root , dirs , files in os .walk (template_dir ):
26
30
27
31
# Get the last part of the path
28
32
# This is used as the basis for the copying
29
33
path_rest = root [len (template_dir ) + 1 :]
30
34
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
+ )
33
40
34
41
# 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
+ )
36
45
os .makedirs (destination_dir , exist_ok = True )
37
46
38
47
for dirname in dirs [:]:
@@ -54,14 +63,17 @@ def create(self) -> None:
54
63
for old_suffix , new_suffix in self .rewrite_template_suffixes :
55
64
56
65
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
58
68
break # Only rewrite once
59
69
60
70
if os .path .exists (destination_path ):
61
- raise ImproperlyConfigured (
71
+ raise ImproperlyConfigured (
62
72
"{} already exists. Overlaying {} {} into an existing "
63
73
"directory won't replace conflicting "
64
- "files." .format (destination_path , filename , destination_path )
74
+ "files." .format (
75
+ destination_path , filename , destination_path
76
+ )
65
77
)
66
78
67
79
copyfile (template_path , destination_path )
@@ -72,20 +84,29 @@ def create(self) -> None:
72
84
except OSError :
73
85
raise ImproperlyConfigured (
74
86
"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
+ )
76
90
)
77
91
78
92
# 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
+ ]:
80
98
81
99
# Read the file
82
100
with open (destination_path , 'r' ) as file :
83
101
84
102
file_data = file .read ()
85
103
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
+ )
88
109
89
110
# Write the file out again
90
111
with open (destination_path , 'w' ) as file :
91
- file .write (file_data )
112
+ file .write (file_data )
0 commit comments