tiferet 1.0.0a13__tar.gz → 1.0.0a15__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. {tiferet-1.0.0a13/tiferet.egg-info → tiferet-1.0.0a15}/PKG-INFO +1 -1
  2. {tiferet-1.0.0a13 → tiferet-1.0.0a15}/setup.py +2 -3
  3. {tiferet-1.0.0a13 → tiferet-1.0.0a15}/tiferet/contexts/__init__.py +1 -1
  4. tiferet-1.0.0a15/tiferet/contexts/app.py +285 -0
  5. {tiferet-1.0.0a13 → tiferet-1.0.0a15}/tiferet/contexts/container.py +40 -3
  6. {tiferet-1.0.0a13 → tiferet-1.0.0a15}/tiferet/data/app.py +1 -52
  7. {tiferet-1.0.0a13 → tiferet-1.0.0a15}/tiferet/domain/__init__.py +1 -1
  8. {tiferet-1.0.0a13 → tiferet-1.0.0a15}/tiferet/domain/app.py +1 -56
  9. {tiferet-1.0.0a13 → tiferet-1.0.0a15}/tiferet/repos/app.py +2 -2
  10. {tiferet-1.0.0a13 → tiferet-1.0.0a15/tiferet.egg-info}/PKG-INFO +1 -1
  11. {tiferet-1.0.0a13 → tiferet-1.0.0a15}/tiferet.egg-info/SOURCES.txt +1 -4
  12. tiferet-1.0.0a13/tiferet/contexts/app.py +0 -144
  13. tiferet-1.0.0a13/tiferet/services/__init__.py +0 -5
  14. tiferet-1.0.0a13/tiferet/services/app.py +0 -52
  15. tiferet-1.0.0a13/tiferet/services/container.py +0 -46
  16. {tiferet-1.0.0a13 → tiferet-1.0.0a15}/LICENSE +0 -0
  17. {tiferet-1.0.0a13 → tiferet-1.0.0a15}/setup.cfg +0 -0
  18. {tiferet-1.0.0a13 → tiferet-1.0.0a15}/tiferet/__init__.py +0 -0
  19. {tiferet-1.0.0a13 → tiferet-1.0.0a15}/tiferet/clients/__init__.py +0 -0
  20. {tiferet-1.0.0a13 → tiferet-1.0.0a15}/tiferet/clients/yaml.py +0 -0
  21. {tiferet-1.0.0a13 → tiferet-1.0.0a15}/tiferet/commands/__init__.py +0 -0
  22. {tiferet-1.0.0a13 → tiferet-1.0.0a15}/tiferet/commands/container.py +0 -0
  23. {tiferet-1.0.0a13 → tiferet-1.0.0a15}/tiferet/commands/error.py +0 -0
  24. {tiferet-1.0.0a13 → tiferet-1.0.0a15}/tiferet/commands/feature.py +0 -0
  25. {tiferet-1.0.0a13 → tiferet-1.0.0a15}/tiferet/configs/__init__.py +0 -0
  26. {tiferet-1.0.0a13 → tiferet-1.0.0a15}/tiferet/contexts/error.py +0 -0
  27. {tiferet-1.0.0a13 → tiferet-1.0.0a15}/tiferet/contexts/feature.py +0 -0
  28. {tiferet-1.0.0a13 → tiferet-1.0.0a15}/tiferet/contexts/request.py +0 -0
  29. {tiferet-1.0.0a13 → tiferet-1.0.0a15}/tiferet/data/__init__.py +0 -0
  30. {tiferet-1.0.0a13 → tiferet-1.0.0a15}/tiferet/data/container.py +0 -0
  31. {tiferet-1.0.0a13 → tiferet-1.0.0a15}/tiferet/data/error.py +0 -0
  32. {tiferet-1.0.0a13 → tiferet-1.0.0a15}/tiferet/data/feature.py +0 -0
  33. {tiferet-1.0.0a13 → tiferet-1.0.0a15}/tiferet/domain/container.py +0 -0
  34. {tiferet-1.0.0a13 → tiferet-1.0.0a15}/tiferet/domain/core.py +0 -0
  35. {tiferet-1.0.0a13 → tiferet-1.0.0a15}/tiferet/domain/error.py +0 -0
  36. {tiferet-1.0.0a13 → tiferet-1.0.0a15}/tiferet/domain/feature.py +0 -0
  37. {tiferet-1.0.0a13 → tiferet-1.0.0a15}/tiferet/repos/__init__.py +0 -0
  38. {tiferet-1.0.0a13 → tiferet-1.0.0a15}/tiferet/repos/container.py +0 -0
  39. {tiferet-1.0.0a13 → tiferet-1.0.0a15}/tiferet/repos/error.py +0 -0
  40. {tiferet-1.0.0a13 → tiferet-1.0.0a15}/tiferet/repos/feature.py +0 -0
  41. {tiferet-1.0.0a13 → tiferet-1.0.0a15}/tiferet.egg-info/dependency_links.txt +0 -0
  42. {tiferet-1.0.0a13 → tiferet-1.0.0a15}/tiferet.egg-info/requires.txt +0 -0
  43. {tiferet-1.0.0a13 → tiferet-1.0.0a15}/tiferet.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: tiferet
