sysml 0.1.0__py3-none-win_amd64.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.
- sysml/__init__.py +5 -0
- sysml/_native/RUST-STANDARD-LIBRARY-NOTICES.html +29357 -0
- sysml/_native/THIRD-PARTY-NOTICES.txt +1102 -0
- sysml/_native/sysmlv2_abi.dll +0 -0
- sysml/base.py +358 -0
- sysml/classes.py +14291 -0
- sysml/classes.pyi +13769 -0
- sysml/library.py +151 -0
- sysml/stdlib/Domain Libraries/Analysis/.meta.json +10 -0
- sysml/stdlib/Domain Libraries/Analysis/.project.json +27 -0
- sysml/stdlib/Domain Libraries/Analysis/AnalysisTooling.sysml +34 -0
- sysml/stdlib/Domain Libraries/Analysis/SampledFunctions.sysml +119 -0
- sysml/stdlib/Domain Libraries/Analysis/StateSpaceRepresentation.sysml +143 -0
- sysml/stdlib/Domain Libraries/Analysis/TradeStudies.sysml +171 -0
- sysml/stdlib/Domain Libraries/Cause and Effect/.meta.json +8 -0
- sysml/stdlib/Domain Libraries/Cause and Effect/.project.json +23 -0
- sysml/stdlib/Domain Libraries/Cause and Effect/CausationConnections.sysml +83 -0
- sysml/stdlib/Domain Libraries/Cause and Effect/CauseAndEffect.sysml +81 -0
- sysml/stdlib/Domain Libraries/Geometry/.meta.json +8 -0
- sysml/stdlib/Domain Libraries/Geometry/.project.json +27 -0
- sysml/stdlib/Domain Libraries/Geometry/ShapeItems.sysml +899 -0
- sysml/stdlib/Domain Libraries/Geometry/SpatialItems.sysml +168 -0
- sysml/stdlib/Domain Libraries/Metadata/.meta.json +10 -0
- sysml/stdlib/Domain Libraries/Metadata/.project.json +19 -0
- sysml/stdlib/Domain Libraries/Metadata/ImageMetadata.sysml +78 -0
- sysml/stdlib/Domain Libraries/Metadata/ModelingMetadata.sysml +143 -0
- sysml/stdlib/Domain Libraries/Metadata/ParametersOfInterestMetadata.sysml +39 -0
- sysml/stdlib/Domain Libraries/Metadata/RiskMetadata.sysml +100 -0
- sysml/stdlib/Domain Libraries/Quantities and Units/.meta.json +30 -0
- sysml/stdlib/Domain Libraries/Quantities and Units/.project.json +23 -0
- sysml/stdlib/Domain Libraries/Quantities and Units/ISQ.sysml +42 -0
- sysml/stdlib/Domain Libraries/Quantities and Units/ISQAcoustics.sysml +439 -0
- sysml/stdlib/Domain Libraries/Quantities and Units/ISQAtomicNuclear.sysml +2726 -0
- sysml/stdlib/Domain Libraries/Quantities and Units/ISQBase.sysml +206 -0
- sysml/stdlib/Domain Libraries/Quantities and Units/ISQCharacteristicNumbers.sysml +1991 -0
- sysml/stdlib/Domain Libraries/Quantities and Units/ISQChemistryMolecular.sysml +1353 -0
- sysml/stdlib/Domain Libraries/Quantities and Units/ISQCondensedMatter.sysml +1223 -0
- sysml/stdlib/Domain Libraries/Quantities and Units/ISQElectromagnetism.sysml +2333 -0
- sysml/stdlib/Domain Libraries/Quantities and Units/ISQInformation.sysml +958 -0
- sysml/stdlib/Domain Libraries/Quantities and Units/ISQLight.sysml +1537 -0
- sysml/stdlib/Domain Libraries/Quantities and Units/ISQMechanics.sysml +1564 -0
- sysml/stdlib/Domain Libraries/Quantities and Units/ISQSpaceTime.sysml +1169 -0
- sysml/stdlib/Domain Libraries/Quantities and Units/ISQThermodynamics.sysml +1256 -0
- sysml/stdlib/Domain Libraries/Quantities and Units/MeasurementRefCalculations.sysml +30 -0
- sysml/stdlib/Domain Libraries/Quantities and Units/MeasurementReferences.sysml +526 -0
- sysml/stdlib/Domain Libraries/Quantities and Units/Quantities.sysml +107 -0
- sysml/stdlib/Domain Libraries/Quantities and Units/QuantityCalculations.sysml +70 -0
- sysml/stdlib/Domain Libraries/Quantities and Units/SI.sysml +378 -0
- sysml/stdlib/Domain Libraries/Quantities and Units/SIPrefixes.sysml +48 -0
- sysml/stdlib/Domain Libraries/Quantities and Units/TensorCalculations.sysml +50 -0
- sysml/stdlib/Domain Libraries/Quantities and Units/Time.sysml +274 -0
- sysml/stdlib/Domain Libraries/Quantities and Units/USCustomaryUnits.sysml +260 -0
- sysml/stdlib/Domain Libraries/Quantities and Units/VectorCalculations.sysml +62 -0
- sysml/stdlib/Domain Libraries/Requirement Derivation/.meta.json +8 -0
- sysml/stdlib/Domain Libraries/Requirement Derivation/.project.json +19 -0
- sysml/stdlib/Domain Libraries/Requirement Derivation/DerivationConnections.sysml +63 -0
- sysml/stdlib/Domain Libraries/Requirement Derivation/RequirementDerivation.sysml +39 -0
- sysml/stdlib/Kernel Libraries/Kernel Data Type Library/.meta.json +9 -0
- sysml/stdlib/Kernel Libraries/Kernel Data Type Library/.project.json +11 -0
- sysml/stdlib/Kernel Libraries/Kernel Data Type Library/Collections.kerml +177 -0
- sysml/stdlib/Kernel Libraries/Kernel Data Type Library/ScalarValues.kerml +23 -0
- sysml/stdlib/Kernel Libraries/Kernel Data Type Library/VectorValues.kerml +64 -0
- sysml/stdlib/Kernel Libraries/Kernel Function Library/.meta.json +23 -0
- sysml/stdlib/Kernel Libraries/Kernel Function Library/.project.json +15 -0
- sysml/stdlib/Kernel Libraries/Kernel Function Library/BaseFunctions.kerml +80 -0
- sysml/stdlib/Kernel Libraries/Kernel Function Library/BooleanFunctions.kerml +22 -0
- sysml/stdlib/Kernel Libraries/Kernel Function Library/CollectionFunctions.kerml +68 -0
- sysml/stdlib/Kernel Libraries/Kernel Function Library/ComplexFunctions.kerml +47 -0
- sysml/stdlib/Kernel Libraries/Kernel Function Library/ControlFunctions.kerml +117 -0
- sysml/stdlib/Kernel Libraries/Kernel Function Library/DataFunctions.kerml +43 -0
- sysml/stdlib/Kernel Libraries/Kernel Function Library/IntegerFunctions.kerml +43 -0
- sysml/stdlib/Kernel Libraries/Kernel Function Library/NaturalFunctions.kerml +27 -0
- sysml/stdlib/Kernel Libraries/Kernel Function Library/NumericalFunctions.kerml +43 -0
- sysml/stdlib/Kernel Libraries/Kernel Function Library/OccurrenceFunctions.kerml +154 -0
- sysml/stdlib/Kernel Libraries/Kernel Function Library/RationalFunctions.kerml +49 -0
- sysml/stdlib/Kernel Libraries/Kernel Function Library/RealFunctions.kerml +56 -0
- sysml/stdlib/Kernel Libraries/Kernel Function Library/ScalarFunctions.kerml +33 -0
- sysml/stdlib/Kernel Libraries/Kernel Function Library/SequenceFunctions.kerml +111 -0
- sysml/stdlib/Kernel Libraries/Kernel Function Library/StringFunctions.kerml +25 -0
- sysml/stdlib/Kernel Libraries/Kernel Function Library/TrigFunctions.kerml +35 -0
- sysml/stdlib/Kernel Libraries/Kernel Function Library/VectorFunctions.kerml +273 -0
- sysml/stdlib/Kernel Libraries/Kernel Semantic Library/.meta.json +22 -0
- sysml/stdlib/Kernel Libraries/Kernel Semantic Library/.project.json +15 -0
- sysml/stdlib/Kernel Libraries/Kernel Semantic Library/Base.kerml +95 -0
- sysml/stdlib/Kernel Libraries/Kernel Semantic Library/Clocks.kerml +156 -0
- sysml/stdlib/Kernel Libraries/Kernel Semantic Library/ControlPerformances.kerml +135 -0
- sysml/stdlib/Kernel Libraries/Kernel Semantic Library/FeatureReferencingPerformances.kerml +190 -0
- sysml/stdlib/Kernel Libraries/Kernel Semantic Library/KerML.kerml +483 -0
- sysml/stdlib/Kernel Libraries/Kernel Semantic Library/Links.kerml +67 -0
- sysml/stdlib/Kernel Libraries/Kernel Semantic Library/Metaobjects.kerml +58 -0
- sysml/stdlib/Kernel Libraries/Kernel Semantic Library/Objects.kerml +212 -0
- sysml/stdlib/Kernel Libraries/Kernel Semantic Library/Observation.kerml +161 -0
- sysml/stdlib/Kernel Libraries/Kernel Semantic Library/Occurrences.kerml +992 -0
- sysml/stdlib/Kernel Libraries/Kernel Semantic Library/Performances.kerml +293 -0
- sysml/stdlib/Kernel Libraries/Kernel Semantic Library/SpatialFrames.kerml +197 -0
- sysml/stdlib/Kernel Libraries/Kernel Semantic Library/StatePerformances.kerml +145 -0
- sysml/stdlib/Kernel Libraries/Kernel Semantic Library/Transfers.kerml +281 -0
- sysml/stdlib/Kernel Libraries/Kernel Semantic Library/TransitionPerformances.kerml +66 -0
- sysml/stdlib/Kernel Libraries/Kernel Semantic Library/Triggers.kerml +188 -0
- sysml/stdlib/LICENSE +277 -0
- sysml/stdlib/NOTICE +27 -0
- sysml/stdlib/Systems Library/.meta.json +27 -0
- sysml/stdlib/Systems Library/.project.json +19 -0
- sysml/stdlib/Systems Library/Actions.sysml +557 -0
- sysml/stdlib/Systems Library/Allocations.sysml +29 -0
- sysml/stdlib/Systems Library/AnalysisCases.sysml +38 -0
- sysml/stdlib/Systems Library/Attributes.sysml +25 -0
- sysml/stdlib/Systems Library/Calculations.sysml +37 -0
- sysml/stdlib/Systems Library/Cases.sysml +71 -0
- sysml/stdlib/Systems Library/Connections.sysml +60 -0
- sysml/stdlib/Systems Library/Constraints.sysml +44 -0
- sysml/stdlib/Systems Library/Flows.sysml +126 -0
- sysml/stdlib/Systems Library/Interfaces.sysml +89 -0
- sysml/stdlib/Systems Library/Items.sysml +153 -0
- sysml/stdlib/Systems Library/Metadata.sysml +32 -0
- sysml/stdlib/Systems Library/Parts.sysml +81 -0
- sysml/stdlib/Systems Library/Ports.sysml +54 -0
- sysml/stdlib/Systems Library/Requirements.sysml +194 -0
- sysml/stdlib/Systems Library/StandardViewDefinitions.sysml +123 -0
- sysml/stdlib/Systems Library/States.sysml +103 -0
- sysml/stdlib/Systems Library/SysML.sysml +539 -0
- sysml/stdlib/Systems Library/UseCases.sysml +57 -0
- sysml/stdlib/Systems Library/VerificationCases.sysml +103 -0
- sysml/stdlib/Systems Library/Views.sysml +164 -0
- sysml/toolkit.py +373 -0
- sysml/toolkit_table.py +665 -0
- sysml-0.1.0.dist-info/METADATA +87 -0
- sysml-0.1.0.dist-info/RECORD +134 -0
- sysml-0.1.0.dist-info/WHEEL +5 -0
- sysml-0.1.0.dist-info/licenses/LICENSE +202 -0
- sysml-0.1.0.dist-info/licenses/NOTICE +7 -0
- sysml-0.1.0.dist-info/licenses/stdlib/LICENSE +277 -0
- sysml-0.1.0.dist-info/licenses/stdlib/NOTICE +27 -0
- sysml-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
standard library package VerificationCases {
|
|
2
|
+
doc
|
|
3
|
+
/*
|
|
4
|
+
* This package defines the base types for verification cases and related behavioral elements
|
|
5
|
+
* in the SysML language.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
private import Cases::Case;
|
|
9
|
+
private import Cases::cases;
|
|
10
|
+
private import Requirements::RequirementCheck;
|
|
11
|
+
private import ScalarValues::Boolean;
|
|
12
|
+
|
|
13
|
+
abstract verification def VerificationCase :> Case {
|
|
14
|
+
doc
|
|
15
|
+
/*
|
|
16
|
+
* VerificationCase is the most general class of performances of VerificationCaseDefinitions.
|
|
17
|
+
* VericationCase is the base class of all VerificationCaseDefinitions.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
ref verification self : VerificationCase :>> Case::self;
|
|
21
|
+
subject subj :>> Case::subj;
|
|
22
|
+
return verdict : VerdictKind :>> result;
|
|
23
|
+
|
|
24
|
+
objective obj :>> Case::obj {
|
|
25
|
+
subject subj = VerificationCase::subj;
|
|
26
|
+
|
|
27
|
+
requirement requirementVerifications : RequirementCheck[0..*] :> subrequirements {
|
|
28
|
+
doc
|
|
29
|
+
/*
|
|
30
|
+
* A record of the evaluations of the RequirementChecks of requirements being verified.
|
|
31
|
+
*/
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
ref requirement requirementVerifications : RequirementCheck[0..*] = obj.requirementVerifications {
|
|
36
|
+
doc
|
|
37
|
+
/*
|
|
38
|
+
* Checks on whether the verifiedRequirements of the VerificationCase have been satisfied.
|
|
39
|
+
*/
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
abstract verification subVerificationCases : VerificationCase[0..*] :> verificationCases, subcases {
|
|
43
|
+
doc
|
|
44
|
+
/*
|
|
45
|
+
* The subcases of this VerificationCase that are VerificationCaseUsages.
|
|
46
|
+
*/
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
abstract verification verificationCases : VerificationCase[0..*] nonunique :> cases {
|
|
52
|
+
doc
|
|
53
|
+
/*
|
|
54
|
+
* verificationCases is the base feature of all VerificationCaseUsages.
|
|
55
|
+
*/
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
enum def VerdictKind {
|
|
59
|
+
doc
|
|
60
|
+
/*
|
|
61
|
+
* VerdictKind is an enumeration of the possible results of a VerificationCase.
|
|
62
|
+
*/
|
|
63
|
+
|
|
64
|
+
pass;
|
|
65
|
+
fail;
|
|
66
|
+
inconclusive;
|
|
67
|
+
error;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
calc def PassIf {
|
|
71
|
+
doc
|
|
72
|
+
/*
|
|
73
|
+
* PassIf returns a pass or fail VerdictKind depending on whether its argument is
|
|
74
|
+
* true or false.
|
|
75
|
+
*/
|
|
76
|
+
|
|
77
|
+
in attribute isPassing : Boolean;
|
|
78
|
+
return attribute verdict : VerdictKind = if isPassing? VerdictKind::pass else VerdictKind::fail;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
metadata def VerificationMethod {
|
|
82
|
+
doc
|
|
83
|
+
/*
|
|
84
|
+
* VerificationMethod can be used as metadata annotating a verification case or action.
|
|
85
|
+
*/
|
|
86
|
+
|
|
87
|
+
attribute kind : VerificationMethodKind[1..*];
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
enum def VerificationMethodKind {
|
|
91
|
+
doc
|
|
92
|
+
/*
|
|
93
|
+
* VerificationMethodKind is an enumeration of the standard methods by which verification
|
|
94
|
+
* can be carried out.
|
|
95
|
+
*/
|
|
96
|
+
|
|
97
|
+
inspect;
|
|
98
|
+
analyze;
|
|
99
|
+
demo;
|
|
100
|
+
test;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
standard library package Views {
|
|
2
|
+
doc
|
|
3
|
+
/*
|
|
4
|
+
* This package defines the base types for views, viewpoints, renderings and related elements
|
|
5
|
+
* in the SysML language.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
private import Parts::Part;
|
|
9
|
+
private import Parts::parts;
|
|
10
|
+
private import Requirements::RequirementCheck;
|
|
11
|
+
private import Requirements::requirementChecks;
|
|
12
|
+
|
|
13
|
+
abstract view def View :> Part {
|
|
14
|
+
ref view :>> self : View;
|
|
15
|
+
|
|
16
|
+
abstract ref view subviews : View[0..*] :> views {
|
|
17
|
+
doc
|
|
18
|
+
/*
|
|
19
|
+
* Other Views that are used in the rendering of this View.
|
|
20
|
+
*/
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
abstract ref rendering viewRendering : Rendering[0..1] {
|
|
24
|
+
doc
|
|
25
|
+
/*
|
|
26
|
+
* The rendering of this View.
|
|
27
|
+
*/
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
viewpoint viewpointSatisfactions : ViewpointCheck[0..*] :> viewpointChecks, checkedConstraints {
|
|
31
|
+
doc
|
|
32
|
+
/*
|
|
33
|
+
* Checks that the View satisfies all required ViewpointUsages.
|
|
34
|
+
*/
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
satisfy requirement viewpointConformance by that {
|
|
38
|
+
doc
|
|
39
|
+
/*
|
|
40
|
+
* An assertion that all viewpointSatisfactions are true.
|
|
41
|
+
*/
|
|
42
|
+
|
|
43
|
+
require viewpointSatisfactions {
|
|
44
|
+
doc
|
|
45
|
+
/*
|
|
46
|
+
* The required ViewpointChecks.
|
|
47
|
+
*/
|
|
48
|
+
ref :>> ownedPerformances::this, subperformances::this default that.that;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
abstract viewpoint def ViewpointCheck :> RequirementCheck {
|
|
54
|
+
doc
|
|
55
|
+
/*
|
|
56
|
+
* ViewpointCheck is a RequirementCheck for checking if a View meets the concerns of viewpoint stakeholders.
|
|
57
|
+
* It is the base type of all ViewpointDefinitions.
|
|
58
|
+
*/
|
|
59
|
+
|
|
60
|
+
ref viewpoint :>> self : ViewpointCheck;
|
|
61
|
+
subject subj : View[1] :>> RequirementCheck::subj;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
abstract rendering def Rendering :> Part {
|
|
65
|
+
doc
|
|
66
|
+
/*
|
|
67
|
+
* Rendering is the base type of all RenderingDefinitions.
|
|
68
|
+
*/
|
|
69
|
+
|
|
70
|
+
ref rendering :>> self : Rendering;
|
|
71
|
+
|
|
72
|
+
abstract ref rendering subrenderings : Rendering[0..*] :> renderings {
|
|
73
|
+
doc
|
|
74
|
+
/*
|
|
75
|
+
* Other Renderings used to carry out this Rendering.
|
|
76
|
+
*/
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
rendering def TextualRendering :> Rendering {
|
|
81
|
+
doc
|
|
82
|
+
/*
|
|
83
|
+
* A TextualRendering is a Rendering of a View into a textual format.
|
|
84
|
+
*/
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
rendering def GraphicalRendering :> Rendering {
|
|
88
|
+
doc
|
|
89
|
+
/*
|
|
90
|
+
* A GraphicalRendering is a Rendering of a View into a Graphical format.
|
|
91
|
+
*/
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
rendering def TabularRendering :> Rendering {
|
|
95
|
+
doc
|
|
96
|
+
/*
|
|
97
|
+
* A TabularRendering is a Rendering of a View into a tabular format.
|
|
98
|
+
*/
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
abstract view views : View[0..*] nonunique :> parts {
|
|
102
|
+
doc
|
|
103
|
+
/*
|
|
104
|
+
* views is the base feature of all ViewUsages.
|
|
105
|
+
*/
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
abstract viewpoint viewpointChecks : ViewpointCheck[0..*] nonunique :> requirementChecks {
|
|
109
|
+
doc
|
|
110
|
+
/*
|
|
111
|
+
* viewpointChecks is the base feature of all ViewpointUsages.
|
|
112
|
+
*/
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
abstract rendering renderings : Rendering[0..*] nonunique :> parts {
|
|
116
|
+
doc
|
|
117
|
+
/*
|
|
118
|
+
* renderings is the base feature of all RenderingUsages.
|
|
119
|
+
*/
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
rendering asTextualNotation : TextualRendering[1] :> renderings {
|
|
123
|
+
doc
|
|
124
|
+
/*
|
|
125
|
+
* asTextualNotation renders a View into textual notation as defined in the
|
|
126
|
+
* KerML and SysML specifications.
|
|
127
|
+
*/
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
rendering asTreeDiagram : GraphicalRendering[1] :> renderings {
|
|
131
|
+
doc
|
|
132
|
+
/*
|
|
133
|
+
* asTreeDiagram renders a View as a tree diagram, using the
|
|
134
|
+
* graphical notation defined in the SysML specification.
|
|
135
|
+
*/
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
rendering asInterconnectionDiagram : GraphicalRendering[1] :> renderings {
|
|
139
|
+
doc
|
|
140
|
+
/*
|
|
141
|
+
* asInterconnectionDiagram renders a View as an interconnection
|
|
142
|
+
* diagram, using the graphical notation defined in the SysML specification.
|
|
143
|
+
*/
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
rendering asElementTable : TabularRendering[1] :> renderings {
|
|
147
|
+
doc
|
|
148
|
+
/*
|
|
149
|
+
* asElementTable renders a View as a table, with one row for each exposed
|
|
150
|
+
* Element and columns rendered by applying the columnViews in order to the
|
|
151
|
+
* Element in each row.
|
|
152
|
+
*/
|
|
153
|
+
|
|
154
|
+
view columnView[0..*] ordered {
|
|
155
|
+
doc
|
|
156
|
+
/*
|
|
157
|
+
* The Views to be rendered in the column cells, in order, of each rows of the table.
|
|
158
|
+
*/
|
|
159
|
+
|
|
160
|
+
abstract ref rendering :>> viewRendering[0..1];
|
|
161
|
+
}
|
|
162
|
+
rendering :>> subrenderings[0..*] = columnView.viewRendering;
|
|
163
|
+
}
|
|
164
|
+
}
|
sysml/toolkit.py
ADDED
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
"""The SysML Toolkit backend: the Python core over the binding library (abi/).
|
|
2
|
+
|
|
3
|
+
Implements the same five-method backend contract as PayloadBackend, so the generated classes
|
|
4
|
+
and `Model` are untouched. Handles are the integers the library mints; references come back
|
|
5
|
+
as ``{"@id": handle}`` so that `_wrap` turns them into typed elements exactly as it does for
|
|
6
|
+
payload models.
|
|
7
|
+
|
|
8
|
+
Dispatch is static: each generated descriptor carries the C symbol and result shape resolved
|
|
9
|
+
at generation time for its declaring class, and ``read`` calls that symbol directly. No
|
|
10
|
+
lookup, no base walk. ``get(handle, prop)`` remains as the name-based fallback the shared
|
|
11
|
+
`Model` helpers use.
|
|
12
|
+
|
|
13
|
+
Errors follow the ABI specification: NOT_IMPLEMENTED raises NotImplementedInToolkit,
|
|
14
|
+
NOT_APPLICABLE is an absent value, INVALID_HANDLE raises Gone.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
19
|
+
import ctypes as C
|
|
20
|
+
import errno
|
|
21
|
+
import json
|
|
22
|
+
import os
|
|
23
|
+
import sys
|
|
24
|
+
from typing import Any, Iterable, Optional
|
|
25
|
+
|
|
26
|
+
from .base import SdkError, Gone, NotImplementedInToolkit, UnresolvedReference
|
|
27
|
+
from . import toolkit_table as T
|
|
28
|
+
|
|
29
|
+
# ---------------------------------------------------------------- C structures
|
|
30
|
+
|
|
31
|
+
class Str(C.Structure):
|
|
32
|
+
_fields_ = [("ptr", C.c_void_p), ("len", C.c_size_t), ("present", C.c_bool), ("owner", C.c_void_p)]
|
|
33
|
+
|
|
34
|
+
class Handles(C.Structure):
|
|
35
|
+
_fields_ = [("items", C.POINTER(C.c_uint64)), ("len", C.c_size_t), ("owner", C.c_void_p)]
|
|
36
|
+
|
|
37
|
+
class Ref(C.Structure):
|
|
38
|
+
_fields_ = [("present", C.c_bool), ("value", C.c_uint64)]
|
|
39
|
+
|
|
40
|
+
class Bool(C.Structure):
|
|
41
|
+
_fields_ = [("present", C.c_bool), ("value", C.c_bool)]
|
|
42
|
+
|
|
43
|
+
class Int(C.Structure):
|
|
44
|
+
_fields_ = [("present", C.c_bool), ("value", C.c_int64)]
|
|
45
|
+
|
|
46
|
+
class Real(C.Structure):
|
|
47
|
+
_fields_ = [("present", C.c_bool), ("value", C.c_double)]
|
|
48
|
+
|
|
49
|
+
class LoadOptions(C.Structure):
|
|
50
|
+
_fields_ = [
|
|
51
|
+
("paths", C.POINTER(Str)), ("paths_len", C.c_size_t),
|
|
52
|
+
("source_names", C.POINTER(Str)), ("source_texts", C.POINTER(Str)), ("sources_len", C.c_size_t),
|
|
53
|
+
("library_dir", Str),
|
|
54
|
+
]
|
|
55
|
+
|
|
56
|
+
# "T", a list of strings, crosses the ABI as JSON text in a Str.
|
|
57
|
+
OUT_TYPES = {"H": Handles, "R": Ref, "S": Str, "T": Str, "B": Bool, "I": Int, "F": Real}
|
|
58
|
+
OK, NOT_IMPLEMENTED, NOT_APPLICABLE, INVALID_HANDLE, INVALID_ARG, LOAD_FAILED, INTERNAL, UNRESOLVED = range(8)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
class ToolkitError(SdkError):
|
|
62
|
+
"""A status the ABI specification classes as an error other than the two typed ones."""
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
# ---------------------------------------------------------------- library loading
|
|
66
|
+
|
|
67
|
+
def _default_library_path() -> str:
|
|
68
|
+
"""SYSMLV2_ABI; else the library a platform wheel carries; else the repository's build."""
|
|
69
|
+
env = os.environ.get("SYSMLV2_ABI")
|
|
70
|
+
if env:
|
|
71
|
+
return env
|
|
72
|
+
name = {"win32": "sysmlv2_abi.dll", "darwin": "libsysmlv2_abi.dylib"}.get(sys.platform, "libsysmlv2_abi.so")
|
|
73
|
+
here = os.path.dirname(os.path.abspath(__file__)) # python/sysml
|
|
74
|
+
packaged = os.path.join(here, "_native", name)
|
|
75
|
+
if os.path.exists(packaged):
|
|
76
|
+
return packaged
|
|
77
|
+
repo = os.path.dirname(os.path.dirname(here))
|
|
78
|
+
return os.path.join(repo, "abi", "target", "release", name)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
class Library:
|
|
82
|
+
"""One loaded binding library, shared by every session created from it."""
|
|
83
|
+
|
|
84
|
+
def __init__(self, path: Optional[str] = None):
|
|
85
|
+
self.path = path or _default_library_path()
|
|
86
|
+
if path is None and not os.path.exists(self.path):
|
|
87
|
+
# The source distribution, on a platform no wheel is built for, carries no library.
|
|
88
|
+
raise FileNotFoundError(
|
|
89
|
+
errno.ENOENT,
|
|
90
|
+
"no binding library for the SysML Toolkit backend: this installation of the SDK "
|
|
91
|
+
f"carries none for this platform ({sys.platform}). Platform wheels carry one for Windows "
|
|
92
|
+
"x64, Linux x64 (glibc 2.28 or later), and macOS on Apple silicon (11 or later) and on "
|
|
93
|
+
"Intel (10.12 or later). Elsewhere, set SYSMLV2_ABI to a sysmlv2_abi library built for "
|
|
94
|
+
"this platform (abi/README.md). Reading interchange JSON (Model.from_full_json) needs "
|
|
95
|
+
"no binding library")
|
|
96
|
+
self.lib = C.CDLL(self.path)
|
|
97
|
+
lib = self.lib
|
|
98
|
+
lib.sysmlv2_free.argtypes = [C.c_void_p]
|
|
99
|
+
lib.sysmlv2_free.restype = None
|
|
100
|
+
lib.sysmlv2_abi_version.restype = C.c_uint32
|
|
101
|
+
lib.sysmlv2_names_digest.restype = C.c_void_p
|
|
102
|
+
lib.sysmlv2_names_digest_len.restype = C.c_size_t
|
|
103
|
+
lib.sysmlv2_session_open.argtypes = [C.POINTER(LoadOptions), C.POINTER(C.c_void_p)]
|
|
104
|
+
lib.sysmlv2_session_close.argtypes = [C.c_void_p]
|
|
105
|
+
lib.sysmlv2_session_roots.argtypes = [C.c_void_p, C.POINTER(Handles)]
|
|
106
|
+
lib.sysmlv2_last_error.argtypes = [C.c_void_p, C.POINTER(Str)]
|
|
107
|
+
lib.sysmlv2_metaclass.argtypes = [C.c_void_p, C.c_uint64, C.POINTER(Str)]
|
|
108
|
+
lib.sysmlv2_user_elements.argtypes = [C.c_void_p, C.POINTER(Handles)]
|
|
109
|
+
lib.sysmlv2_session_full_json.argtypes = [C.c_void_p, C.c_uint32, C.POINTER(Str)]
|
|
110
|
+
digest = C.string_at(lib.sysmlv2_names_digest(), lib.sysmlv2_names_digest_len()).decode()
|
|
111
|
+
if digest != T.NAMES_DIGEST:
|
|
112
|
+
raise ToolkitError(
|
|
113
|
+
f"binding library {self.path} was generated from naming table {digest[:12]}, "
|
|
114
|
+
f"this SDK from {T.NAMES_DIGEST[:12]}; regenerate one side"
|
|
115
|
+
)
|
|
116
|
+
self._fn_cache: dict[str, Any] = {}
|
|
117
|
+
|
|
118
|
+
def fn(self, symbol: str, out_type):
|
|
119
|
+
f = self._fn_cache.get(symbol)
|
|
120
|
+
if f is None:
|
|
121
|
+
f = getattr(self.lib, symbol)
|
|
122
|
+
f.argtypes = [C.c_void_p, C.c_uint64, C.POINTER(out_type)]
|
|
123
|
+
f.restype = C.c_int
|
|
124
|
+
self._fn_cache[symbol] = f
|
|
125
|
+
return f
|
|
126
|
+
|
|
127
|
+
def take_str(self, s: Str) -> Optional[str]:
|
|
128
|
+
v = C.string_at(s.ptr, s.len).decode() if (s.present and s.ptr) else None
|
|
129
|
+
self.lib.sysmlv2_free(s.owner)
|
|
130
|
+
return v
|
|
131
|
+
|
|
132
|
+
def take_handles(self, h: Handles) -> list[int]:
|
|
133
|
+
v = [h.items[i] for i in range(h.len)]
|
|
134
|
+
self.lib.sysmlv2_free(h.owner)
|
|
135
|
+
return v
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
_DEFAULT: Optional[Library] = None
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
def library(path: Optional[str] = None) -> Library:
|
|
142
|
+
global _DEFAULT
|
|
143
|
+
if path is not None:
|
|
144
|
+
return Library(path)
|
|
145
|
+
if _DEFAULT is None:
|
|
146
|
+
_DEFAULT = Library()
|
|
147
|
+
return _DEFAULT
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
# ---------------------------------------------------------------- backend
|
|
151
|
+
|
|
152
|
+
def _c_str(b: bytes, keep: list) -> Str:
|
|
153
|
+
buf = C.create_string_buffer(b, len(b))
|
|
154
|
+
keep.append(buf)
|
|
155
|
+
return Str(C.cast(buf, C.c_void_p), len(b), True, None)
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
class ToolkitBackend:
|
|
159
|
+
"""A read-only session over the SysML Toolkit, through the binding library."""
|
|
160
|
+
|
|
161
|
+
def __init__(self, session: C.c_void_p, lib: Library):
|
|
162
|
+
self._s = session
|
|
163
|
+
self._L = lib
|
|
164
|
+
self._mc: dict[int, str] = {}
|
|
165
|
+
self._declaring: dict[tuple[str, str], tuple[str, str] | None] = {}
|
|
166
|
+
|
|
167
|
+
@classmethod
|
|
168
|
+
def open(cls, paths: Iterable[str | os.PathLike] = (), *, sources: dict[str, str] | None = None,
|
|
169
|
+
library_dir: str | os.PathLike | None = None, lib: Optional[Library] = None) -> "ToolkitBackend":
|
|
170
|
+
L = lib or library()
|
|
171
|
+
keep: list = []
|
|
172
|
+
paths = [os.fspath(p) for p in paths]
|
|
173
|
+
library_dir = os.fspath(library_dir) if library_dir is not None else None
|
|
174
|
+
opts = LoadOptions()
|
|
175
|
+
if sources:
|
|
176
|
+
names = (Str * len(sources))(*[_c_str(k.encode(), keep) for k in sources])
|
|
177
|
+
texts = (Str * len(sources))(*[_c_str(v.encode(), keep) for v in sources.values()])
|
|
178
|
+
opts.source_names, opts.source_texts, opts.sources_len = names, texts, len(sources)
|
|
179
|
+
elif paths:
|
|
180
|
+
arr = (Str * len(paths))(*[_c_str(p.encode(), keep) for p in paths])
|
|
181
|
+
opts.paths, opts.paths_len = arr, len(paths)
|
|
182
|
+
else:
|
|
183
|
+
raise ToolkitError("open needs paths or sources")
|
|
184
|
+
for p in ([] if sources else paths):
|
|
185
|
+
if not os.path.isfile(p):
|
|
186
|
+
raise FileNotFoundError(errno.ENOENT, "model file not found", os.path.abspath(p))
|
|
187
|
+
if library_dir and not os.path.isdir(library_dir):
|
|
188
|
+
raise FileNotFoundError(errno.ENOENT, "library directory not found", os.path.abspath(library_dir))
|
|
189
|
+
opts.library_dir = _c_str(library_dir.encode(), keep) if library_dir else Str(None, 0, False, None)
|
|
190
|
+
sess = C.c_void_p()
|
|
191
|
+
st = L.lib.sysmlv2_session_open(C.byref(opts), C.byref(sess))
|
|
192
|
+
if st != OK:
|
|
193
|
+
raise ToolkitError(f"the SysML Toolkit could not load {paths or list(sources)}: status {st} (the SysML Toolkit's reason is on stderr)")
|
|
194
|
+
return cls(sess, L)
|
|
195
|
+
|
|
196
|
+
def close(self) -> None:
|
|
197
|
+
if self._s:
|
|
198
|
+
self._L.lib.sysmlv2_session_close(self._s)
|
|
199
|
+
self._s = None
|
|
200
|
+
|
|
201
|
+
def __del__(self):
|
|
202
|
+
try:
|
|
203
|
+
self.close()
|
|
204
|
+
except Exception:
|
|
205
|
+
pass
|
|
206
|
+
|
|
207
|
+
# -- errors --------------------------------------------------------------
|
|
208
|
+
|
|
209
|
+
def _error(self) -> str:
|
|
210
|
+
out = Str()
|
|
211
|
+
self._L.lib.sysmlv2_last_error(self._s, C.byref(out))
|
|
212
|
+
return self._L.take_str(out) or ""
|
|
213
|
+
|
|
214
|
+
def _check(self, st: int, where: str) -> bool:
|
|
215
|
+
"""True when a value is present; False for NOT_APPLICABLE; raises otherwise."""
|
|
216
|
+
if st == OK:
|
|
217
|
+
return True
|
|
218
|
+
if st == NOT_APPLICABLE:
|
|
219
|
+
return False
|
|
220
|
+
msg = self._error()
|
|
221
|
+
if st == NOT_IMPLEMENTED:
|
|
222
|
+
raise NotImplementedInToolkit(msg or f"{where}: not implemented by the SysML Toolkit")
|
|
223
|
+
if st == INVALID_HANDLE:
|
|
224
|
+
raise Gone(msg or f"{where}: invalid handle")
|
|
225
|
+
if st == UNRESOLVED:
|
|
226
|
+
raise UnresolvedReference(msg or f"{where}: a reference did not resolve")
|
|
227
|
+
raise ToolkitError(f"{where}: status {st}: {msg}")
|
|
228
|
+
|
|
229
|
+
# -- dispatch ------------------------------------------------------------
|
|
230
|
+
|
|
231
|
+
def _declaring_entry(self, mc: str, prop: str):
|
|
232
|
+
key = (mc, prop)
|
|
233
|
+
if key in self._declaring:
|
|
234
|
+
return self._declaring[key]
|
|
235
|
+
seen, stack, found = set(), [mc], None
|
|
236
|
+
while stack:
|
|
237
|
+
c = stack.pop()
|
|
238
|
+
if c in seen:
|
|
239
|
+
continue
|
|
240
|
+
seen.add(c)
|
|
241
|
+
e = T.FUNCS.get((c, prop))
|
|
242
|
+
if e is not None:
|
|
243
|
+
found = e
|
|
244
|
+
break
|
|
245
|
+
stack.extend(T.BASES.get(c, []))
|
|
246
|
+
self._declaring[key] = found
|
|
247
|
+
return found
|
|
248
|
+
|
|
249
|
+
def _call(self, symbol: str, code: str, handle: int, where: str) -> Any:
|
|
250
|
+
out_t = OUT_TYPES[code]
|
|
251
|
+
out = out_t()
|
|
252
|
+
st = self._L.fn(symbol, out_t)(self._s, C.c_uint64(handle), C.byref(out))
|
|
253
|
+
if not self._check(st, where):
|
|
254
|
+
return [] if code in ("H", "T") else None
|
|
255
|
+
return self._unpack(code, out)
|
|
256
|
+
|
|
257
|
+
def _unpack(self, code: str, out) -> Any:
|
|
258
|
+
if code == "H":
|
|
259
|
+
return [{"@id": h} for h in self._L.take_handles(out)]
|
|
260
|
+
if code == "R":
|
|
261
|
+
return {"@id": out.value} if out.present else None
|
|
262
|
+
if code == "S":
|
|
263
|
+
return self._L.take_str(out)
|
|
264
|
+
if code == "T": # a list of strings (a requirement's `text`), as JSON text
|
|
265
|
+
text = self._L.take_str(out)
|
|
266
|
+
return [] if text is None else json.loads(text)
|
|
267
|
+
return out.value if out.present else None
|
|
268
|
+
|
|
269
|
+
# -- the backend contract --------------------------------------------------
|
|
270
|
+
|
|
271
|
+
def read(self, handle: int, prop) -> Any:
|
|
272
|
+
"""Static dispatch: the descriptor already names the binding library function."""
|
|
273
|
+
return self._call(prop.symbol, prop.code, handle, f"{self.metaclass(handle)}.{prop.name}")
|
|
274
|
+
|
|
275
|
+
_PARAM_CTYPES = {"Handle": C.c_uint64, "bool": C.c_bool, "Str": C.POINTER(Str), "Handles": C.POINTER(Handles)}
|
|
276
|
+
|
|
277
|
+
def call(self, handle: int, op, args: tuple) -> Any:
|
|
278
|
+
"""Invoke a specification operation with its declared parameters."""
|
|
279
|
+
if len(args) != len(op.param_types):
|
|
280
|
+
raise TypeError(f"{op.name}() takes {len(op.param_types)} argument(s), {len(args)} given")
|
|
281
|
+
keep: list = []
|
|
282
|
+
cargs = []
|
|
283
|
+
|
|
284
|
+
def handle_of(value, what: str) -> int:
|
|
285
|
+
# The binding library has no "no element": a missing element is refused here, never
|
|
286
|
+
# passed as a handle that names some other element.
|
|
287
|
+
if hasattr(value, "_handle"):
|
|
288
|
+
return value._handle
|
|
289
|
+
if isinstance(value, int) and not isinstance(value, bool):
|
|
290
|
+
return value
|
|
291
|
+
raise TypeError(f"{self.metaclass(handle)}.{op.name}(): {what} must be an element, not {value!r}")
|
|
292
|
+
|
|
293
|
+
for (pname, ptype), value in zip(op.param_types, args):
|
|
294
|
+
if ptype == "Handle":
|
|
295
|
+
cargs.append(C.c_uint64(handle_of(value, pname)))
|
|
296
|
+
elif ptype == "bool":
|
|
297
|
+
cargs.append(C.c_bool(bool(value)))
|
|
298
|
+
elif ptype == "Str": # an element as its element id, as every binding passes it
|
|
299
|
+
text = value.element_id if hasattr(value, "element_id") else "" if value is None else str(value)
|
|
300
|
+
cargs.append(C.byref(_c_str(text.encode(), keep)))
|
|
301
|
+
else: # Handles
|
|
302
|
+
hs = [handle_of(v, f"each of {pname}") for v in (value or [])]
|
|
303
|
+
arr = (C.c_uint64 * max(1, len(hs)))(*hs)
|
|
304
|
+
keep.append(arr)
|
|
305
|
+
keep.append(Handles(C.cast(arr, C.POINTER(C.c_uint64)), len(hs), None))
|
|
306
|
+
cargs.append(C.byref(keep[-1]))
|
|
307
|
+
out_t = OUT_TYPES[op.code]
|
|
308
|
+
f = getattr(self._L.lib, op.symbol)
|
|
309
|
+
f.argtypes = [C.c_void_p, C.c_uint64] + [self._PARAM_CTYPES[t] for _, t in op.param_types] + [C.POINTER(out_t)]
|
|
310
|
+
f.restype = C.c_int
|
|
311
|
+
out = out_t()
|
|
312
|
+
st = f(self._s, C.c_uint64(handle), *cargs, C.byref(out))
|
|
313
|
+
where = f"{self.metaclass(handle)}.{op.name}()"
|
|
314
|
+
if not self._check(st, where):
|
|
315
|
+
return [] if op.code == "H" else None
|
|
316
|
+
return self._unpack(op.code, out)
|
|
317
|
+
|
|
318
|
+
def full_json(self, closures: bool = True) -> str:
|
|
319
|
+
"""The model as full-form interchange JSON, from the SysML Toolkit's own emitter.
|
|
320
|
+
|
|
321
|
+
With `closures` (the default) the inheritance-aware properties carry the specification's
|
|
322
|
+
values, inherited and imported members included. Without, they carry the owned side only,
|
|
323
|
+
as the SysML Toolkit's command-line export writes them.
|
|
324
|
+
"""
|
|
325
|
+
out = Str()
|
|
326
|
+
st = self._L.lib.sysmlv2_session_full_json(self._s, 1 if closures else 0, C.byref(out))
|
|
327
|
+
self._check(st, "full_json")
|
|
328
|
+
return self._L.take_str(out) or "[]"
|
|
329
|
+
|
|
330
|
+
def get(self, handle: int, prop: str) -> Any:
|
|
331
|
+
mc = self.metaclass(handle)
|
|
332
|
+
entry = self._declaring_entry(mc, prop)
|
|
333
|
+
if entry is None:
|
|
334
|
+
return None # not a member of this metaclass: absent, as the payload backend answers
|
|
335
|
+
symbol, code, _ = entry
|
|
336
|
+
return self._call(symbol, code, handle, f"{mc}.{prop}")
|
|
337
|
+
|
|
338
|
+
def metaclass(self, handle: int) -> str:
|
|
339
|
+
mc = self._mc.get(handle)
|
|
340
|
+
if mc is None:
|
|
341
|
+
out = Str()
|
|
342
|
+
st = self._L.lib.sysmlv2_metaclass(self._s, C.c_uint64(handle), C.byref(out))
|
|
343
|
+
self._check(st, f"metaclass({handle})")
|
|
344
|
+
mc = self._L.take_str(out) or ""
|
|
345
|
+
self._mc[handle] = mc
|
|
346
|
+
return mc
|
|
347
|
+
|
|
348
|
+
def element_id(self, handle: int) -> str:
|
|
349
|
+
return self._call("sysmlv2_element_element_id", "S", handle, "elementId") or ""
|
|
350
|
+
|
|
351
|
+
def resolve(self, qualified_name: str) -> Optional[int]:
|
|
352
|
+
keep: list = []
|
|
353
|
+
arg = _c_str(qualified_name.encode(), keep)
|
|
354
|
+
f = self._L.lib.sysmlv2_session_resolve
|
|
355
|
+
f.argtypes = [C.c_void_p, C.POINTER(Str), C.POINTER(Ref)]
|
|
356
|
+
f.restype = C.c_int
|
|
357
|
+
out = Ref()
|
|
358
|
+
st = f(self._s, C.byref(arg), C.byref(out))
|
|
359
|
+
if not self._check(st, f"resolve({qualified_name!r})"):
|
|
360
|
+
return None
|
|
361
|
+
return out.value if out.present else None
|
|
362
|
+
|
|
363
|
+
def all_handles(self) -> Iterable[int]:
|
|
364
|
+
out = Handles()
|
|
365
|
+
st = self._L.lib.sysmlv2_user_elements(self._s, C.byref(out))
|
|
366
|
+
self._check(st, "user_elements")
|
|
367
|
+
return self._L.take_handles(out)
|
|
368
|
+
|
|
369
|
+
def roots(self) -> list[int]:
|
|
370
|
+
out = Handles()
|
|
371
|
+
st = self._L.lib.sysmlv2_session_roots(self._s, C.byref(out))
|
|
372
|
+
self._check(st, "roots")
|
|
373
|
+
return self._L.take_handles(out)
|