Skip to content

Commit 6ba23eb

Browse files
author
coding-kitties
authored
Merge pull request #35 from coding-kitties/develop
Develop
2 parents 3bddba0 + df0f7b1 commit 6ba23eb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+531
-246
lines changed

docs/CONTRIBUTING.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,6 @@ pytest tests/test_<file_name>.py::test_<method_name>
4747
flake8 investing_algorithm_framework
4848
```
4949

50-
### 3. Test if all type-hints are correct
51-
52-
#### Run mypy
53-
54-
``` bash
55-
mypy investing_algorithm_framework
56-
```
57-
5850
### Process: Your own code changes
5951

6052
All code changes, regardless of who does them, need to be reviewed and merged by someone else.

investing_algorithm_framework/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22

33
VERSION = (0, 1, 0, 'alpha', 0)
44

5+
__all__ = ['get_version']

investing_algorithm_framework/__main__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
"""
2-
Invokes investing_algorithm_framework-admin when the investing_algorithm_framework framework module is run as a script.
3-
Example: python -m investing_algorithm_framework create_standard_algo SampleAlgorithm
2+
Invokes investing_algorithm_framework-admin when the
3+
investing_algorithm_framework framework module is run as a script.
4+
Example:
5+
python -m investing_algorithm_framework create_standard_algo SampleAlgorithm
46
"""
57

68
from investing_algorithm_framework.management import execute_from_command_line

investing_algorithm_framework/configuration/__init__.py

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@
44
from importlib import import_module
55
from enum import Enum
66

7-
from investing_algorithm_framework.core.exceptions import ImproperlyConfigured, OperationalException
8-
from investing_algorithm_framework.configuration.config_constants import SETTINGS_MODULE_PATH_ENV_NAME, \
9-
SETTINGS_STRATEGY_REGISTERED_APPS, SETTINGS_DATA_PROVIDER_REGISTERED_APPS, SETTINGS_LOGGING_CONFIG
7+
from investing_algorithm_framework.core.exceptions \
8+
import ImproperlyConfigured, OperationalException
9+
from investing_algorithm_framework.configuration.config_constants \
10+
import SETTINGS_MODULE_PATH_ENV_NAME, \
11+
SETTINGS_STRATEGY_REGISTERED_APPS, SETTINGS_LOGGING_CONFIG, \
12+
SETTINGS_DATA_PROVIDER_REGISTERED_APPS
1013

1114

1215
class TimeUnit(Enum):
@@ -30,13 +33,19 @@ def from_string(value: str):
3033
elif value.lower() in ('hr', 'hour', 'hours'):
3134
return TimeUnit.HOUR
3235

33-
elif value.lower() in ('always', 'every', 'continuous', 'every_time'):
36+
elif value.lower() in (
37+
'always', 'every', 'continuous', 'every_time'
38+
):
3439
return TimeUnit.ALWAYS
3540
else:
36-
raise OperationalException('Could not convert value {} to a time_unit'.format(value))
41+
raise OperationalException(
42+
'Could not convert value {} to a time_unit'.format(value)
43+
)
3744

3845
else:
39-
raise OperationalException("Could not convert non string value to a time_unit")
46+
raise OperationalException(
47+
"Could not convert non string value to a time_unit"
48+
)
4049

4150
def equals(self, other):
4251

@@ -55,7 +64,8 @@ def equals(self, other):
5564

5665
class BaseSettings:
5766
"""
58-
Base wrapper for settings module. It will load all the default settings for a given settings module
67+
Base wrapper for settings module. It will load all the default settings
68+
for a given settings module
5969
"""
6070

6171
def __init__(self) -> None:
@@ -66,7 +76,9 @@ def configure(self, settings_module: str = None) -> None:
6676
self._settings_module = settings_module
6777

6878
if settings_module is None:
69-
self.settings_module = os.environ.get(SETTINGS_MODULE_PATH_ENV_NAME)
79+
self.settings_module = os.environ.get(
80+
SETTINGS_MODULE_PATH_ENV_NAME
81+
)
7082
else:
7183
self.settings_module = settings_module
7284

@@ -88,8 +100,11 @@ def configure(self, settings_module: str = None) -> None:
88100
if setting.isupper():
89101
setting_value = getattr(module, setting)
90102

91-
if setting in tuple_settings and not isinstance(setting_value, (list, tuple)):
92-
raise ImproperlyConfigured("The %s setting must be a list or a tuple. " % setting)
103+
if setting in tuple_settings and \
104+
not isinstance(setting_value, (list, tuple)):
105+
raise ImproperlyConfigured(
106+
"The {} setting must be a list or a "
107+
"tuple.".format(setting))
93108

94109
setattr(self, setting, setting_value)
95110

@@ -114,11 +129,16 @@ def __getitem__(self, item) -> Any:
114129
if isinstance(item, str):
115130

116131
if not hasattr(self, item):
117-
raise OperationalException("Setting object doesn't have the specific attribute {}".format(item))
132+
raise OperationalException(
133+
"Setting object doesn't have the specific "
134+
"attribute {}".format(item)
135+
)
118136

119137
return self.__getattribute__(item)
120138
else:
121-
raise OperationalException("Settings attributes can only be referenced by string")
139+
raise OperationalException(
140+
"Settings attributes can only be referenced by string"
141+
)
122142

123143
def get(self, key: str, default: Any = None) -> Any:
124144
"""
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
from investing_algorithm_framework.configuration.setup.default_template_creators import DefaultProjectCreator
1+
from investing_algorithm_framework.configuration.setup\
2+
.default_template_creators import DefaultProjectCreator
3+
4+
__all__ = ['DefaultProjectCreator']

investing_algorithm_framework/configuration/setup/default_template_creators.py

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33

44
import investing_algorithm_framework
55
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
78

89

910
class 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)

investing_algorithm_framework/configuration/setup/template.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55

66
class Template:
77
"""
8-
A template class is responsible for creating a templates for the investing_algorithm_framework.
8+
A template class is responsible for creating a templates for the
9+
investing_algorithm_framework.
910
"""
1011

1112
def __init__(self, bot_project_directory: str, bot_name: str) -> None:
1213
"""
13-
investing_algorithm_framework project directory is the root directory of the given
14-
investing_algorithm_framework. The algorithm_name will be the same as the root project directory. For
14+
investing_algorithm_framework project directory is the root
15+
directory of the given investing_algorithm_framework. The
16+
algorithm_name will be the same as the root project directory. For
1517
simplicity it is explicitly passed as a parameter
1618
"""
1719

investing_algorithm_framework/configuration/setup/template_creator.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ def __init__(self, bot_project_directory: str, bot_name: str) -> None:
2121
@abstractmethod
2222
def create(self) -> None:
2323
"""
24-
Create here the template, it is recommended to first call the configure method, this will check if
25-
everything is setup correctly.
24+
Create here the template, it is recommended to first call the configure
25+
method, this will check if everything is setup correctly.
2626
"""
2727

2828
pass
@@ -37,5 +37,3 @@ def make_writeable(filename):
3737
st = os.stat(filename)
3838
new_permissions = stat.S_IMODE(st.st_mode) | stat.S_IWUSR
3939
os.chmod(filename, new_permissions)
40-
41-
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
from investing_algorithm_framework.core.context.context import Context
2+
3+
__all__ = ['Context']

investing_algorithm_framework/core/context/context.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88

99
class Context(metaclass=Singleton):
1010
"""
11-
The Context defines the current state of the running algorithms. It also maintains a reference to an instance of a
12-
state subclass, which represents the current state of the context instance.
11+
The Context defines the current state of the running algorithms. It
12+
also maintains a reference to an instance of a state subclass, which
13+
represents the current state of the context instance.
1314
"""
1415

1516
# A reference to the current state of the context.
@@ -36,8 +37,9 @@ def _check_state(self, raise_exception: bool = False) -> bool:
3637

3738
if raise_exception:
3839
raise OperationalException(
39-
"Context doesn't have a state. Make sure that you set the state either "
40-
"by initializing it or making sure that you transition to a new valid state."
40+
"Context doesn't have a state. Make sure that you set "
41+
"the state either by initializing it or making sure that "
42+
"you transition to a new valid state."
4143
)
4244
else:
4345
return False
@@ -59,4 +61,3 @@ def _run_state(self) -> None:
5961
self._state.start()
6062
transition_state = self._state.get_transition_state_class()
6163
self.transition_to(transition_state)
62-
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
from investing_algorithm_framework.core.events.observable import Observable
22
from investing_algorithm_framework.core.events.observer import Observer
3+
4+
__all__ = ['Observable', 'Observer']
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
11
class ImproperlyConfigured(Exception):
22
"""
3-
Class ImproperlyConfigured: Exception class indicating a problem with the configuration of the investing_algorithm_framework
3+
Class ImproperlyConfigured: Exception class indicating a problem with
4+
the configuration of the investing_algorithm_framework
45
"""
56
def __init__(self, message) -> None:
67
super(ImproperlyConfigured, self).__init__(message)
78

89

910
class OperationalException(Exception):
1011
"""
11-
Class OperationalException: Exception class indicating a problem occurred during running of the investing_algorithm_framework
12+
Class OperationalException: Exception class indicating a problem occurred
13+
during running of the investing_algorithm_framework
1214
"""
1315
def __init__(self, message) -> None:
1416
super(OperationalException, self).__init__(message)
1517

1618

1719
class DatabaseOperationalException(Exception):
1820
"""
19-
Class DatabaseOperationalException: Exception class indicating a problem occurred during usage of the database
21+
Class DatabaseOperationalException: Exception class indicating a problem
22+
occurred during usage of the database
2023
"""
2124
def __init__(self, message) -> None:
2225
super(DatabaseOperationalException, self).__init__(message)
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
from investing_algorithm_framework.core.executors.executor import Executor
2-
from investing_algorithm_framework.core.executors.execution_scheduler import ExecutionScheduler
2+
from investing_algorithm_framework.core.executors.execution_scheduler \
3+
import ExecutionScheduler
4+
5+
__all__ = ['Executor', 'ExecutionScheduler']

0 commit comments

Comments
 (0)