3
- Version: 1.0.0a13
3
+ Version: 1.0.0a15
4
4
  Summary: A multi-purpose application framework embodying beauty in form.
5
5
  Home-page: https://github.com/greatstrength/app
6
6
  Download-URL: https://github.com/greatstrength/app
@@ -9,7 +9,7 @@ config = {
9
9
  'url': r'https://github.com/greatstrength/app',
10
10
  'download_url': r'https://github.com/greatstrength/app',
11
11
  'author_email': 'andrew@greatstrength.me',
12
- 'version': '1.0.0-alpha.13',
12
+ 'version': '1.0.0-alpha.15',
13
13
  'license': 'BSD 3',
14
14
  'install_requires': [
15
15
  'schematics>=2.1.1',
@@ -24,8 +24,7 @@ config = {
24
24
  'tiferet.contexts',
25
25
  'tiferet.data',
26
26
  'tiferet.domain',
27
- 'tiferet.repos',
28
- 'tiferet.services',
27
+ 'tiferet.repos'
29
28
  ],
30
29
  'scripts': [],
31
30
  'name': 'tiferet',
@@ -1,7 +1,7 @@
1
1
  # *** imports
2
2
 
3
3
  # ** app
4
- from .app import AppInterfaceContext
4
+ from .app import AppContext, AppContext as App, AppInterfaceContext
5
5
  from .container import ContainerContext
6
6
  from .error import ErrorContext
7
7
  from .feature import FeatureContext
@@ -0,0 +1,285 @@
1
+ # *** imports
2
+
3
+ # ** core
4
+ from typing import Dict, Any, Tuple
5
+
6
+ # ** app
7
+ from .request import RequestContext
8
+ from .feature import FeatureContext
9
+ from .error import ErrorContext
10
+ from .container import create_injector, import_dependency
11
+ from ..domain import Model, StringType, DictType, ModelType
12
+ from ..domain import AppInterface
13
+ from ..repos import AppRepository
14
+
15
+
16
+ # *** contexts
17
+
18
+ # ** context: app_context
19
+ class AppContext(Model):
20
+
21
+ # * attribute: app_repo_module_path
22
+ app_repo_module_path = StringType(
23
+ required=True,
24
+ default='tiferet.repos.app',
25
+ metadata=dict(
26
+ description='The application repository module path.'
27
+ ),
28
+ )
29
+
30
+ # * attribute: app_repo_class_name
31
+ app_repo_class_name = StringType(
32
+ required=True,
33
+ default='AppYamlProxy',
34
+ metadata=dict(
35
+ description='The application repository class name.'
36
+ ),
37
+ )
38
+
39
+ # * attribute: app_repo_parameters
40
+ app_repo_parameters = DictType(
41
+ StringType(),
42
+ default=dict(
43
+ app_config_file='app/configs/app.yml'
44
+ ),
45
+ metadata=dict(
46
+ description='The application repository parameters.'
47
+ ),
48
+ )
49
+
50
+ # * method: run
51
+ def run(self, interface_id: str, dependencies: Dict[str, Any] = {}, **kwargs) -> Any:
52
+ '''
53
+ Run the application interface.
54
+
55
+ :param interface_id: The interface ID.
56
+ :type interface_id: str
57
+ :param dependencies: The dependencies.
58
+ :type dependencies: dict
59
+ :param kwargs: Additional keyword arguments.
60
+ :type kwargs: dict
61
+ :return: The response.
62
+ :rtype: Any
63
+ '''
64
+
65
+ # Load the interface.
66
+ app_interface = self.load_interface(interface_id, **dependencies)
67
+
68
+ # Run the interface.
69
+ return app_interface.run(**kwargs)
70
+
71
+ # * method: load_interface
72
+ def load_interface(self, interface_id: str, **dependencies) -> AppInterface:
73
+ '''
74
+ Load the application interface.
75
+
76
+ :param interface_id: The interface ID.
77
+ :type interface_id: str
78
+ :param dependencies: The dependencies.
79
+ :type dependencies: dict
80
+ :return: The application interface.
81
+ :rtype: AppInterface
82
+ '''
83
+
84
+ # Import the app repository.
85
+ app_repo = self.import_app_repo(
86
+ self.app_repo_module_path,
87
+ self.app_repo_class_name,
88
+ **self.app_repo_parameters
89
+ )
90
+
91
+ # Get the app interface.
92
+ app_interface = app_repo.get_interface(interface_id)
93
+
94
+ # Create the injector.
95
+ injector = self.create_injector(app_interface, **dependencies)
96
+
97
+ # Load the app interface context.
98
+ return getattr(injector, 'app_context')
99
+
100
+ # * method: import_app_repo
101
+ def import_app_repo(self, module_path: str, class_name: str, **kwargs) -> AppRepository:
102
+ '''
103
+ Import the app repository.
104
+
105
+ :param module_path: The module path.
106
+ :type module_path: str
107
+ :param class_name: The class name.
108
+ :type class_name: str
109
+ :param kwargs: Additional keyword arguments.
110
+ :type kwargs: dict
111
+ :return: The app repository.
112
+ :rtype: AppRepository
113
+ '''
114
+
115
+ # Try to import the module provided.
116
+ try:
117
+ return import_dependency(module_path, class_name)(**kwargs)
118
+
119
+ # Return None if nothing comes up.
120
+ except:
121
+ return None
122
+
123
+ # ** method: create_injector
124
+ def create_injector(self, app_interface: AppInterface, **kwargs) -> Any:
125
+ '''
126
+ Create the injector.
127
+
128
+ :param app_interface: The app interface.
129
+ :type app_interface: AppInterface
130
+ :param kwargs: Additional keyword arguments.
131
+ :type kwargs: dict
132
+ :return: The injector.
133
+ :rtype: Any
134
+ '''
135
+
136
+ # Get the dependencies for the app interface.
137
+ dependencies = dict(
138
+ interface_id=app_interface.id,
139
+ app_name=app_interface.name,
140
+ feature_flag=app_interface.feature_flag,
141
+ data_flag=app_interface.data_flag,
142
+ app_context=import_dependency(
143
+ **app_interface.get_dependency('app_context').to_primitive()
144
+ ),
145
+ **app_interface.constants
146
+ )
147
+
148
+ # Add the remaining dependencies from the app interface.
149
+ dependencies.update({dep.attribute_id: import_dependency(dep.module_path, dep.class_name) for dep in app_interface.dependencies})
150
+
151
+ # Create the injector.
152
+ return create_injector(app_interface.id, **dependencies, **kwargs)
153
+
154
+
155
+ # ** context: app_interface_context
156
+ class AppInterfaceContext(Model):
157
+ '''
158
+ The application interface context is a class that is used to create and run the application interface.
159
+ '''
160
+
161
+ # * attribute: interface_id
162
+ interface_id = StringType(
163
+ required=True,
164
+ metadata=dict(
165
+ description='The interface ID.'
166
+ ),
167
+ )
168
+
169
+ # * attribute: name
170
+ name = StringType(
171
+ required=True,
172
+ metadata=dict(
173
+ description='The application name.'
174
+ ),
175
+ )
176
+
177
+ # * field: features
178
+ features = ModelType(
179
+ FeatureContext,
180
+ required=True,
181
+ metadata=dict(
182
+ description='The feature context.'
183
+ ),
184
+ )
185
+
186
+ # * field: errors
187
+ errors = ModelType(
188
+ ErrorContext,
189
+ required=True,
190
+ metadata=dict(
191
+ description='The error context.'
192
+ ),
193
+ )
194
+
195
+ # * method: init
196
+ def __init__(self, interface_id: str, app_name: str, feature_context: FeatureContext, error_context: ErrorContext):
197
+ '''
198
+ Initialize the application interface context.
199
+
200
+ :param interface_id: The interface ID.
201
+ :type interface_id: str
202
+ :param app_name: The application name.
203
+ :type app_name: str
204
+ :param feature_context: The feature context.
205
+ :type feature_context: FeatureContext
206
+ :param error_context: The error context.
207
+ :type error_context: ErrorContext
208
+ '''
209
+
210
+ # Initialize the model.
211
+ super().__init__(dict(
212
+ interface_id=interface_id,
213
+ name=app_name
214
+ ))
215
+ self.features = feature_context
216
+ self.errors = error_context
217
+
218
+ # * method: parse_request
219
+ def parse_request(self, request: Any, **kwargs) -> Tuple[RequestContext, dict]:
220
+ '''
221
+ Parse the incoming request.
222
+
223
+ :param request: The incoming request.
224
+ :type request: Any
225
+ :param kwargs: Additional keyword arguments.
226
+ :type kwargs: dict
227
+ :return: The request context.
228
+ :rtype: RequestContext
229
+ '''
230
+
231
+ # Parse request.
232
+ return request, kwargs
233
+
234
+ # * method: execute_feature
235
+ def execute_feature(self, request: RequestContext, **kwargs):
236
+ '''
237
+ Execute the feature context.
238
+
239
+ :param request: The request context.
240
+ :type request: RequestContext
241
+ '''
242
+
243
+ # Execute feature context and return session.
244
+ self.features.execute(request, **kwargs)
245
+
246
+ # * method: handle_response
247
+ def handle_response(self, request: RequestContext) -> Any:
248
+ '''
249
+ Handle the response.
250
+
251
+ :param request: The request context.
252
+ :type request: RequestContext
253
+ :return: The response.
254
+ :rtype: Any
255
+ '''
256
+
257
+ # Import the JSON module.
258
+ import json
259
+
260
+ # Return the response.
261
+ return json.loads(request.result) if request.result else None
262
+
263
+ # * method: run
264
+ def run(self, **kwargs):
265
+ '''
266
+ Run the application interface.
267
+
268
+ :param kwargs: Additional keyword arguments.
269
+ :type kwargs: dict
270
+ '''
271
+
272
+ # Parse request.
273
+ request, kwargs = self.parse_request(**kwargs)
274
+
275
+ # Execute feature context and return session.
276
+ try:
277
+ self.execute_feature(request, **kwargs)
278
+
279
+ # Handle error and return response if triggered.
280
+ except Exception as e:
281
+ print('Error:', e)
282
+ return self.errors.handle_error(e)
283
+
284
+ # Handle response.
285
+ return self.handle_response(request)
@@ -6,10 +6,47 @@ from typing import Any
6
6
 
7
7
  # ** app
8
8
  from ..domain import *
9
- from ..services import container_service
10
9
  from ..repos.container import ContainerRepository
11
10
 
12
11
 
12
+ # *** functions
13
+
14
+ # ** function: create_injector
15
+ def create_injector(name: str, **dependencies) -> Any:
16
+ '''
17
+ Create an injector object with the given dependencies.
18
+
19
+ :param name: The name of the injector.
20
+ :type name: str
21
+ :param dependencies: The dependencies.
22
+ :type dependencies: dict
23
+ :return: The injector object.
24
+ :rtype: Any
25
+ '''
26
+
27
+ # Create container.
28
+ from dependencies import Injector
29
+ return type(f'{name.capitalize()}Container', (Injector,), {**dependencies})
30
+
31
+
32
+ # ** function: import_dependency
33
+ def import_dependency(module_path: str, class_name: str) -> Any:
34
+ '''
35
+ Import an object dependency from its configured Python module.
36
+
37
+ :param module_path: The module path.
38
+ :type module_path: str
39
+ :param class_name: The class name.
40
+ :type class_name: str
41
+ :return: The dependency.
42
+ :rtype: Any
43
+ '''
44
+
45
+ # Import module.
46
+ from importlib import import_module
47
+ return getattr(import_module(module_path), class_name)
48
+
49
+
13
50
  # *** contexts
14
51
 
15
52
  # ** contexts: container_context
@@ -165,7 +202,7 @@ class ContainerContext(Model):
165
202
  dependencies[attribute_id] = self.import_dependency(attribute, flag_map[attribute.type])
166
203
 
167
204
  # Create container.
168
- return container_service.create_injector(
205
+ return create_injector(
169
206
  self.interface_id,
170
207
  **self.constants,
171
208
  **dependencies,
@@ -192,4 +229,4 @@ class ContainerContext(Model):
192
229
  dependency = attribute.get_dependency('core')
193
230
 
194
231
  # Import the dependency.
195
- return container_service.import_dependency(dependency.module_path, dependency.class_name)
232
+ return import_dependency(dependency.module_path, dependency.class_name)
@@ -6,7 +6,7 @@ from typing import Dict
6
6
  # ** app
7
7
  from ..configs import *
8
8
  from ..domain import DataObject
9
- from ..domain.app import AppDependency, AppInterface, AppRepositoryConfiguration
9
+ from ..domain.app import AppDependency, AppInterface
10
10
 
11
11
 
12
12
  # *** constants
@@ -283,54 +283,3 @@ class AppInterfaceYamlData(AppInterface, DataObject):
283
283
  **self.to_primitive('to_model'),
284
284
  **kwargs
285
285
  )
286
-
287
-
288
- # ** data: app_repository_configuration_yaml_data
289
- class AppRepositoryConfigurationYamlData(DataObject, AppRepositoryConfiguration):
290
- '''
291
- A YAML data representation of an app repository configuration object.
292
- '''
293
-
294
- class Options():
295
- '''
296
- The options for the app repository configuration data.
297
- '''
298
- serialize_when_none = False
299
- roles = {
300
- 'to_model': DataObject.allow(),
301
- 'to_data': DataObject.allow()
302
- }
303
-
304
- # * method: new
305
- @staticmethod
306
- def from_data(**kwargs) -> 'AppRepositoryConfigurationYamlData':
307
- '''
308
- Initializes a new YAML representation of an AppRepositoryConfiguration object.
309
-
310
- :param kwargs: Additional keyword arguments.
311
- :type kwargs: dict
312
- :return: A new AppRepositoryConfigurationData object.
313
- :rtype: AppRepositoryConfigurationData
314
- '''
315
-
316
- # Create a new AppRepositoryConfigurationData object.
317
- return super(AppRepositoryConfigurationYamlData, AppRepositoryConfigurationYamlData).from_data(
318
- AppRepositoryConfigurationYamlData,
319
- **kwargs
320
- )
321
-
322
- # * method: map
323
- def map(self, **kwargs) -> AppRepositoryConfiguration:
324
- '''
325
- Maps the app repository configuration data to an app repository configuration object.
326
-
327
- :param role: The role for the mapping.
328
- :type role: str
329
- :param kwargs: Additional keyword arguments.
330
- :type kwargs: dict
331
- :return: A new app repository configuration object.
332
- :rtype: AppRepositoryConfiguration
333
- '''
334
-
335
- # Map the app repository configuration data.
336
- return super().map(AppRepositoryConfiguration, **kwargs)
@@ -1,5 +1,5 @@
1
1
  from .core import *
2
- from .app import AppInterface, AppDependency, AppRepositoryConfiguration
2
+ from .app import AppInterface, AppDependency
3
3
  from .container import ContainerAttribute, ContainerDependency
4
4
  from .error import Error, ErrorMessage
5
5
  from .feature import Feature
@@ -128,59 +128,4 @@ class AppInterface(Entity):
128
128
 
129
129
  # Get the dependency by attribute id.
130
130
  return next((dep for dep in self.dependencies if dep.attribute_id == attribute_id), None)
131
-
132
-
133
- # ** model: app_repository_configuration
134
- class AppRepositoryConfiguration(ModuleDependency):
135
- '''
136
- The import configuration for the application repository.
137
- '''
138
-
139
- # * attribute: module_path
140
- module_path = StringType(
141
- required=True,
142
- default='tiferet.repos.app',
143
- metadata=dict(
144
- description='The module path for the application repository.'
145
- ),
146
- )
147
-
148
- # * attribute: class_name
149
- class_name = StringType(
150
- required=True,
151
- default='YamlProxy',
152
- metadata=dict(
153
- description='The class name for the application repository.'
154
- ),
155
- )
156
-
157
- # * attribute: params
158
- params = DictType(
159
- StringType,
160
- default=dict(
161
- app_config_file='app/configs/app.yml',
162
- ),
163
- metadata=dict(
164
- description='The application repository configuration parameters.'
165
- ),
166
- )
167
-
168
- # * method: new
169
- @staticmethod
170
- def new(**kwargs) -> 'AppRepositoryConfiguration':
171
- '''
172
- Initializes a new AppRepositoryConfiguration object.
173
-
174
- :param kwargs: Additional keyword arguments.
175
- :type kwargs: dict
176
- :return: A new AppRepositoryConfiguration object.
177
- :rtype: AppRepositoryConfiguration
178
- '''
179
-
180
- # Create and return a new AppRepositoryConfiguration object.
181
- return AppRepositoryConfiguration(
182
- super(AppRepositoryConfiguration, AppRepositoryConfiguration).new(
183
- AppRepositoryConfiguration,
184
- **kwargs),
185
- strict=False,
186
- )
131
+
@@ -41,8 +41,8 @@ class AppRepository(object):
41
41
  raise NotImplementedError()
42
42
 
43
43
 
44
- # ** proxy: yaml_proxy
45
- class YamlProxy(object):
44
+ # ** proxy: app_yaml_proxy
45
+ class AppYamlProxy(AppRepository):
46
46
 
47
47
  # * field: config_file
48
48
  config_file: str = None
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: tiferet
3
- Version: 1.0.0a13
3
+ Version: 1.0.0a15
4
4
  Summary: A multi-purpose application framework embodying beauty in form.
5
5
  Home-page: https://github.com/greatstrength/app
6
6
  Download-URL: https://github.com/greatstrength/app
@@ -34,7 +34,4 @@ tiferet/repos/__init__.py
34
34
  tiferet/repos/app.py
35
35
  tiferet/repos/container.py
36
36
  tiferet/repos/error.py
37
- tiferet/repos/feature.py
38
- tiferet/services/__init__.py
39
- tiferet/services/app.py
40
- tiferet/services/container.py
37
+ tiferet/repos/feature.py
@@ -1,144 +0,0 @@
1
- # *** imports
2
-
3
- # ** core
4
- from typing import Any, Tuple
5
-
6
- # ** app
7
- from .request import RequestContext
8
- from .feature import FeatureContext
9
- from .error import ErrorContext
10
- from ..domain import *
11
-
12
-
13
- # *** contexts
14
-
15
- # ** context: app_interface_context
16
- class AppInterfaceContext(Model):
17
- '''
18
- The application interface context is a class that is used to create and run the application interface.
19
- '''
20
-
21
- # * attribute: interface_id
22
- interface_id = StringType(
23
- required=True,
24
- metadata=dict(
25
- description='The interface ID.'
26
- ),
27
- )
28
-
29
- # * attribute: name
30
- name = StringType(
31
- required=True,
32
- metadata=dict(
33
- description='The application name.'
34
- ),
35
- )
36
-
37
- # * field: features
38
- features = ModelType(
39
- FeatureContext,
40
- required=True,
41
- metadata=dict(
42
- description='The feature context.'
43
- ),
44
- )
45
-
46
- # * field: errors
47
- errors = ModelType(
48
- ErrorContext,
49
- required=True,
50
- metadata=dict(
51
- description='The error context.'
52
- ),
53
- )
54
-
55
- # * method: init
56
- def __init__(self, interface_id: str, app_name: str, feature_context: FeatureContext, error_context: ErrorContext):
57
- '''
58
- Initialize the application interface context.
59
-
60
- :param interface_id: The interface ID.
61
- :type interface_id: str
62
- :param app_name: The application name.
63
- :type app_name: str
64
- :param feature_context: The feature context.
65
- :type feature_context: FeatureContext
66
- :param error_context: The error context.
67
- :type error_context: ErrorContext
68
- '''
69
-
70
- # Initialize the model.
71
- super().__init__(dict(
72
- interface_id=interface_id,
73
- name=app_name
74
- ))
75
- self.features = feature_context
76
- self.errors = error_context
77
-
78
- # * method: parse_request
79
- def parse_request(self, request: Any, **kwargs) -> Tuple[RequestContext, dict]:
80
- '''
81
- Parse the incoming request.
82
-
83
- :param request: The incoming request.
84
- :type request: Any
85
- :param kwargs: Additional keyword arguments.
86
- :type kwargs: dict
87
- :return: The request context.
88
- :rtype: RequestContext
89
- '''
90
-
91
- # Parse request.
92
- return request, kwargs
93
-
94
- # * method: execute_feature
95
- def execute_feature(self, request: RequestContext, **kwargs):
96
- '''
97
- Execute the feature context.
98
-
99
- :param request: The request context.
100
- :type request: RequestContext
101
- '''
102
-
103
- # Execute feature context and return session.
104
- self.features.execute(request, **kwargs)
105
-
106
- # * method: handle_response
107
- def handle_response(self, request: RequestContext) -> Any:
108
- '''
109
- Handle the response.
110
-
111
- :param request: The request context.
112
- :type request: RequestContext
113
- :return: The response.
114
- :rtype: Any
115
- '''
116
-
117
- # Import the JSON module.
118
- import json
119
-
120
- # Return the response.
121
- return json.loads(request.result) if request.result else None
122
-
123
- # * method: run
124
- def run(self, **kwargs):
125
- '''
126
- Run the application interface.
127
-
128
- :param kwargs: Additional keyword arguments.
129
- :type kwargs: dict
130
- '''
131
-
132
- # Parse request.
133
- request, kwargs = self.parse_request(**kwargs)
134
-
135
- # Execute feature context and return session.
136
- # Handle error and return response if triggered.
137
- try:
138
- self.execute_feature(request, **kwargs)
139
- except Exception as e:
140
- print('Error:', e)
141
- return self.errors.handle_error(e)
142
-
143
- # Handle response.
144
- return self.handle_response(request)
@@ -1,5 +0,0 @@
1
- # *** imports
2
-
3
- # ** app
4
- from . import container as container_service
5
- from . import app as app_service
@@ -1,52 +0,0 @@
1
- # *** imports
2
-
3
- # ** core
4
- from typing import Any
5
-
6
- # ** app
7
- from ..domain import AppInterface
8
- from ..repos.app import AppRepository
9
- from . import container_service
10
-
11
-
12
- # *** functions
13
-
14
- # ** function: load_app_context
15
- def load_app_context(interface_id: str, app_repo: AppRepository) -> Any:
16
- '''
17
- Load the app context.
18
-
19
- :param container: The app container.
20
- :type container: AppContainer
21
- :return: The app context.
22
- :rtype: Any
23
- '''
24
-
25
- # Get the app interface.
26
- app_interface: AppInterface = app_repo.get_interface(interface_id)
27
-
28
- # Get the default dependencies for the app interface.
29
- app_context = app_interface.get_dependency('app_context')
30
- dependencies = dict(
31
- interface_id=app_interface.id,
32
- app_name=app_interface.name,
33
- feature_flag=app_interface.feature_flag,
34
- data_flag=app_interface.data_flag,
35
- app_context=container_service.import_dependency(
36
- **app_context.to_primitive()
37
- ),
38
- **app_interface.constants
39
- )
40
-
41
- # Import the dependencies.
42
- for dep in app_interface.dependencies:
43
- dependencies[dep.attribute_id] = container_service.import_dependency(dep.module_path, dep.class_name)
44
-
45
- # Create the injector from the dependencies, constants, and the app interface.
46
- injector = container_service.create_injector(
47
- app_interface.id,
48
- **dependencies
49
- )
50
-
51
- # Return the app context.
52
- return getattr(injector, 'app_context')
@@ -1,46 +0,0 @@
1
- # *** imports
2
-
3
- # ** core
4
- from typing import Any
5
-
6
- # ** infra
7
- from dependencies import Injector
8
-
9
-
10
- # *** functions
11
-
12
- # ** function: import_dependency
13
- def import_dependency(module_path: str, class_name: str, **kwargs) -> Any:
14
- '''
15
- Import an object dependency from its configured Python module.
16
-
17
- :param module_path: The module path.
18
- :type module_path: str
19
- :param class_name: The class name.
20
- :type class_name: str
21
- :param kwargs: Additional keyword arguments.
22
- :type kwargs: dict
23
- :return: The dependency.
24
- :rtype: Any
25
- '''
26
-
27
- # Import module.
28
- from importlib import import_module
29
- return getattr(import_module(module_path), class_name)
30
-
31
-
32
- # ** function: create_injector
33
- def create_injector(name: str, **dependencies) -> Any:
34
- '''
35
- Create an injector object with the given dependencies.
36
-
37
- :param name: The name of the injector.
38
- :type name: str
39
- :param dependencies: The dependencies.
40
- :type dependencies: dict
41
- :return: The injector object.
42
- :rtype: Any
43
- '''
44
-
45
- # Create container.
46
- return type(f'{name.capitalize()}Container', (Injector,), {**dependencies})
File without changes
File without changes