buildzr 0.0.11__py3-none-any.whl → 0.0.13__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.
buildzr/__about__.py CHANGED
@@ -1 +1 @@
1
- VERSION = "0.0.11"
1
+ VERSION = "0.0.13"
buildzr/dsl/dsl.py CHANGED
@@ -29,7 +29,6 @@ from buildzr.dsl.interfaces import (
29
29
  DslWorkspaceElement,
30
30
  DslElement,
31
31
  DslViewElement,
32
- DslViewsElement,
33
32
  )
34
33
  from buildzr.dsl.relations import (
35
34
  DslElementRelationOverrides,
@@ -181,13 +180,43 @@ class Workspace(DslWorkspaceElement):
181
180
  else:
182
181
  raise ValueError('Invalid element type: Trying to add an element of type {} to a workspace.'.format(type(model)))
183
182
 
184
- def apply_views( self, *views: Union[ 'SystemLandscapeView',
183
+ def apply_view(
184
+ self,
185
+ view: Union[
186
+ 'SystemLandscapeView',
185
187
  'SystemContextView',
186
188
  'ContainerView',
187
189
  'ComponentView',
188
190
  ]
189
191
  ) -> None:
190
- Views(self).add_views(*views)
192
+
193
+ view._on_added(self)
194
+
195
+ if not self.model.views:
196
+ self.model.views = buildzr.models.Views()
197
+
198
+ if isinstance(view, SystemLandscapeView):
199
+ if not self.model.views.systemLandscapeViews:
200
+ self.model.views.systemLandscapeViews = [view.model]
201
+ else:
202
+ self.model.views.systemLandscapeViews.append(view.model)
203
+ elif isinstance(view, SystemContextView):
204
+ if not self.model.views.systemContextViews:
205
+ self.model.views.systemContextViews = [view.model]
206
+ else:
207
+ self.model.views.systemContextViews.append(view.model)
208
+ elif isinstance(view, ContainerView):
209
+ if not self.model.views.containerViews:
210
+ self.model.views.containerViews = [view.model]
211
+ else:
212
+ self.model.views.containerViews.append(view.model)
213
+ elif isinstance(view, ComponentView):
214
+ if not self.model.views.componentViews:
215
+ self.model.views.componentViews = [view.model]
216
+ else:
217
+ self.model.views.componentViews.append(view.model)
218
+ else:
219
+ raise NotImplementedError("The view {0} is currently not supported", type(view))
191
220
 
192
221
  def apply_style( self,
193
222
  style: Union['StyleElements', 'StyleRelationships'],
@@ -273,7 +302,7 @@ class SoftwareSystem(DslElementRelationOverrides[
273
302
  return self._destinations
274
303
 
275
304
  @property
276
- def relationships(self) -> Set[_Relationship]:
305
+ def relationships(self) -> Set[DslRelationship]:
277
306
  return self._relationships
278
307
 
279
308
  @property
@@ -287,7 +316,7 @@ class SoftwareSystem(DslElementRelationOverrides[
287
316
  self._children: Optional[List['Container']] = []
288
317
  self._sources: List[DslElement] = []
289
318
  self._destinations: List[DslElement] = []
290
- self._relationships: Set[_Relationship] = set()
319
+ self._relationships: Set[DslRelationship] = set()
291
320
  self._tags = {'Element', 'Software System'}.union(tags)
292
321
  self._dynamic_attrs: Dict[str, 'Container'] = {}
293
322
  self._label: Optional[str] = None
@@ -387,7 +416,7 @@ class Person(DslElementRelationOverrides[
387
416
  return self._destinations
388
417
 
389
418
  @property
390
- def relationships(self) -> Set[_Relationship]:
419
+ def relationships(self) -> Set[DslRelationship]:
391
420
  return self._relationships
392
421
 
393
422
  @property
@@ -399,7 +428,7 @@ class Person(DslElementRelationOverrides[
399
428
  self._parent: Optional[Workspace] = None
400
429
  self._sources: List[DslElement] = []
401
430
  self._destinations: List[DslElement] = []
402
- self._relationships: Set[_Relationship] = set()
431
+ self._relationships: Set[DslRelationship] = set()
403
432
  self._tags = {'Element', 'Person'}.union(tags)
404
433
  self._label: Optional[str] = None
405
434
  self.model.id = GenerateId.for_element()
@@ -458,7 +487,7 @@ class Container(DslElementRelationOverrides[
458
487
  return self._destinations
459
488
 
460
489
  @property
461
- def relationships(self) -> Set[_Relationship]:
490
+ def relationships(self) -> Set[DslRelationship]:
462
491
  return self._relationships
463
492
 
464
493
  @property
@@ -472,7 +501,7 @@ class Container(DslElementRelationOverrides[
472
501
  self._children: Optional[List['Component']] = []
473
502
  self._sources: List[DslElement] = []
474
503
  self._destinations: List[DslElement] = []
475
- self._relationships: Set[_Relationship] = set()
504
+ self._relationships: Set[DslRelationship] = set()
476
505
  self._tags = {'Element', 'Container'}.union(tags)
477
506
  self._dynamic_attrs: Dict[str, 'Component'] = {}
478
507
  self._label: Optional[str] = None
@@ -570,7 +599,7 @@ class Component(DslElementRelationOverrides[
570
599
  return self._destinations
571
600
 
572
601
  @property
573
- def relationships(self) -> Set[_Relationship]:
602
+ def relationships(self) -> Set[DslRelationship]:
574
603
  return self._relationships
575
604
 
576
605
  @property
@@ -582,7 +611,7 @@ class Component(DslElementRelationOverrides[
582
611
  self._parent: Optional[Container] = None
583
612
  self._sources: List[DslElement] = []
584
613
  self._destinations: List[DslElement] = []
585
- self._relationships: Set[_Relationship] = set()
614
+ self._relationships: Set[DslRelationship] = set()
586
615
  self._tags = {'Element', 'Component'}.union(tags)
587
616
  self._label: Optional[str] = None
588
617
  self.model.id = GenerateId.for_element()
@@ -738,30 +767,25 @@ def _auto_layout_to_model(auto_layout: _AutoLayout) -> buildzr.models.AutomaticL
738
767
 
739
768
  class SystemLandscapeView(DslViewElement):
740
769
 
741
- from buildzr.dsl.expression import Expression, Element, Relationship
770
+ from buildzr.dsl.expression import Expression, WorkspaceExpression, ElementExpression, RelationshipExpression
742
771
 
743
772
  @property
744
773
  def model(self) -> buildzr.models.SystemLandscapeView:
745
774
  return self._m
746
775
 
747
- @property
748
- def parent(self) -> Optional['Views']:
749
- return self._parent
750
-
751
776
  def __init__(
752
777
  self,
753
778
  key: str,
754
779
  description: str,
755
780
  auto_layout: _AutoLayout='tb',
756
781
  title: Optional[str]=None,
757
- include_elements: List[Union[DslElement, Callable[[Workspace, Element], bool]]]=[],
758
- exclude_elements: List[Union[DslElement, Callable[[Workspace, Element], bool]]]=[],
759
- include_relationships: List[Union[DslElement, Callable[[Workspace, Relationship], bool]]]=[],
760
- exclude_relationships: List[Union[DslElement, Callable[[Workspace, Relationship], bool]]]=[],
782
+ include_elements: List[Union[DslElement, Callable[[WorkspaceExpression, ElementExpression], bool]]]=[],
783
+ exclude_elements: List[Union[DslElement, Callable[[WorkspaceExpression, ElementExpression], bool]]]=[],
784
+ include_relationships: List[Union[DslElement, Callable[[WorkspaceExpression, RelationshipExpression], bool]]]=[],
785
+ exclude_relationships: List[Union[DslElement, Callable[[WorkspaceExpression, RelationshipExpression], bool]]]=[],
761
786
  properties: Optional[Dict[str, str]]=None,
762
787
  ) -> None:
763
788
  self._m = buildzr.models.SystemLandscapeView()
764
- self._parent: Optional['Views'] = None
765
789
 
766
790
  self._m.key = key
767
791
  self._m.description = description
@@ -777,11 +801,11 @@ class SystemLandscapeView(DslViewElement):
777
801
 
778
802
  workspace = _current_workspace.get()
779
803
  if workspace is not None:
780
- workspace.apply_views(self)
804
+ workspace.apply_view(self)
781
805
 
782
- def _on_added(self) -> None:
806
+ def _on_added(self, workspace: Workspace) -> None:
783
807
 
784
- from buildzr.dsl.expression import Expression, Element, Relationship
808
+ from buildzr.dsl.expression import Expression, WorkspaceExpression, ElementExpression, RelationshipExpression
785
809
  from buildzr.models import ElementView, RelationshipView
786
810
 
787
811
  expression = Expression(
@@ -791,19 +815,17 @@ class SystemLandscapeView(DslViewElement):
791
815
  exclude_relationships=self._exclude_relationships,
792
816
  )
793
817
 
794
- workspace = self._parent._parent
795
-
796
- include_view_elements_filter: List[Union[DslElement, Callable[[Workspace, Element], bool]]] = [
818
+ include_view_elements_filter: List[Union[DslElement, Callable[[WorkspaceExpression, ElementExpression], bool]]] = [
797
819
  lambda w, e: e.type == Person,
798
820
  lambda w, e: e.type == SoftwareSystem
799
821
  ]
800
822
 
801
- exclude_view_elements_filter: List[Union[DslElement, Callable[[Workspace, Element], bool]]] = [
823
+ exclude_view_elements_filter: List[Union[DslElement, Callable[[WorkspaceExpression, ElementExpression], bool]]] = [
802
824
  lambda w, e: e.type == Container,
803
825
  lambda w, e: e.type == Component,
804
826
  ]
805
827
 
806
- include_view_relationships_filter: List[Union[DslElement, Callable[[Workspace, Relationship], bool]]] = [
828
+ include_view_relationships_filter: List[Union[DslElement, Callable[[WorkspaceExpression, RelationshipExpression], bool]]] = [
807
829
  lambda w, r: r.source.type == Person,
808
830
  lambda w, r: r.source.type == SoftwareSystem,
809
831
  lambda w, r: r.destination.type == Person,
@@ -842,31 +864,26 @@ class SystemContextView(DslViewElement):
842
864
  relationship with the selected `SoftwareSystem`.
843
865
  """
844
866
 
845
- from buildzr.dsl.expression import Expression, Element, Relationship
867
+ from buildzr.dsl.expression import Expression, WorkspaceExpression, ElementExpression, RelationshipExpression
846
868
 
847
869
  @property
848
870
  def model(self) -> buildzr.models.SystemContextView:
849
871
  return self._m
850
872
 
851
- @property
852
- def parent(self) -> Optional['Views']:
853
- return self._parent
854
-
855
873
  def __init__(
856
874
  self,
857
- software_system_selector: Union[SoftwareSystem, Callable[[Workspace], SoftwareSystem]],
875
+ software_system_selector: Union[SoftwareSystem, Callable[[WorkspaceExpression], SoftwareSystem]],
858
876
  key: str,
859
877
  description: str,
860
878
  auto_layout: _AutoLayout='tb',
861
879
  title: Optional[str]=None,
862
- include_elements: List[Union[DslElement, Callable[[Workspace, Element], bool]]]=[],
863
- exclude_elements: List[Union[DslElement, Callable[[Workspace, Element], bool]]]=[],
864
- include_relationships: List[Union[DslElement, Callable[[Workspace, Relationship], bool]]]=[],
865
- exclude_relationships: List[Union[DslElement, Callable[[Workspace, Relationship], bool]]]=[],
880
+ include_elements: List[Union[DslElement, Callable[[WorkspaceExpression, ElementExpression], bool]]]=[],
881
+ exclude_elements: List[Union[DslElement, Callable[[WorkspaceExpression, ElementExpression], bool]]]=[],
882
+ include_relationships: List[Union[DslElement, Callable[[WorkspaceExpression, RelationshipExpression], bool]]]=[],
883
+ exclude_relationships: List[Union[DslElement, Callable[[WorkspaceExpression, RelationshipExpression], bool]]]=[],
866
884
  properties: Optional[Dict[str, str]]=None,
867
885
  ) -> None:
868
886
  self._m = buildzr.models.SystemContextView()
869
- self._parent: Optional['Views'] = None
870
887
 
871
888
  self._m.key = key
872
889
  self._m.description = description
@@ -883,25 +900,25 @@ class SystemContextView(DslViewElement):
883
900
 
884
901
  workspace = _current_workspace.get()
885
902
  if workspace is not None:
886
- workspace.apply_views(self)
903
+ workspace.apply_view(self)
887
904
 
888
- def _on_added(self) -> None:
905
+ def _on_added(self, workspace: Workspace) -> None:
889
906
 
890
- from buildzr.dsl.expression import Expression, Element, Relationship
907
+ from buildzr.dsl.expression import Expression, WorkspaceExpression, ElementExpression, RelationshipExpression
891
908
  from buildzr.models import ElementView, RelationshipView
892
909
 
893
910
  if isinstance(self._selector, SoftwareSystem):
894
911
  software_system = self._selector
895
912
  else:
896
- software_system = self._selector(self._parent._parent)
913
+ software_system = self._selector(WorkspaceExpression(workspace))
897
914
  self._m.softwareSystemId = software_system.model.id
898
- view_elements_filter: List[Union[DslElement, Callable[[Workspace, Element], bool]]] = [
915
+ view_elements_filter: List[Union[DslElement, Callable[[WorkspaceExpression, ElementExpression], bool]]] = [
899
916
  lambda w, e: e == software_system,
900
917
  lambda w, e: software_system.model.id in e.sources.ids,
901
918
  lambda w, e: software_system.model.id in e.destinations.ids,
902
919
  ]
903
920
 
904
- view_relationships_filter: List[Union[DslElement, Callable[[Workspace, Relationship], bool]]] = [
921
+ view_relationships_filter: List[Union[DslElement, Callable[[WorkspaceExpression, RelationshipExpression], bool]]] = [
905
922
  lambda w, r: software_system == r.source,
906
923
  lambda w, r: software_system == r.destination,
907
924
  ]
@@ -913,8 +930,6 @@ class SystemContextView(DslViewElement):
913
930
  exclude_relationships=self._exclude_relationships,
914
931
  )
915
932
 
916
- workspace = self._parent._parent
917
-
918
933
  element_ids = map(
919
934
  lambda x: str(x.model.id),
920
935
  expression.elements(workspace)
@@ -935,31 +950,26 @@ class SystemContextView(DslViewElement):
935
950
 
936
951
  class ContainerView(DslViewElement):
937
952
 
938
- from buildzr.dsl.expression import Expression, Element, Relationship
953
+ from buildzr.dsl.expression import Expression, WorkspaceExpression, ElementExpression, RelationshipExpression
939
954
 
940
955
  @property
941
956
  def model(self) -> buildzr.models.ContainerView:
942
957
  return self._m
943
958
 
944
- @property
945
- def parent(self) -> Optional['Views']:
946
- return self._parent
947
-
948
959
  def __init__(
949
960
  self,
950
- software_system_selector: Union[SoftwareSystem, Callable[[Workspace], SoftwareSystem]],
961
+ software_system_selector: Union[SoftwareSystem, Callable[[WorkspaceExpression], SoftwareSystem]],
951
962
  key: str,
952
963
  description: str,
953
964
  auto_layout: _AutoLayout='tb',
954
965
  title: Optional[str]=None,
955
- include_elements: List[Union[DslElement, Callable[[Workspace, Element], bool]]]=[],
956
- exclude_elements: List[Union[DslElement, Callable[[Workspace, Element], bool]]]=[],
957
- include_relationships: List[Union[DslElement, Callable[[Workspace, Relationship], bool]]]=[],
958
- exclude_relationships: List[Union[DslElement, Callable[[Workspace, Relationship], bool]]]=[],
966
+ include_elements: List[Union[DslElement, Callable[[WorkspaceExpression, ElementExpression], bool]]]=[],
967
+ exclude_elements: List[Union[DslElement, Callable[[WorkspaceExpression, ElementExpression], bool]]]=[],
968
+ include_relationships: List[Union[DslElement, Callable[[WorkspaceExpression, RelationshipExpression], bool]]]=[],
969
+ exclude_relationships: List[Union[DslElement, Callable[[WorkspaceExpression, RelationshipExpression], bool]]]=[],
959
970
  properties: Optional[Dict[str, str]]=None,
960
971
  ) -> None:
961
972
  self._m = buildzr.models.ContainerView()
962
- self._parent: Optional['Views'] = None
963
973
 
964
974
  self._m.key = key
965
975
  self._m.description = description
@@ -976,28 +986,28 @@ class ContainerView(DslViewElement):
976
986
 
977
987
  workspace = _current_workspace.get()
978
988
  if workspace is not None:
979
- workspace.apply_views(self)
989
+ workspace.apply_view(self)
980
990
 
981
- def _on_added(self) -> None:
991
+ def _on_added(self, workspace: Workspace) -> None:
982
992
 
983
- from buildzr.dsl.expression import Expression, Element, Relationship
993
+ from buildzr.dsl.expression import Expression, WorkspaceExpression, ElementExpression, RelationshipExpression
984
994
  from buildzr.models import ElementView, RelationshipView
985
995
 
986
996
  if isinstance(self._selector, SoftwareSystem):
987
997
  software_system = self._selector
988
998
  else:
989
- software_system = self._selector(self._parent._parent)
999
+ software_system = self._selector(WorkspaceExpression(workspace))
990
1000
  self._m.softwareSystemId = software_system.model.id
991
1001
 
992
1002
  container_ids = { container.model.id for container in software_system.children}
993
1003
 
994
- view_elements_filter: List[Union[DslElement, Callable[[Workspace, Element], bool]]] = [
1004
+ view_elements_filter: List[Union[DslElement, Callable[[WorkspaceExpression, ElementExpression], bool]]] = [
995
1005
  lambda w, e: e.parent == software_system,
996
1006
  lambda w, e: any(container_ids.intersection({ id for id in e.sources.ids })),
997
1007
  lambda w, e: any(container_ids.intersection({ id for id in e.destinations.ids })),
998
1008
  ]
999
1009
 
1000
- view_relationships_filter: List[Union[DslElement, Callable[[Workspace, Relationship], bool]]] = [
1010
+ view_relationships_filter: List[Union[DslElement, Callable[[WorkspaceExpression, RelationshipExpression], bool]]] = [
1001
1011
  lambda w, r: software_system == r.source.parent,
1002
1012
  lambda w, r: software_system == r.destination.parent,
1003
1013
  ]
@@ -1009,8 +1019,6 @@ class ContainerView(DslViewElement):
1009
1019
  exclude_relationships=self._exclude_relationships,
1010
1020
  )
1011
1021
 
1012
- workspace = self._parent._parent
1013
-
1014
1022
  element_ids = map(
1015
1023
  lambda x: str(x.model.id),
1016
1024
  expression.elements(workspace)
@@ -1031,31 +1039,26 @@ class ContainerView(DslViewElement):
1031
1039
 
1032
1040
  class ComponentView(DslViewElement):
1033
1041
 
1034
- from buildzr.dsl.expression import Expression, Element, Relationship
1042
+ from buildzr.dsl.expression import Expression, WorkspaceExpression, ElementExpression, RelationshipExpression
1035
1043
 
1036
1044
  @property
1037
1045
  def model(self) -> buildzr.models.ComponentView:
1038
1046
  return self._m
1039
1047
 
1040
- @property
1041
- def parent(self) -> Optional['Views']:
1042
- return self._parent
1043
-
1044
1048
  def __init__(
1045
1049
  self,
1046
- container_selector: Union[Container, Callable[[Workspace], Container]],
1050
+ container_selector: Union[Container, Callable[[WorkspaceExpression], Container]],
1047
1051
  key: str,
1048
1052
  description: str,
1049
1053
  auto_layout: _AutoLayout='tb',
1050
1054
  title: Optional[str]=None,
1051
- include_elements: List[Union[DslElement, Callable[[Workspace, Element], bool]]]=[],
1052
- exclude_elements: List[Union[DslElement, Callable[[Workspace, Element], bool]]]=[],
1053
- include_relationships: List[Union[DslElement, Callable[[Workspace, Relationship], bool]]]=[],
1054
- exclude_relationships: List[Union[DslElement, Callable[[Workspace, Relationship], bool]]]=[],
1055
+ include_elements: List[Union[DslElement, Callable[[WorkspaceExpression, ElementExpression], bool]]]=[],
1056
+ exclude_elements: List[Union[DslElement, Callable[[WorkspaceExpression, ElementExpression], bool]]]=[],
1057
+ include_relationships: List[Union[DslElement, Callable[[WorkspaceExpression, RelationshipExpression], bool]]]=[],
1058
+ exclude_relationships: List[Union[DslElement, Callable[[WorkspaceExpression, RelationshipExpression], bool]]]=[],
1055
1059
  properties: Optional[Dict[str, str]]=None,
1056
1060
  ) -> None:
1057
1061
  self._m = buildzr.models.ComponentView()
1058
- self._parent: Optional['Views'] = None
1059
1062
 
1060
1063
  self._m.key = key
1061
1064
  self._m.description = description
@@ -1072,28 +1075,28 @@ class ComponentView(DslViewElement):
1072
1075
 
1073
1076
  workspace = _current_workspace.get()
1074
1077
  if workspace is not None:
1075
- workspace.apply_views(self)
1078
+ workspace.apply_view(self)
1076
1079
 
1077
- def _on_added(self) -> None:
1080
+ def _on_added(self, workspace: Workspace) -> None:
1078
1081
 
1079
- from buildzr.dsl.expression import Expression, Element, Relationship
1082
+ from buildzr.dsl.expression import Expression, WorkspaceExpression, ElementExpression, RelationshipExpression
1080
1083
  from buildzr.models import ElementView, RelationshipView
1081
1084
 
1082
1085
  if isinstance(self._selector, Container):
1083
1086
  container = self._selector
1084
1087
  else:
1085
- container = self._selector(self._parent._parent)
1088
+ container = self._selector(WorkspaceExpression(workspace))
1086
1089
  self._m.containerId = container.model.id
1087
1090
 
1088
1091
  component_ids = { component.model.id for component in container.children }
1089
1092
 
1090
- view_elements_filter: List[Union[DslElement, Callable[[Workspace, Element], bool]]] = [
1093
+ view_elements_filter: List[Union[DslElement, Callable[[WorkspaceExpression, ElementExpression], bool]]] = [
1091
1094
  lambda w, e: e.parent == container,
1092
1095
  lambda w, e: any(component_ids.intersection({ id for id in e.sources.ids })),
1093
1096
  lambda w, e: any(component_ids.intersection({ id for id in e.destinations.ids })),
1094
1097
  ]
1095
1098
 
1096
- view_relationships_filter: List[Union[DslElement, Callable[[Workspace, Relationship], bool]]] = [
1099
+ view_relationships_filter: List[Union[DslElement, Callable[[WorkspaceExpression, RelationshipExpression], bool]]] = [
1097
1100
  lambda w, r: container == r.source.parent,
1098
1101
  lambda w, r: container == r.destination.parent,
1099
1102
  ]
@@ -1105,8 +1108,6 @@ class ComponentView(DslViewElement):
1105
1108
  exclude_relationships=self._exclude_relationships,
1106
1109
  )
1107
1110
 
1108
- workspace = self._parent._parent
1109
-
1110
1111
  element_ids = map(
1111
1112
  lambda x: str(x.model.id),
1112
1113
  expression.elements(workspace)
@@ -1125,73 +1126,9 @@ class ComponentView(DslViewElement):
1125
1126
  for relationship_id in relationship_ids:
1126
1127
  self._m.relationships.append(RelationshipView(id=relationship_id))
1127
1128
 
1128
- class Views(DslViewsElement):
1129
-
1130
- # TODO: Make this view a "hidden" class -- it's not a "first class citizen"
1131
- # in buildzr DSL.
1132
-
1133
- @property
1134
- def model(self) -> buildzr.models.Views:
1135
- return self._m
1136
-
1137
- @property
1138
- def parent(self) -> Optional[Workspace]:
1139
- return self._parent
1140
-
1141
- def __init__(
1142
- self,
1143
- workspace: Workspace,
1144
- ) -> None:
1145
- self._m = buildzr.models.Views()
1146
- self._parent = workspace
1147
- self._parent._m.views = self._m
1148
-
1149
- def add_views(
1150
- self,
1151
- *views: DslViewElement
1152
- ) -> None:
1153
-
1154
- for view in views:
1155
- if isinstance(view, SystemLandscapeView):
1156
- view._parent = self
1157
- view._on_added()
1158
- if self._m.systemLandscapeViews:
1159
- self._m.systemLandscapeViews.append(view.model)
1160
- else:
1161
- self._m.systemLandscapeViews = [view.model]
1162
- elif isinstance(view, SystemContextView):
1163
- view._parent = self
1164
- view._on_added()
1165
- if self._m.systemContextViews:
1166
- self._m.systemContextViews.append(view.model)
1167
- else:
1168
- self._m.systemContextViews = [view.model]
1169
- elif isinstance(view, ContainerView):
1170
- view._parent = self
1171
- view._on_added()
1172
- if self._m.containerViews:
1173
- self._m.containerViews.append(view.model)
1174
- else:
1175
- self._m.containerViews = [view.model]
1176
- elif isinstance(view, ComponentView):
1177
- view._parent = self
1178
- view._on_added()
1179
- if self._m.componentViews:
1180
- self._m.componentViews.append(view.model)
1181
- else:
1182
- self._m.componentViews = [view.model]
1183
- else:
1184
- raise NotImplementedError("The view {0} is currently not supported", type(view))
1185
-
1186
- def get_workspace(self) -> Workspace:
1187
- """
1188
- Get the `Workspace` which contain this views definition.
1189
- """
1190
- return self._parent
1191
-
1192
1129
  class StyleElements:
1193
1130
 
1194
- from buildzr.dsl.expression import Element
1131
+ from buildzr.dsl.expression import WorkspaceExpression, ElementExpression
1195
1132
 
1196
1133
  Shapes = Union[
1197
1134
  Literal['Box'],
@@ -1224,7 +1161,7 @@ class StyleElements:
1224
1161
  on: List[Union[
1225
1162
  DslElement,
1226
1163
  Group,
1227
- Callable[[Workspace, Element], bool],
1164
+ Callable[[WorkspaceExpression, ElementExpression], bool],
1228
1165
  Type[Union['Person', 'SoftwareSystem', 'Container', 'Component']],
1229
1166
  str
1230
1167
  ]],
@@ -1267,7 +1204,7 @@ class StyleElements:
1267
1204
  # item, not for each of `StyleElements` instance. This makes the styling
1268
1205
  # makes more concise and flexible.
1269
1206
 
1270
- from buildzr.dsl.expression import Element
1207
+ from buildzr.dsl.expression import ElementExpression
1271
1208
  from uuid import uuid4
1272
1209
 
1273
1210
  if background:
@@ -1340,7 +1277,7 @@ class StyleElements:
1340
1277
  elif isinstance(element, str):
1341
1278
  element_style.tag = element
1342
1279
  elif callable(element):
1343
- from buildzr.dsl.expression import Element, Expression
1280
+ from buildzr.dsl.expression import ElementExpression, Expression
1344
1281
  if self._parent:
1345
1282
  matched_elems = Expression(include_elements=[element]).elements(self._parent)
1346
1283
  for e in matched_elems:
@@ -1356,7 +1293,7 @@ class StyleElements:
1356
1293
 
1357
1294
  class StyleRelationships:
1358
1295
 
1359
- from buildzr.dsl.expression import Relationship
1296
+ from buildzr.dsl.expression import WorkspaceExpression, RelationshipExpression
1360
1297
 
1361
1298
  @property
1362
1299
  def model(self) -> List[buildzr.models.RelationshipStyle]:
@@ -1371,7 +1308,7 @@ class StyleRelationships:
1371
1308
  on: Optional[List[Union[
1372
1309
  DslRelationship,
1373
1310
  Group,
1374
- Callable[[Workspace, Relationship], bool],
1311
+ Callable[[WorkspaceExpression, RelationshipExpression], bool],
1375
1312
  str
1376
1313
  ]]]=None,
1377
1314
  thickness: Optional[int]=None,
buildzr/dsl/explorer.py CHANGED
@@ -14,12 +14,17 @@ from typing import (
14
14
  Union,
15
15
  Generator,
16
16
  Iterable,
17
+ cast,
17
18
  )
18
19
 
19
20
  from buildzr.dsl.dsl import (
20
21
  Workspace,
21
22
  )
22
23
 
24
+ from buildzr.dsl.interfaces import (
25
+ DslRelationship,
26
+ )
27
+
23
28
  class Explorer:
24
29
 
25
30
  def __init__(self, workspace_or_element: Union[Workspace, Person, SoftwareSystem, Container, Component]):
@@ -32,7 +37,7 @@ class Explorer:
32
37
  yield child
33
38
  yield from explorer
34
39
 
35
- def walk_relationships(self) -> Generator[_Relationship, None, None]:
40
+ def walk_relationships(self) -> Generator[DslRelationship, None, None]:
36
41
 
37
42
  if self._workspace_or_element.children:
38
43
 
@@ -40,7 +45,7 @@ class Explorer:
40
45
 
41
46
  if child.relationships:
42
47
  for relationship in child.relationships:
43
- yield relationship
48
+ yield cast(_Relationship, relationship) # TODO: Temporary fix. Use a better approach - Generics?
44
49
 
45
50
  explorer = Explorer(child).walk_relationships()
46
51
  yield from explorer
buildzr/dsl/expression.py CHANGED
@@ -10,6 +10,7 @@ from buildzr.dsl.dsl import (
10
10
  SoftwareSystem,
11
11
  Container,
12
12
  Component,
13
+ TypedDynamicAttribute,
13
14
  )
14
15
 
15
16
  from buildzr.dsl.relations import _Relationship
@@ -47,12 +48,37 @@ class FlattenElement:
47
48
  all_tags = all_tags.union(tags)
48
49
  return all_tags
49
50
 
50
- class Element:
51
+ class WorkspaceExpression:
52
+
53
+ """
54
+ A class used to filter the allowable methods and properties of the
55
+ `Structurizr DSL` workspace. This is used to filter the elements and
56
+ relationships in the workspace.
57
+ """
58
+
59
+ def __init__(self, workspace: Workspace):
60
+ self._workspace = workspace
61
+ self._dynamic_attributes = self._workspace._dynamic_attrs
62
+
63
+ def software_system(self) -> TypedDynamicAttribute['SoftwareSystem']:
64
+ """
65
+ Returns the software system of the workspace. This is used to filter the
66
+ elements and relationships in the workspace.
67
+ """
68
+ return TypedDynamicAttribute['SoftwareSystem'](self._dynamic_attributes)
69
+
70
+ def person(self) -> TypedDynamicAttribute['Person']:
71
+ """
72
+ Returns the person of the workspace. This is used to filter the elements
73
+ and relationships in the workspace.
74
+ """
75
+ return TypedDynamicAttribute['Person'](self._dynamic_attributes)
76
+
77
+ class ElementExpression:
51
78
 
52
79
  def __init__(self, element: DslElement):
53
80
  self._element = element
54
81
 
55
- # TODO: Make a test for this in `tests/test_expression.py`
56
82
  @property
57
83
  def id(self) -> str:
58
84
  return cast(str, self._element.model.id)
@@ -102,9 +128,9 @@ class Element:
102
128
  return isinstance(element, type(self._element)) and\
103
129
  element.model.id == self._element.model.id
104
130
 
105
- class Relationship:
131
+ class RelationshipExpression:
106
132
 
107
- def __init__(self, relationship: _Relationship):
133
+ def __init__(self, relationship: DslRelationship):
108
134
  self._relationship = relationship
109
135
 
110
136
  # TODO: Make a test for this in `tests/test_expression.py`
@@ -121,12 +147,12 @@ class Relationship:
121
147
  return self._relationship.model.technology
122
148
 
123
149
  @property
124
- def source(self) -> Element:
125
- return Element(self._relationship.source)
150
+ def source(self) -> ElementExpression:
151
+ return ElementExpression(self._relationship.source)
126
152
 
127
153
  @property
128
- def destination(self) -> Element:
129
- return Element(self._relationship.destination)
154
+ def destination(self) -> ElementExpression:
155
+ return ElementExpression(self._relationship.destination)
130
156
 
131
157
  @property
132
158
  def properties(self) -> Dict[str, Any]:
@@ -146,10 +172,10 @@ class Expression:
146
172
 
147
173
  def __init__(
148
174
  self,
149
- include_elements: Iterable[Union[DslElement, Callable[[Workspace, Element], bool]]]=[lambda w, e: True],
150
- exclude_elements: Iterable[Union[DslElement, Callable[[Workspace, Element], bool]]]=[],
151
- include_relationships: Iterable[Union[DslElement, Callable[[Workspace, Relationship], bool]]]=[lambda w, e: True],
152
- exclude_relationships: Iterable[Union[DslElement, Callable[[Workspace, Relationship], bool]]]=[],
175
+ include_elements: Iterable[Union[DslElement, Callable[[WorkspaceExpression, ElementExpression], bool]]]=[lambda w, e: True],
176
+ exclude_elements: Iterable[Union[DslElement, Callable[[WorkspaceExpression, ElementExpression], bool]]]=[],
177
+ include_relationships: Iterable[Union[DslElement, Callable[[WorkspaceExpression, RelationshipExpression], bool]]]=[lambda w, e: True],
178
+ exclude_relationships: Iterable[Union[DslElement, Callable[[WorkspaceExpression, RelationshipExpression], bool]]]=[],
153
179
  ) -> 'None':
154
180
  self._include_elements = include_elements
155
181
  self._exclude_elements = exclude_elements
@@ -171,12 +197,12 @@ class Expression:
171
197
  if isinstance(f, DslElement):
172
198
  includes.append(f == element)
173
199
  else:
174
- includes.append(f(workspace, Element(element)))
200
+ includes.append(f(WorkspaceExpression(workspace), ElementExpression(element)))
175
201
  for f in self._exclude_elements:
176
202
  if isinstance(f, DslElement):
177
203
  excludes.append(f == element)
178
204
  else:
179
- excludes.append(f(workspace, Element(element)))
205
+ excludes.append(f(WorkspaceExpression(workspace), ElementExpression(element)))
180
206
  if any(includes) and not any(excludes):
181
207
  filtered_elements.append(element)
182
208
 
@@ -198,9 +224,9 @@ class Expression:
198
224
  filtered_relationships: List[DslRelationship] = []
199
225
 
200
226
  def _is_relationship_of_excluded_elements(
201
- workspace: Workspace,
202
- relationship: Relationship,
203
- exclude_element_predicates: Iterable[Union[DslElement, Callable[[Workspace, Element], bool]]],
227
+ workspace: WorkspaceExpression,
228
+ relationship: RelationshipExpression,
229
+ exclude_element_predicates: Iterable[Union[DslElement, Callable[[WorkspaceExpression, ElementExpression], bool]]],
204
230
  ) -> bool:
205
231
  for f in exclude_element_predicates:
206
232
  if isinstance(f, DslElement):
@@ -222,20 +248,20 @@ class Expression:
222
248
  if isinstance(f, DslElement):
223
249
  includes.append(f == relationship)
224
250
  else:
225
- includes.append(f(workspace, Relationship(relationship)))
251
+ includes.append(f(WorkspaceExpression(workspace), RelationshipExpression(relationship)))
226
252
 
227
253
  for f in self._exclude_relationships:
228
254
  if isinstance(f, DslElement):
229
255
  excludes.append(f == relationship)
230
256
  else:
231
- excludes.append(f(workspace, Relationship(relationship)))
257
+ excludes.append(f(WorkspaceExpression(workspace), RelationshipExpression(relationship)))
232
258
 
233
259
  # Also exclude relationships whose source or destination elements
234
260
  # are excluded.
235
261
  excludes.append(
236
262
  _is_relationship_of_excluded_elements(
237
- workspace,
238
- Relationship(relationship),
263
+ WorkspaceExpression(workspace),
264
+ RelationshipExpression(relationship),
239
265
  self._exclude_elements,
240
266
  )
241
267
  )
@@ -3,7 +3,6 @@ from .interfaces import (
3
3
  DslRelationship,
4
4
  DslWorkspaceElement,
5
5
  DslViewElement,
6
- DslViewsElement,
7
6
  BindLeft,
8
7
  BindRight,
9
8
  BindLeftLate,
@@ -205,31 +205,4 @@ class DslViewElement(ABC):
205
205
  @property
206
206
  @abstractmethod
207
207
  def model(self) -> ViewModel:
208
- pass
209
-
210
- @property
211
- @abstractmethod
212
- def parent(self) -> 'DslViewsElement':
213
- pass
214
-
215
- def _on_added(self) -> None:
216
- pass
217
-
218
- class DslViewsElement(ABC):
219
-
220
- @property
221
- @abstractmethod
222
- def model(self) -> buildzr.models.Views:
223
- pass
224
-
225
- @property
226
- @abstractmethod
227
- def parent(self) -> DslWorkspaceElement:
228
- pass
229
-
230
- @abstractmethod
231
- def add_views(
232
- self,
233
- *views: Union[DslViewElement],
234
- ) -> None:
235
208
  pass
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: buildzr
3
- Version: 0.0.11
3
+ Version: 0.0.13
4
4
  Summary: Structurizr for the `buildzr`s 🧱⚒️
5
5
  Project-URL: homepage, https://github.com/amirulmenjeni/buildzr
6
6
  Project-URL: issues, https://github.com/amirulmenjeni/buildzr/issues
@@ -1,15 +1,15 @@
1
- buildzr/__about__.py,sha256=bj0hPvAeGyNerr-JDHit8pvb9_bqoEjX9AlWuS88Xhs,18
1
+ buildzr/__about__.py,sha256=0umS7uDo4dgXIWRbDuyPpvLwiPObPtpkbuCwUnINda0,18
2
2
  buildzr/__init__.py,sha256=hY-cOdjBQcz0v2m8cBF1oEJFIbcR3sWI-xww--0RKSo,99
3
3
  buildzr/dsl/__init__.py,sha256=k0G9blhA3NSzCBs1dSfBNzCh0iDS_ylkzS_5a3pqrSY,375
4
4
  buildzr/dsl/color.py,sha256=at5lo3WgLEDCjrnbu37ra1p1TjzdB51sxeW7pBMC_7U,4019
5
- buildzr/dsl/dsl.py,sha256=47_O2OqN6XR7MNZnmJK2EaX8JPZrGu-h5YEVEaLUwdM,54154
6
- buildzr/dsl/explorer.py,sha256=vLAgQEYd0h22QuVfWfBdk4zyDpGaE1T67Pn9V7P1C-I,1238
7
- buildzr/dsl/expression.py,sha256=EMAtaZQA0O_zwENCZs3l4u_w9wUuO09XA0LgnvsomfA,8256
5
+ buildzr/dsl/dsl.py,sha256=EXHGvC84Xz8ba2f3XMTS3HLqfrkxc8D905IThJu_WUM,53644
6
+ buildzr/dsl/explorer.py,sha256=GuQihoEvmTwiriXT3X8oasJ_U65ERyKJeJ2WW-S9D84,1389
7
+ buildzr/dsl/expression.py,sha256=Q4lK6tWETLg_YfLTGuT20Gl2dsWp6m5_8PhlTF_dJbw,9525
8
8
  buildzr/dsl/relations.py,sha256=GBs5epr9uuExU_H6VcP4XY76iJPQ__rz_d8tZlhhWQ4,11891
9
9
  buildzr/dsl/factory/__init__.py,sha256=niaYqvNPUWJejoPyRyABUtzVsoxaV8eSjzS9dta4bMI,30
10
10
  buildzr/dsl/factory/gen_id.py,sha256=LnaeOCMngSvYkcGnuARjQYoUVWdcOoNHO2EHe6PMGco,538
11
- buildzr/dsl/interfaces/__init__.py,sha256=ncYARIPB4ARcCCRObgV1b4jluEubpm2s46mp1ZC8Urk,197
12
- buildzr/dsl/interfaces/interfaces.py,sha256=j8UCPCRegmFZ2Jl4qCz0uW0OxBS2mRe0VjPcNExH8mc,5553
11
+ buildzr/dsl/interfaces/__init__.py,sha256=GRzfjdDxAUaZ-2n-eP4YaGLy3b0_giHhMshGqoj9rbo,176
12
+ buildzr/dsl/interfaces/interfaces.py,sha256=OYOS-eGlkadGWXvcLSP1Qs9AnJfhtoJGh9UqJRC8gDk,5079
13
13
  buildzr/encoders/__init__.py,sha256=suID63Ay-023T0uKD25EAoGYmAMTa9AKxIjioccpiPM,32
14
14
  buildzr/encoders/encoder.py,sha256=n8WLVMrisykBTLTr1z6PAxgqhqW2dFRZhSupOuMdx_A,3235
15
15
  buildzr/models/__init__.py,sha256=SRfF7oDVlOOAi6nGKiJIUK6B_arqYLO9iSMp-2IZZps,21
@@ -18,7 +18,7 @@ buildzr/models/models.py,sha256=0LhLG1wmbt4dvROV5MEBZLLoxPbMpkUsOqNz525cynE,4248
18
18
  buildzr/sinks/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
19
19
  buildzr/sinks/interfaces.py,sha256=LOZekP4WNjomD5J5f3FnZTwGj0aXMr6RbrvyFV5zn0E,383
20
20
  buildzr/sinks/json_sink.py,sha256=onKOZTpwOQfeMEj1ONkuIEHBAQhx4yQSqqI_lgZBaP8,777
21
- buildzr-0.0.11.dist-info/METADATA,sha256=y7VRNvZySrY7DsNV19V23WrYiOyx2VxLjcR_QkpSmSA,6579
22
- buildzr-0.0.11.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
23
- buildzr-0.0.11.dist-info/licenses/LICENSE.md,sha256=e8e6W6tL4MbBY-c-gXMgDbaMf_BnaQDQv4Yoy42b-CI,1070
24
- buildzr-0.0.11.dist-info/RECORD,,
21
+ buildzr-0.0.13.dist-info/METADATA,sha256=oz1_tOasiJ4EKOqtPpO45Bq8jmoua3eoohE9mbK_CdQ,6579
22
+ buildzr-0.0.13.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
23
+ buildzr-0.0.13.dist-info/licenses/LICENSE.md,sha256=e8e6W6tL4MbBY-c-gXMgDbaMf_BnaQDQv4Yoy42b-CI,1070
24
+ buildzr-0.0.13.dist-info/RECORD,,