Skip to content

Commit 0b5efe3

Browse files
committed
Fix flake8 warnings
1 parent f7c5a12 commit 0b5efe3

File tree

15 files changed

+207
-154
lines changed

15 files changed

+207
-154
lines changed

investing_algorithm_framework/app/algorithm.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@ def start(self, number_of_iterations: int = None):
144144
app.
145145
146146
Args:
147-
number_of_iterations (int): (Optional) The number of iterations to run the algorithm
147+
number_of_iterations (int): (Optional) The number of
148+
iterations to run the algorithm
148149
149150
Returns:
150151
None

investing_algorithm_framework/app/app.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def initialize_config(self):
9696

9797
# Check if the resource directory is set
9898
if RESOURCE_DIRECTORY not in config \
99-
or config[RESOURCE_DIRECTORY] is None:
99+
or config[RESOURCE_DIRECTORY] is None:
100100
logger.info(
101101
"Resource directory not set, setting" +
102102
" to current working directory"
@@ -115,7 +115,7 @@ def initialize_config(self):
115115
config = configuration_service.get_config()
116116

117117
if DATABASE_DIRECTORY_PATH not in config \
118-
or config[DATABASE_DIRECTORY_PATH] is None:
118+
or config[DATABASE_DIRECTORY_PATH] is None:
119119
resource_dir = config[RESOURCE_DIRECTORY]
120120
configuration_service.add_value(
121121
DATABASE_DIRECTORY_PATH,
@@ -125,7 +125,7 @@ def initialize_config(self):
125125
config = configuration_service.get_config()
126126

127127
if SQLALCHEMY_DATABASE_URI not in config \
128-
or config[SQLALCHEMY_DATABASE_URI] is None:
128+
or config[SQLALCHEMY_DATABASE_URI] is None:
129129
path = "sqlite:///" + os.path.join(
130130
configuration_service.config[DATABASE_DIRECTORY_PATH],
131131
configuration_service.config[DATABASE_NAME]
@@ -262,7 +262,6 @@ def sync(self, portfolio):
262262
# Sync all trades from exchange with current trade history
263263
portfolio_sync_service.sync_trades(portfolio)
264264

265-
266265
def _initialize_standard(self):
267266
"""
268267
Initialize the app for standard mode by setting the configuration
@@ -545,8 +544,9 @@ def run(
545544
number of iterations provided. This mode is useful when running the
546545
app in a loop for a fixed number of iterations.
547546
548-
This function first checks if there is an algorithm registered. If not, it raises an OperationalException. Then it initializes the algorithm with the services and the configuration.
549-
547+
This function first checks if there is an algorithm registered.
548+
If not, it raises an OperationalException. Then it
549+
initializes the algorithm with the services and the configuration.
550550
551551
Args:
552552
payload (dict): The payload to handle for the algorithm
@@ -697,8 +697,10 @@ def _initialize_web(self):
697697

698698
def _create_resources_if_not_exists(self):
699699
"""
700-
Function to create the resources required by the app if they do not exist. This function will check if the resource directory exists and
701-
check if the database directory exists. If they do not exist, it will create them.
700+
Function to create the resources required by the app if they
701+
do not exist. This function will check if the resource directory
702+
exists and check if the database directory exists. If they do
703+
not exist, it will create them.
702704
703705
Returns:
704706
None
@@ -947,8 +949,8 @@ def on_initialize(self, app_hook: AppHook):
947949

948950
def after_initialize(self, app_hook: AppHook):
949951
"""
950-
Function to add a hook that runs after the app is initialized. The hook
951-
should be an instance of AppHook.
952+
Function to add a hook that runs after the app is initialized.
953+
The hook should be an instance of AppHook.
952954
"""
953955

954956
if inspect.isclass(app_hook):

investing_algorithm_framework/cli/create_azure_function_app_skeleton.py

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,44 @@
22
import click
33

44

5+
def create_file(file_path):
6+
"""
7+
Creates a new file.
8+
9+
Args:
10+
file_path (str): The path to the file to create.
11+
12+
Returns:
13+
None
14+
"""
15+
16+
if not os.path.exists(file_path):
17+
with open(file_path, "w") as file:
18+
file.write("")
19+
20+
521
def create_file_from_template(template_path, output_path):
622
"""
723
Creates a new file by replacing placeholders in a template file.
824
925
Args:
1026
template_path (str): The path to the template file.
1127
output_path (str): The path to the output file.
12-
replacements (dict): A dictionary of placeholder keys and their replacements.
28+
replacements (dict): A dictionary of placeholder keys and
29+
their replacements.
1330
1431
Returns:
1532
None
1633
"""
17-
with open(template_path, "r") as file:
18-
template = file.read()
1934

20-
with open(output_path, "w") as file:
21-
file.write(template)
35+
# Check if output path already exists
36+
if not os.path.exists(output_path):
37+
with open(template_path, "r") as file:
38+
template = file.read()
39+
40+
with open(output_path, "w") as file:
41+
file.write(template)
42+
2243

2344
def create_azure_function_skeleton(
2445
add_app_template, add_requirements_template
@@ -62,14 +83,23 @@ def create_azure_function_skeleton(
6283
"templates",
6384
"azure_function_framework_app.py.template"
6485
)
86+
create_file_from_template(
87+
function_app_path,
88+
os.path.join(cwd, "app_entry.py")
89+
)
6590

6691
if add_requirements_template:
6792
requirements_path = os.path.join(
6893
os.path.dirname(current_script_path),
6994
"templates",
7095
"azure_function_requirements.txt.template"
7196
)
97+
create_file_from_template(
98+
function_app_path,
99+
os.path.join(cwd, "requirements.txt")
100+
)
72101

102+
create_file(os.path.join(cwd, "__init__.py"))
73103
create_file_from_template(
74104
template_host_file_path,
75105
os.path.join(cwd, "host.json")
@@ -87,7 +117,7 @@ def create_azure_function_skeleton(
87117
os.path.join(cwd, "requirements.txt")
88118
)
89119
print(
90-
f"Function App trading bot skeleton creation completed"
120+
"Function App trading bot skeleton creation completed"
91121
)
92122

93123

@@ -110,7 +140,8 @@ def cli(add_app_template, add_requirements_template):
110140
111141
Args:
112142
add_app_template (bool): Flag to create an app skeleton.
113-
add_requirements_template (bool): Flag to create a requirements template.
143+
add_requirements_template (bool): Flag to create a
144+
requirements template.
114145
115146
Returns:
116147
None

0 commit comments

Comments
 (0)