tiferet 1.0.0a13__py3-none-any.whl → 1.0.0a15__py3-none-any.whl

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.
@@ -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
tiferet/contexts/app.py CHANGED
@@ -1,17 +1,157 @@
1
1
  # *** imports
2
2
 
3
3
  # ** core
4
- from typing import Any, Tuple
4
+ from typing import Dict, Any, Tuple
5
5
 
6
6
  # ** app
7
7
  from .request import RequestContext
8
8
  from .feature import FeatureContext
9
9
  from .error import ErrorContext
10
- from ..domain import *
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
11
14
 
12
15
 
13
16
  # *** contexts
14
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
+
15
155
  # ** context: app_interface_context
16
156
  class AppInterfaceContext(Model):
17
157
  '''
@@ -133,9 +273,10 @@ class AppInterfaceContext(Model):
133
273
  request, kwargs = self.parse_request(**kwargs)
134
274
 
135
275
  # Execute feature context and return session.
136
- # Handle error and return response if triggered.
137
276
  try:
138
277
  self.execute_feature(request, **kwargs)
278
+
279
+ # Handle error and return response if triggered.
139
280
  except Exception as e:
140
281
  print('Error:', e)
141
282
  return self.errors.handle_error(e)
@@ -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)
tiferet/data/app.py CHANGED
@@ -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
tiferet/domain/app.py CHANGED
@@ -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
+
tiferet/repos/app.py CHANGED
@@ -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
@@ -6,33 +6,30 @@ tiferet/commands/container.py,sha256=L2IKJqEbRglw_LC144oYAkARr2Rixj8IFuC6Ro1jAqA
6
6
  tiferet/commands/error.py,sha256=ixMYH0yrEWlMAVGDSRke3IGoWaOShfmiXntrUC2b3wY,573
7
7
  tiferet/commands/feature.py,sha256=tXa-MDf14ByIJqwQFeSUu2QLUjHPdsyvFNhj1XeaQVk,2507
8
8
  tiferet/configs/__init__.py,sha256=NfT6XFNcJznOLXjMuNmj3XeaOPVWwbc-N4kVWaVjuD0,845
9
- tiferet/contexts/__init__.py,sha256=HjI-9n29mFxN6ILSa3LBhLSVPRe-1V36ffQXSP9RavM,204
10
- tiferet/contexts/app.py,sha256=uCSUWZlhieyI97tFgJ0VzHqhBxrPo_if0CLCPEPBSaM,3783
11
- tiferet/contexts/container.py,sha256=qQzrAxGoq5yNqijMnVzE2wVwKprBmEVgiaBunnNcMd8,5704
9
+ tiferet/contexts/__init__.py,sha256=PvTgdVMav7B4pbKV4vxfNTMSod88DKGSR_0W8reIyC4,235
10
+ tiferet/contexts/app.py,sha256=90DAr0K09UzWbblarzP3Jw7lhADb2wjkaTFSIFJ8OnQ,8187
11
+ tiferet/contexts/container.py,sha256=Wo_2HENb7XPpIcZSkEikSGh8vWmClpLgkBbSW-jMDK4,6619
12
12
  tiferet/contexts/error.py,sha256=Gqewmk5WqbER9umNvR9gliQNi-bmbaNyXOSG4jUZfJc,3262
13
13
  tiferet/contexts/feature.py,sha256=kVVRpIyjWa3T2QoT2R-T7clOIQEpNMYa8ZJRVxgY_6o,3730
14
14
  tiferet/contexts/request.py,sha256=EwTyXVYi8z1t1ns_0yDrjY6qICIMPn1UvZpV7ULKReY,2756
15
15
  tiferet/data/__init__.py,sha256=JKaeCw508WY15-etqdFJxPUUJxMxCAi6ASmA472D1_s,93
16
- tiferet/data/app.py,sha256=TWWwP0MDpQ-LSKg9166CyPSeI7jjcklIfwBlLW_rT5c,9619
16
+ tiferet/data/app.py,sha256=dQXcC-A9oDJrwJCqkLSO9KyyldxtUjF7hGmfJqMzEXs,7881
17
17
  tiferet/data/container.py,sha256=o2HnLN1LasqWGP_S1Ub32CrCqYzehlD3dgXizW9XfU8,6154
18
18
  tiferet/data/error.py,sha256=Kllt0w62BAyShdVSwATN0LiVTeQHqkyQAN9_HuFg31Q,2339
19
19
  tiferet/data/feature.py,sha256=cjmm0lkmoFiCs0kyTDLH-OruTxTNJQf4BAkjtFu22Tk,2921
20
- tiferet/domain/__init__.py,sha256=H6mwtBHSlRZmYqXJcSVUIXLGLC7tNZZX22LuHU3b1ZI,224
21
- tiferet/domain/app.py,sha256=uRBKpPJa1IrDtnwQRtu2brDZBniFZcdaxOGOfUIN3e0,4808
20
+ tiferet/domain/__init__.py,sha256=vlZizSMkzaDYAZVHDB_YPaS3mo57vyW53DWaaSZhhkw,196
21
+ tiferet/domain/app.py,sha256=CYFK8KqkBqpAWNY45jMN-r_Tf7sell2R6pqquo7cmJg,3242
22
22
  tiferet/domain/container.py,sha256=wjal73hWAs5EvRO9XbrBBfdpV9nq9J89mAPbd4SH4ws,3666
23
23
  tiferet/domain/core.py,sha256=fOZeGxTJLGzY2zgAoSJu6rVJySpv-vCycT-WcEMk8kI,5152
24
24
  tiferet/domain/error.py,sha256=tWoJqg81LtfZfArN5OJRPVaZrAFcET0YUJJs52KHqYA,3853
25
25
  tiferet/domain/feature.py,sha256=drkCfhuIQhT05m61QzKdscaFdP0f-4K4tqO98lzXOjM,4866
26
26
  tiferet/repos/__init__.py,sha256=m6YLp90oqqs0cXQKOrDxudcc8P-AbeJ87a8okgoU7uI,171
27
- tiferet/repos/app.py,sha256=S7HM_iH_UkittmTZTO6Dxff9IYjXlE-QjG31X3bPnaA,2886
27
+ tiferet/repos/app.py,sha256=VxPanqWw4lGi1VoajTXN3sv9yy_XV6m_95E6DTdMHb8,2900
28
28
  tiferet/repos/container.py,sha256=n9Tz83QETdAocGAT4oKcvllEGwFp069pYqkXs2-KFFk,3519
29
29
  tiferet/repos/error.py,sha256=jDze41uioKwKEkAswkzLubVw-bxsVyeUkJwyeO5Es0E,4245
30
30
  tiferet/repos/feature.py,sha256=GxOV8XHNwz9YY3I8Wch6GaDskvkdi8l1hM9E9fCg1y0,3644
31
- tiferet/services/__init__.py,sha256=zB5elAFApNH435JLExPmWxvBmZcCtbAyai-KawUjr4E,101
32
- tiferet/services/app.py,sha256=92GvC-Vh8FDZoYMLdgzQ3iS1TVL4uyIErk7NJ4rpYPI,1462
33
- tiferet/services/container.py,sha256=ISJhkiNLV--nHbAv6Ajd3ug1cGiyazZoePJOCJu5n_s,1130
34
- tiferet-1.0.0a13.dist-info/LICENSE,sha256=e8_GutFM0sxbRlgUaeVsGvJ5uE-KvruLApOzIoHy_zU,1513
35
- tiferet-1.0.0a13.dist-info/METADATA,sha256=BYfB1FjgAaGADSuDhktzftuuxLGCr2Z6kGAyldRBLrA,536
36
- tiferet-1.0.0a13.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
37
- tiferet-1.0.0a13.dist-info/top_level.txt,sha256=g19Qw0j_VxPw-fgPF1TMPwbtHjnEhNQs0fa69wJZ6IM,8
38
- tiferet-1.0.0a13.dist-info/RECORD,,
31
+ tiferet-1.0.0a15.dist-info/LICENSE,sha256=e8_GutFM0sxbRlgUaeVsGvJ5uE-KvruLApOzIoHy_zU,1513
32
+ tiferet-1.0.0a15.dist-info/METADATA,sha256=g7VFuy4ajCOsjyL5Vxku8WSSOaTW8AkfM5fjTPAg7fE,536
33
+ tiferet-1.0.0a15.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
34
+ tiferet-1.0.0a15.dist-info/top_level.txt,sha256=g19Qw0j_VxPw-fgPF1TMPwbtHjnEhNQs0fa69wJZ6IM,8
35
+ tiferet-1.0.0a15.dist-info/RECORD,,
@@ -1,5 +0,0 @@
1
- # *** imports
2
-
3
- # ** app
4
- from . import container as container_service
5
- from . import app as app_service
tiferet/services/app.py DELETED
@@ -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})