opensysml 0.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- opensysml-0.3.0/LICENSE +202 -0
- opensysml-0.3.0/PKG-INFO +240 -0
- opensysml-0.3.0/README.md +196 -0
- opensysml-0.3.0/opensysml/__init__.py +355 -0
- opensysml-0.3.0/opensysml/_dist.py +90 -0
- opensysml-0.3.0/opensysml/_version.py +9 -0
- opensysml-0.3.0/opensysml/binary.py +555 -0
- opensysml-0.3.0/opensysml/capabilities.py +192 -0
- opensysml-0.3.0/opensysml/connection.py +1710 -0
- opensysml-0.3.0/opensysml/conversion.py +137 -0
- opensysml-0.3.0/opensysml/diagnostic.py +80 -0
- opensysml-0.3.0/opensysml/edit.py +448 -0
- opensysml-0.3.0/opensysml/enumeration.py +30 -0
- opensysml-0.3.0/opensysml/errors.py +515 -0
- opensysml-0.3.0/opensysml/generate.py +678 -0
- opensysml-0.3.0/opensysml/instance.py +196 -0
- opensysml-0.3.0/opensysml/model.py +587 -0
- opensysml-0.3.0/opensysml/proto/__init__.py +0 -0
- opensysml-0.3.0/opensysml/proto/sysml_pb2.py +187 -0
- opensysml-0.3.0/opensysml/proto/sysml_pb2.pyi +772 -0
- opensysml-0.3.0/opensysml/proto/sysml_pb2_grpc.py +725 -0
- opensysml-0.3.0/opensysml/py.typed +0 -0
- opensysml-0.3.0/opensysml/query.py +238 -0
- opensysml-0.3.0/opensysml/symbol.py +385 -0
- opensysml-0.3.0/opensysml/typed.py +250 -0
- opensysml-0.3.0/opensysml/typefacts.py +149 -0
- opensysml-0.3.0/opensysml/values.py +450 -0
- opensysml-0.3.0/opensysml/verdict.py +185 -0
- opensysml-0.3.0/opensysml.egg-info/PKG-INFO +240 -0
- opensysml-0.3.0/opensysml.egg-info/SOURCES.txt +69 -0
- opensysml-0.3.0/opensysml.egg-info/dependency_links.txt +1 -0
- opensysml-0.3.0/opensysml.egg-info/entry_points.txt +2 -0
- opensysml-0.3.0/opensysml.egg-info/requires.txt +15 -0
- opensysml-0.3.0/opensysml.egg-info/top_level.txt +1 -0
- opensysml-0.3.0/pyproject.toml +90 -0
- opensysml-0.3.0/setup.cfg +4 -0
- opensysml-0.3.0/tests/test_api.py +412 -0
- opensysml-0.3.0/tests/test_binary.py +612 -0
- opensysml-0.3.0/tests/test_capabilities.py +170 -0
- opensysml-0.3.0/tests/test_connection.py +585 -0
- opensysml-0.3.0/tests/test_conversion.py +397 -0
- opensysml-0.3.0/tests/test_diagnostic.py +68 -0
- opensysml-0.3.0/tests/test_edit.py +645 -0
- opensysml-0.3.0/tests/test_enumeration.py +101 -0
- opensysml-0.3.0/tests/test_errors.py +217 -0
- opensysml-0.3.0/tests/test_evaluate_subject.py +86 -0
- opensysml-0.3.0/tests/test_feature_values.py +77 -0
- opensysml-0.3.0/tests/test_feature_values_capability.py +84 -0
- opensysml-0.3.0/tests/test_generate.py +570 -0
- opensysml-0.3.0/tests/test_generate_golden.py +347 -0
- opensysml-0.3.0/tests/test_instance.py +245 -0
- opensysml-0.3.0/tests/test_integration.py +171 -0
- opensysml-0.3.0/tests/test_legacy_pysysml_placeholder.py +68 -0
- opensysml-0.3.0/tests/test_lifecycle.py +364 -0
- opensysml-0.3.0/tests/test_model.py +423 -0
- opensysml-0.3.0/tests/test_model_surface_integration.py +127 -0
- opensysml-0.3.0/tests/test_pin_release_checksums.py +248 -0
- opensysml-0.3.0/tests/test_quantity.py +542 -0
- opensysml-0.3.0/tests/test_query.py +335 -0
- opensysml-0.3.0/tests/test_runtime.py +174 -0
- opensysml-0.3.0/tests/test_runtime_integration.py +328 -0
- opensysml-0.3.0/tests/test_stale_service.py +727 -0
- opensysml-0.3.0/tests/test_strict_and_lookup.py +152 -0
- opensysml-0.3.0/tests/test_strict_conformance.py +80 -0
- opensysml-0.3.0/tests/test_symbol.py +531 -0
- opensysml-0.3.0/tests/test_target.py +140 -0
- opensysml-0.3.0/tests/test_typed.py +251 -0
- opensysml-0.3.0/tests/test_unset.py +90 -0
- opensysml-0.3.0/tests/test_verification.py +508 -0
- opensysml-0.3.0/tests/test_version.py +286 -0
- opensysml-0.3.0/tests/test_wire_compat.py +341 -0
opensysml-0.3.0/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright 2026 Open-MBEE
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
opensysml-0.3.0/PKG-INFO
ADDED
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: opensysml
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Summary: Python client library for OpenSysML, a SysML v2 parser and execution runtime
|
|
5
|
+
Author: Open-MBEE
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/Open-MBEE/OpenSysML
|
|
8
|
+
Project-URL: Repository, https://github.com/Open-MBEE/OpenSysML
|
|
9
|
+
Project-URL: Documentation, https://github.com/Open-MBEE/OpenSysML/blob/main/python/README.md
|
|
10
|
+
Project-URL: Changelog, https://github.com/Open-MBEE/OpenSysML/blob/main/CHANGELOG.md
|
|
11
|
+
Project-URL: Issues, https://github.com/Open-MBEE/OpenSysML/issues
|
|
12
|
+
Keywords: sysml,sysmlv2,kerml,mbse,systems-engineering
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Intended Audience :: Science/Research
|
|
16
|
+
Classifier: Operating System :: MacOS
|
|
17
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
18
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
19
|
+
Classifier: Programming Language :: Python :: 3
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
24
|
+
Classifier: Topic :: Scientific/Engineering
|
|
25
|
+
Classifier: Topic :: Software Development :: Compilers
|
|
26
|
+
Requires-Python: >=3.10
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
License-File: LICENSE
|
|
29
|
+
Requires-Dist: grpcio>=1.83.0
|
|
30
|
+
Requires-Dist: protobuf>=7.35.1
|
|
31
|
+
Requires-Dist: filelock>=3.0.0
|
|
32
|
+
Requires-Dist: psutil>=5.9.0
|
|
33
|
+
Provides-Extra: dev
|
|
34
|
+
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
35
|
+
Requires-Dist: pytest-mock>=3.10.0; extra == "dev"
|
|
36
|
+
Requires-Dist: grpcio-tools>=1.83.0; extra == "dev"
|
|
37
|
+
Requires-Dist: mypy>=1.8.0; extra == "dev"
|
|
38
|
+
Requires-Dist: types-protobuf>=4.24.0; extra == "dev"
|
|
39
|
+
Requires-Dist: types-psutil>=5.9.0; extra == "dev"
|
|
40
|
+
Requires-Dist: grpc-stubs>=1.53.0; extra == "dev"
|
|
41
|
+
Requires-Dist: pandas-stubs>=2.0.0; extra == "dev"
|
|
42
|
+
Requires-Dist: numpy<2.5; extra == "dev"
|
|
43
|
+
Dynamic: license-file
|
|
44
|
+
|
|
45
|
+
# opensysml
|
|
46
|
+
|
|
47
|
+
Python client for OpenSysML: parse, inspect and execute SysML v2 models over the
|
|
48
|
+
`sysml-grpc` service.
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
pip install opensysml # from PyPI, once the first release is published
|
|
52
|
+
pip install -e python/ # or from a checkout, at the repository root
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
```python
|
|
56
|
+
import opensysml
|
|
57
|
+
|
|
58
|
+
model = opensysml.load("model.sysml", strict=True) # raises on error diagnostics
|
|
59
|
+
print(model.eval("1 + 2 * 3")) # 7
|
|
60
|
+
|
|
61
|
+
print(model.eval("mass", subject="Demo::sedan")) # 1200.0 — that object, not the default
|
|
62
|
+
# requires the service's evaluate_subject
|
|
63
|
+
# capability, rather than trusting a
|
|
64
|
+
# service that would ignore the subject
|
|
65
|
+
|
|
66
|
+
vehicle = model["Vehicle"] # by short name or FQN
|
|
67
|
+
vehicle.attributes() # own and inherited, with resolved facts
|
|
68
|
+
inst = model.instantiate("Demo::Vehicle")
|
|
69
|
+
inst.mass # 1500.0 [kg] — a Quantity
|
|
70
|
+
|
|
71
|
+
model.verify_satisfaction() # every assert satisfy … by …
|
|
72
|
+
model.save("model.ttl") # RDF Turtle (experimental)
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Declarations can be authored from notation strings while preserving the
|
|
76
|
+
untouched source:
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
model.edit().add_part_def("", "Vehicle").apply()
|
|
80
|
+
model.edit().add_part("Vehicle", "engine", type="Engine").apply()
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Use `opensysml.loads(text, language="kerml")` for inline KerML content.
|
|
84
|
+
|
|
85
|
+
Every call goes through the `sysml-grpc` service, which `opensysml` starts for you from
|
|
86
|
+
`~/.opensysml/bin/sysml-grpc`; the guide below says how to put it there.
|
|
87
|
+
|
|
88
|
+
## Service ownership
|
|
89
|
+
|
|
90
|
+
`opensysml` never stops a service it did not start.
|
|
91
|
+
|
|
92
|
+
- A connection that finds a healthy service already listening uses it and takes
|
|
93
|
+
no ownership of it: nothing is recorded, and closing the connection leaves the
|
|
94
|
+
service running. Whoever started it decides when it stops.
|
|
95
|
+
- A service `opensysml` starts is recorded in
|
|
96
|
+
`~/.opensysml/sysml-grpc-<port>.pid` (`$OPENSYSML_STATE_DIR` overrides the
|
|
97
|
+
directory) as the service's pid and process start time, plus the pid and start
|
|
98
|
+
time of the process that started it. Only that process stops it, and only when
|
|
99
|
+
the last connection holding it is closed or the interpreter exits.
|
|
100
|
+
- The start times are what authenticate the record: a pid is re-checked against
|
|
101
|
+
the start time written for it, so a pid the operating system has since reused
|
|
102
|
+
is treated as a stale record — cleaned up, never signalled. A command line
|
|
103
|
+
that merely looks like `sysml-grpc` is not identity and is never acted on.
|
|
104
|
+
- A service that crashes leaves a record whose process is gone; the next
|
|
105
|
+
connection detects that, removes it and starts a service of its own.
|
|
106
|
+
|
|
107
|
+
## Pinned release digests
|
|
108
|
+
|
|
109
|
+
A download is verified against `PINNED_SHA256` in `opensysml/binary.py`, which
|
|
110
|
+
pins the SHA-256 of every asset of a release. The `.sha256` served beside a
|
|
111
|
+
binary comes from whoever served the binary, so it detects corruption but not a
|
|
112
|
+
republished release; a pinned digest is independent of that origin. A download
|
|
113
|
+
with no pin fails with a message naming the version, rather than falling back to
|
|
114
|
+
the served checksum — `$OPENSYSML_ALLOW_UNPINNED_DOWNLOAD=<owner/repo>` (or `=1` for
|
|
115
|
+
any repository) accepts same-origin trust explicitly for what it names, with a
|
|
116
|
+
warning.
|
|
117
|
+
|
|
118
|
+
At release time, after the service binaries are published and final:
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
export GITHUB_TOKEN=... # the release API rate-limits unauthenticated calls
|
|
122
|
+
python scripts/pin_release_checksums.py --version v0.0.9 --write
|
|
123
|
+
git commit -am 'chore(python): pin release digests for v0.0.9'
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
The script downloads every `sysml-grpc-*` asset of that release, hashes what it
|
|
127
|
+
downloaded, refuses the release if a `.sha256` sidecar disagrees with the asset
|
|
128
|
+
it describes, and rewrites the table in place. `--check` re-hashes the assets of
|
|
129
|
+
every pinned release and fails on any disagreement, catching a release
|
|
130
|
+
republished with another binary. A opensysml release therefore pins the service
|
|
131
|
+
releases published before it; asking for a newer one needs a newer opensysml (or
|
|
132
|
+
the explicit opt-in above), and leaves an already-downloaded binary serving
|
|
133
|
+
rather than refusing to start — only a digest that *contradicts* a pin is
|
|
134
|
+
treated as tampering and refuses to fall back.
|
|
135
|
+
|
|
136
|
+
## Version
|
|
137
|
+
|
|
138
|
+
`opensysml/_version.py` is the only declaration: the packaging metadata reads it,
|
|
139
|
+
`opensysml.__version__` reports the installed distribution's version, and
|
|
140
|
+
`scripts/check_version.py` fails a release whose tag names another version. The
|
|
141
|
+
version tests therefore require the tree under test to be the installed
|
|
142
|
+
distribution — `pip install -e python/`. A wheel of another version installed
|
|
143
|
+
beside the source tree makes them fail with that remedy: the artifact is what is
|
|
144
|
+
stale, not the declaration.
|
|
145
|
+
|
|
146
|
+
## Generated typed classes
|
|
147
|
+
|
|
148
|
+
`python -m opensysml.generate model.sysml -o model_types.py` emits one class per
|
|
149
|
+
SysML *definition*, and the generated hierarchy follows the model's
|
|
150
|
+
generalization edges: `specializes`, `subsets` and `redefines` all become base
|
|
151
|
+
classes, because Python has a single notion of inheritance. What tells the two
|
|
152
|
+
apart is the members, not the bases:
|
|
153
|
+
|
|
154
|
+
- a **redefinition** reuses the redefined feature's name, so its property
|
|
155
|
+
overrides the base class's property of that name, and takes over the type and
|
|
156
|
+
multiplicity it does not restate (`attribute :>> mass = 2.0;` stays `float`,
|
|
157
|
+
and a redefined `0..*` feature stays a `list[...]`);
|
|
158
|
+
- a **subset** under a new name adds a property beside the base class's one, and
|
|
159
|
+
likewise inherits the type and multiplicity it leaves out.
|
|
160
|
+
|
|
161
|
+
With **multiple supertypes**, bases are emitted in declaration order, a target
|
|
162
|
+
named twice appearing once, and Python resolves members left to right by its
|
|
163
|
+
usual MRO. A base another declared base already specializes is left implicit —
|
|
164
|
+
`Hybrid :> Vehicle, Electric` where `Electric :> Vehicle` emits
|
|
165
|
+
`class Hybrid(Electric)`, which Python can linearize and which keeps both
|
|
166
|
+
relationships and `Electric`'s properties. Where no order linearizes at all
|
|
167
|
+
(two bases specializing a shared pair in opposite orders), rather than emit a
|
|
168
|
+
module that fails to import, the generator keeps the bases it can and records
|
|
169
|
+
what it left out as a comment on the class, naming the edge:
|
|
170
|
+
|
|
171
|
+
```python
|
|
172
|
+
class Both(One):
|
|
173
|
+
# specializes Demo::Two, left out: Python cannot linearize it with the bases above
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
A base outside the generated model is reported the same way. Both are the model's
|
|
177
|
+
hierarchy being wider than Python's, not facts being discarded — the service
|
|
178
|
+
reports every edge, and `Symbol.specializations` still carries them all.
|
|
179
|
+
|
|
180
|
+
**Limitation, unchanged:** only structural usages (`attribute`, `part`, `item`,
|
|
181
|
+
`occurrence`, `individual`, `port`, `enum`) become properties. Behavioral and
|
|
182
|
+
connector usages — `action`, `state`, `calc`, `constraint`, `requirement`,
|
|
183
|
+
`connection`, `flow`, `interface`, `allocation`, `case` — are not instance feature values,
|
|
184
|
+
so a generated class has no member for them; reach them through
|
|
185
|
+
`model["Demo::Vehicle"]`, `verify_constraint` and `verify_satisfaction`.
|
|
186
|
+
|
|
187
|
+
## Names that shadow builtins
|
|
188
|
+
|
|
189
|
+
Neither builtin name is a live part of the API any more: the module-level
|
|
190
|
+
evaluation function is `opensysml.evaluate`, and the execution error is
|
|
191
|
+
`opensysml.ExecutionError`. `opensysml.eval` and `opensysml.errors.RuntimeError`
|
|
192
|
+
remain as deprecated aliases that warn on use, out of their modules' `__all__`,
|
|
193
|
+
so a star-import binds neither.
|
|
194
|
+
|
|
195
|
+
```python
|
|
196
|
+
import opensysml
|
|
197
|
+
|
|
198
|
+
opensysml.evaluate("1 + 2", file_path="model.sysml") # opensysml.eval warns
|
|
199
|
+
model.eval("mass", subject="Demo::sedan") # a method shadows nothing
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
```python
|
|
203
|
+
from opensysml import eval # shadows the builtin in this module — don't
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
Guidance for this package and for code around it:
|
|
207
|
+
|
|
208
|
+
- **Call `opensysml.evaluate`.** `opensysml.eval` still works and returns the same
|
|
209
|
+
result, warning `DeprecationWarning`; it goes away in 1.0.0.
|
|
210
|
+
- Import the package, not its names, for anything named like a builtin.
|
|
211
|
+
- Catch `opensysml.ExecutionError` (or its base `opensysml.OpenSysMLError`), never
|
|
212
|
+
`opensysml.errors.RuntimeError`, which warns and is due for removal.
|
|
213
|
+
- Do not name a new public function or exception after a builtin.
|
|
214
|
+
|
|
215
|
+
0.2.0 therefore publishes `evaluate` as the name to write, with both builtin
|
|
216
|
+
names deprecated rather than removed, so code written against 0.1.x keeps
|
|
217
|
+
running until 1.0.0.
|
|
218
|
+
|
|
219
|
+
## Running the tests
|
|
220
|
+
|
|
221
|
+
```bash
|
|
222
|
+
make build # builds bin/sysml-grpc
|
|
223
|
+
pip install -e python/ && pip install pytest pytest-mock
|
|
224
|
+
python -m pytest python/tests/ -q # service-backed tests skip
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
Tests that need a service skip when none answers on `localhost:50051` and no
|
|
228
|
+
binary is available to spawn one. Where a service *is* provided — as in CI —
|
|
229
|
+
export `OPENSYSML_REQUIRE_SERVICE=1`, and its absence fails instead of skipping.
|
|
230
|
+
|
|
231
|
+
## Documentation
|
|
232
|
+
|
|
233
|
+
- Using the client:
|
|
234
|
+
[docs/guide/09-python.md](https://github.com/Open-MBEE/OpenSysML/blob/main/docs/guide/09-python.md)
|
|
235
|
+
— installing the service binary, loading a model, instances, verification, conversion
|
|
236
|
+
and queries
|
|
237
|
+
- The API surface, generated typed classes, latency and the module map:
|
|
238
|
+
[docs/reference/python-api.md](https://github.com/Open-MBEE/OpenSysML/blob/main/docs/reference/python-api.md)
|
|
239
|
+
- Installing from source and running the tests:
|
|
240
|
+
[INSTALL.md](https://github.com/Open-MBEE/OpenSysML/blob/main/python/INSTALL.md)
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
# opensysml
|
|
2
|
+
|
|
3
|
+
Python client for OpenSysML: parse, inspect and execute SysML v2 models over the
|
|
4
|
+
`sysml-grpc` service.
|
|
5
|
+
|
|
6
|
+
```bash
|
|
7
|
+
pip install opensysml # from PyPI, once the first release is published
|
|
8
|
+
pip install -e python/ # or from a checkout, at the repository root
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
```python
|
|
12
|
+
import opensysml
|
|
13
|
+
|
|
14
|
+
model = opensysml.load("model.sysml", strict=True) # raises on error diagnostics
|
|
15
|
+
print(model.eval("1 + 2 * 3")) # 7
|
|
16
|
+
|
|
17
|
+
print(model.eval("mass", subject="Demo::sedan")) # 1200.0 — that object, not the default
|
|
18
|
+
# requires the service's evaluate_subject
|
|
19
|
+
# capability, rather than trusting a
|
|
20
|
+
# service that would ignore the subject
|
|
21
|
+
|
|
22
|
+
vehicle = model["Vehicle"] # by short name or FQN
|
|
23
|
+
vehicle.attributes() # own and inherited, with resolved facts
|
|
24
|
+
inst = model.instantiate("Demo::Vehicle")
|
|
25
|
+
inst.mass # 1500.0 [kg] — a Quantity
|
|
26
|
+
|
|
27
|
+
model.verify_satisfaction() # every assert satisfy … by …
|
|
28
|
+
model.save("model.ttl") # RDF Turtle (experimental)
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Declarations can be authored from notation strings while preserving the
|
|
32
|
+
untouched source:
|
|
33
|
+
|
|
34
|
+
```python
|
|
35
|
+
model.edit().add_part_def("", "Vehicle").apply()
|
|
36
|
+
model.edit().add_part("Vehicle", "engine", type="Engine").apply()
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Use `opensysml.loads(text, language="kerml")` for inline KerML content.
|
|
40
|
+
|
|
41
|
+
Every call goes through the `sysml-grpc` service, which `opensysml` starts for you from
|
|
42
|
+
`~/.opensysml/bin/sysml-grpc`; the guide below says how to put it there.
|
|
43
|
+
|
|
44
|
+
## Service ownership
|
|
45
|
+
|
|
46
|
+
`opensysml` never stops a service it did not start.
|
|
47
|
+
|
|
48
|
+
- A connection that finds a healthy service already listening uses it and takes
|
|
49
|
+
no ownership of it: nothing is recorded, and closing the connection leaves the
|
|
50
|
+
service running. Whoever started it decides when it stops.
|
|
51
|
+
- A service `opensysml` starts is recorded in
|
|
52
|
+
`~/.opensysml/sysml-grpc-<port>.pid` (`$OPENSYSML_STATE_DIR` overrides the
|
|
53
|
+
directory) as the service's pid and process start time, plus the pid and start
|
|
54
|
+
time of the process that started it. Only that process stops it, and only when
|
|
55
|
+
the last connection holding it is closed or the interpreter exits.
|
|
56
|
+
- The start times are what authenticate the record: a pid is re-checked against
|
|
57
|
+
the start time written for it, so a pid the operating system has since reused
|
|
58
|
+
is treated as a stale record — cleaned up, never signalled. A command line
|
|
59
|
+
that merely looks like `sysml-grpc` is not identity and is never acted on.
|
|
60
|
+
- A service that crashes leaves a record whose process is gone; the next
|
|
61
|
+
connection detects that, removes it and starts a service of its own.
|
|
62
|
+
|
|
63
|
+
## Pinned release digests
|
|
64
|
+
|
|
65
|
+
A download is verified against `PINNED_SHA256` in `opensysml/binary.py`, which
|
|
66
|
+
pins the SHA-256 of every asset of a release. The `.sha256` served beside a
|
|
67
|
+
binary comes from whoever served the binary, so it detects corruption but not a
|
|
68
|
+
republished release; a pinned digest is independent of that origin. A download
|
|
69
|
+
with no pin fails with a message naming the version, rather than falling back to
|
|
70
|
+
the served checksum — `$OPENSYSML_ALLOW_UNPINNED_DOWNLOAD=<owner/repo>` (or `=1` for
|
|
71
|
+
any repository) accepts same-origin trust explicitly for what it names, with a
|
|
72
|
+
warning.
|
|
73
|
+
|
|
74
|
+
At release time, after the service binaries are published and final:
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
export GITHUB_TOKEN=... # the release API rate-limits unauthenticated calls
|
|
78
|
+
python scripts/pin_release_checksums.py --version v0.0.9 --write
|
|
79
|
+
git commit -am 'chore(python): pin release digests for v0.0.9'
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
The script downloads every `sysml-grpc-*` asset of that release, hashes what it
|
|
83
|
+
downloaded, refuses the release if a `.sha256` sidecar disagrees with the asset
|
|
84
|
+
it describes, and rewrites the table in place. `--check` re-hashes the assets of
|
|
85
|
+
every pinned release and fails on any disagreement, catching a release
|
|
86
|
+
republished with another binary. A opensysml release therefore pins the service
|
|
87
|
+
releases published before it; asking for a newer one needs a newer opensysml (or
|
|
88
|
+
the explicit opt-in above), and leaves an already-downloaded binary serving
|
|
89
|
+
rather than refusing to start — only a digest that *contradicts* a pin is
|
|
90
|
+
treated as tampering and refuses to fall back.
|
|
91
|
+
|
|
92
|
+
## Version
|
|
93
|
+
|
|
94
|
+
`opensysml/_version.py` is the only declaration: the packaging metadata reads it,
|
|
95
|
+
`opensysml.__version__` reports the installed distribution's version, and
|
|
96
|
+
`scripts/check_version.py` fails a release whose tag names another version. The
|
|
97
|
+
version tests therefore require the tree under test to be the installed
|
|
98
|
+
distribution — `pip install -e python/`. A wheel of another version installed
|
|
99
|
+
beside the source tree makes them fail with that remedy: the artifact is what is
|
|
100
|
+
stale, not the declaration.
|
|
101
|
+
|
|
102
|
+
## Generated typed classes
|
|
103
|
+
|
|
104
|
+
`python -m opensysml.generate model.sysml -o model_types.py` emits one class per
|
|
105
|
+
SysML *definition*, and the generated hierarchy follows the model's
|
|
106
|
+
generalization edges: `specializes`, `subsets` and `redefines` all become base
|
|
107
|
+
classes, because Python has a single notion of inheritance. What tells the two
|
|
108
|
+
apart is the members, not the bases:
|
|
109
|
+
|
|
110
|
+
- a **redefinition** reuses the redefined feature's name, so its property
|
|
111
|
+
overrides the base class's property of that name, and takes over the type and
|
|
112
|
+
multiplicity it does not restate (`attribute :>> mass = 2.0;` stays `float`,
|
|
113
|
+
and a redefined `0..*` feature stays a `list[...]`);
|
|
114
|
+
- a **subset** under a new name adds a property beside the base class's one, and
|
|
115
|
+
likewise inherits the type and multiplicity it leaves out.
|
|
116
|
+
|
|
117
|
+
With **multiple supertypes**, bases are emitted in declaration order, a target
|
|
118
|
+
named twice appearing once, and Python resolves members left to right by its
|
|
119
|
+
usual MRO. A base another declared base already specializes is left implicit —
|
|
120
|
+
`Hybrid :> Vehicle, Electric` where `Electric :> Vehicle` emits
|
|
121
|
+
`class Hybrid(Electric)`, which Python can linearize and which keeps both
|
|
122
|
+
relationships and `Electric`'s properties. Where no order linearizes at all
|
|
123
|
+
(two bases specializing a shared pair in opposite orders), rather than emit a
|
|
124
|
+
module that fails to import, the generator keeps the bases it can and records
|
|
125
|
+
what it left out as a comment on the class, naming the edge:
|
|
126
|
+
|
|
127
|
+
```python
|
|
128
|
+
class Both(One):
|
|
129
|
+
# specializes Demo::Two, left out: Python cannot linearize it with the bases above
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
A base outside the generated model is reported the same way. Both are the model's
|
|
133
|
+
hierarchy being wider than Python's, not facts being discarded — the service
|
|
134
|
+
reports every edge, and `Symbol.specializations` still carries them all.
|
|
135
|
+
|
|
136
|
+
**Limitation, unchanged:** only structural usages (`attribute`, `part`, `item`,
|
|
137
|
+
`occurrence`, `individual`, `port`, `enum`) become properties. Behavioral and
|
|
138
|
+
connector usages — `action`, `state`, `calc`, `constraint`, `requirement`,
|
|
139
|
+
`connection`, `flow`, `interface`, `allocation`, `case` — are not instance feature values,
|
|
140
|
+
so a generated class has no member for them; reach them through
|
|
141
|
+
`model["Demo::Vehicle"]`, `verify_constraint` and `verify_satisfaction`.
|
|
142
|
+
|
|
143
|
+
## Names that shadow builtins
|
|
144
|
+
|
|
145
|
+
Neither builtin name is a live part of the API any more: the module-level
|
|
146
|
+
evaluation function is `opensysml.evaluate`, and the execution error is
|
|
147
|
+
`opensysml.ExecutionError`. `opensysml.eval` and `opensysml.errors.RuntimeError`
|
|
148
|
+
remain as deprecated aliases that warn on use, out of their modules' `__all__`,
|
|
149
|
+
so a star-import binds neither.
|
|
150
|
+
|
|
151
|
+
```python
|
|
152
|
+
import opensysml
|
|
153
|
+
|
|
154
|
+
opensysml.evaluate("1 + 2", file_path="model.sysml") # opensysml.eval warns
|
|
155
|
+
model.eval("mass", subject="Demo::sedan") # a method shadows nothing
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
```python
|
|
159
|
+
from opensysml import eval # shadows the builtin in this module — don't
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
Guidance for this package and for code around it:
|
|
163
|
+
|
|
164
|
+
- **Call `opensysml.evaluate`.** `opensysml.eval` still works and returns the same
|
|
165
|
+
result, warning `DeprecationWarning`; it goes away in 1.0.0.
|
|
166
|
+
- Import the package, not its names, for anything named like a builtin.
|
|
167
|
+
- Catch `opensysml.ExecutionError` (or its base `opensysml.OpenSysMLError`), never
|
|
168
|
+
`opensysml.errors.RuntimeError`, which warns and is due for removal.
|
|
169
|
+
- Do not name a new public function or exception after a builtin.
|
|
170
|
+
|
|
171
|
+
0.2.0 therefore publishes `evaluate` as the name to write, with both builtin
|
|
172
|
+
names deprecated rather than removed, so code written against 0.1.x keeps
|
|
173
|
+
running until 1.0.0.
|
|
174
|
+
|
|
175
|
+
## Running the tests
|
|
176
|
+
|
|
177
|
+
```bash
|
|
178
|
+
make build # builds bin/sysml-grpc
|
|
179
|
+
pip install -e python/ && pip install pytest pytest-mock
|
|
180
|
+
python -m pytest python/tests/ -q # service-backed tests skip
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
Tests that need a service skip when none answers on `localhost:50051` and no
|
|
184
|
+
binary is available to spawn one. Where a service *is* provided — as in CI —
|
|
185
|
+
export `OPENSYSML_REQUIRE_SERVICE=1`, and its absence fails instead of skipping.
|
|
186
|
+
|
|
187
|
+
## Documentation
|
|
188
|
+
|
|
189
|
+
- Using the client:
|
|
190
|
+
[docs/guide/09-python.md](https://github.com/Open-MBEE/OpenSysML/blob/main/docs/guide/09-python.md)
|
|
191
|
+
— installing the service binary, loading a model, instances, verification, conversion
|
|
192
|
+
and queries
|
|
193
|
+
- The API surface, generated typed classes, latency and the module map:
|
|
194
|
+
[docs/reference/python-api.md](https://github.com/Open-MBEE/OpenSysML/blob/main/docs/reference/python-api.md)
|
|
195
|
+
- Installing from source and running the tests:
|
|
196
|
+
[INSTALL.md](https://github.com/Open-MBEE/OpenSysML/blob/main/python/INSTALL.md)
|