petra-lang 0.1.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.
- petra_lang-0.1.0/LICENSE +202 -0
- petra_lang-0.1.0/PKG-INFO +45 -0
- petra_lang-0.1.0/README.md +32 -0
- petra_lang-0.1.0/_build/petra_build.py +165 -0
- petra_lang-0.1.0/petra/__init__.py +45 -0
- petra_lang-0.1.0/petra/__main__.py +6 -0
- petra_lang-0.1.0/petra/bench/__init__.py +1 -0
- petra_lang-0.1.0/petra/bench/family.py +591 -0
- petra_lang-0.1.0/petra/certs.py +159 -0
- petra_lang-0.1.0/petra/cli.py +470 -0
- petra_lang-0.1.0/petra/coverage.py +252 -0
- petra_lang-0.1.0/petra/docs/api.md +235 -0
- petra_lang-0.1.0/petra/envelope.py +478 -0
- petra_lang-0.1.0/petra/gym/__init__.py +6 -0
- petra_lang-0.1.0/petra/gym/agent.py +200 -0
- petra_lang-0.1.0/petra/gym/env.py +96 -0
- petra_lang-0.1.0/petra/gym/tasks.py +274 -0
- petra_lang-0.1.0/petra/ir.py +285 -0
- petra_lang-0.1.0/petra/kernel/__init__.py +83 -0
- petra_lang-0.1.0/petra/kernel/check.py +434 -0
- petra_lang-0.1.0/petra/kernel/codec.py +212 -0
- petra_lang-0.1.0/petra/kernel/evaluate.py +187 -0
- petra_lang-0.1.0/petra/kernel/evidence.py +99 -0
- petra_lang-0.1.0/petra/kernel/interval.py +268 -0
- petra_lang-0.1.0/petra/kernel/linalg.py +80 -0
- petra_lang-0.1.0/petra/kernel/rules/__init__.py +122 -0
- petra_lang-0.1.0/petra/kernel/rules/base.py +91 -0
- petra_lang-0.1.0/petra/kernel/rules/r1_linear.py +139 -0
- petra_lang-0.1.0/petra/kernel/rules/r2_definite.py +125 -0
- petra_lang-0.1.0/petra/kernel/rules/r3_hypercircle.py +280 -0
- petra_lang-0.1.0/petra/kernel/rules/r4_enclosure.py +123 -0
- petra_lang-0.1.0/petra/kernel/rules/r5_moment.py +120 -0
- petra_lang-0.1.0/petra/kernel/rules/r6_scenario.py +82 -0
- petra_lang-0.1.0/petra/kernel/terms.py +170 -0
- petra_lang-0.1.0/petra/lang/__init__.py +23 -0
- petra_lang-0.1.0/petra/lang/lexer.py +125 -0
- petra_lang-0.1.0/petra/lang/lower.py +455 -0
- petra_lang-0.1.0/petra/lang/parser.py +387 -0
- petra_lang-0.1.0/petra/lang/syntax.py +60 -0
- petra_lang-0.1.0/petra/library/__init__.py +5 -0
- petra_lang-0.1.0/petra/library/family.py +143 -0
- petra_lang-0.1.0/petra/library/store.py +279 -0
- petra_lang-0.1.0/petra/mechanics/__init__.py +49 -0
- petra_lang-0.1.0/petra/mechanics/algebra.py +37 -0
- petra_lang-0.1.0/petra/mechanics/bolt_groups.py +60 -0
- petra_lang-0.1.0/petra/mechanics/sections.py +97 -0
- petra_lang-0.1.0/petra/mechanics/stability.py +18 -0
- petra_lang-0.1.0/petra/mechanics/weld_groups.py +55 -0
- petra_lang-0.1.0/petra/models/__init__.py +66 -0
- petra_lang-0.1.0/petra/models/base.py +818 -0
- petra_lang-0.1.0/petra/models/bolt.py +510 -0
- petra_lang-0.1.0/petra/models/circuit.py +893 -0
- petra_lang-0.1.0/petra/models/contracts.py +96 -0
- petra_lang-0.1.0/petra/models/steel/__init__.py +15 -0
- petra_lang-0.1.0/petra/models/steel/absent.py +249 -0
- petra_lang-0.1.0/petra/models/steel/breaker.py +133 -0
- petra_lang-0.1.0/petra/models/steel/build.py +107 -0
- petra_lang-0.1.0/petra/models/steel/calc.py +163 -0
- petra_lang-0.1.0/petra/models/steel/checks.py +1717 -0
- petra_lang-0.1.0/petra/models/steel/domain.py +125 -0
- petra_lang-0.1.0/petra/models/steel/faults.py +432 -0
- petra_lang-0.1.0/petra/models/steel/gate.py +230 -0
- petra_lang-0.1.0/petra/models/steel/generate.py +651 -0
- petra_lang-0.1.0/petra/models/steel/geometry.py +471 -0
- petra_lang-0.1.0/petra/models/steel/limits.py +404 -0
- petra_lang-0.1.0/petra/models/steel/lower.py +778 -0
- petra_lang-0.1.0/petra/models/steel/package.py +166 -0
- petra_lang-0.1.0/petra/models/steel/path.py +193 -0
- petra_lang-0.1.0/petra/models/steel/trace.py +262 -0
- petra_lang-0.1.0/petra/models/steel/twin.py +1857 -0
- petra_lang-0.1.0/petra/models/steel/vocab.py +437 -0
- petra_lang-0.1.0/petra/models/truss.py +1155 -0
- petra_lang-0.1.0/petra/models/uncertainty.py +288 -0
- petra_lang-0.1.0/petra/pipeline.py +727 -0
- petra_lang-0.1.0/petra/premises.py +235 -0
- petra_lang-0.1.0/petra/readout.py +993 -0
- petra_lang-0.1.0/petra/recall.py +224 -0
- petra_lang-0.1.0/petra/registry/__init__.py +25 -0
- petra_lang-0.1.0/petra/registry/aisc_shapes.json +338 -0
- petra_lang-0.1.0/petra/registry/catalog.py +375 -0
- petra_lang-0.1.0/petra/registry/consistency.py +306 -0
- petra_lang-0.1.0/petra/registry/constants.py +328 -0
- petra_lang-0.1.0/petra/registry/deck.py +271 -0
- petra_lang-0.1.0/petra/registry/model.py +517 -0
- petra_lang-0.1.0/petra/registry/steel.py +711 -0
- petra_lang-0.1.0/petra/registry/steel_shapes.py +280 -0
- petra_lang-0.1.0/petra/solvers/__init__.py +126 -0
- petra_lang-0.1.0/petra/solvers/exact.py +93 -0
- petra_lang-0.1.0/petra/solvers/r1_linear.py +268 -0
- petra_lang-0.1.0/petra/solvers/r2_definite.py +159 -0
- petra_lang-0.1.0/petra/solvers/r3_hypercircle.py +144 -0
- petra_lang-0.1.0/petra/solvers/r4_enclosure.py +269 -0
- petra_lang-0.1.0/petra/solvers/r5_moment.py +104 -0
- petra_lang-0.1.0/petra/solvers/r6_scenario.py +48 -0
- petra_lang-0.1.0/petra/teach.py +549 -0
- petra_lang-0.1.0/petra/templates.py +501 -0
- petra_lang-0.1.0/petra/units.py +250 -0
- petra_lang-0.1.0/petra/verdict.py +781 -0
- petra_lang-0.1.0/pyproject.toml +24 -0
petra_lang-0.1.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 [yyyy] [name of copyright owner]
|
|
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.
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: petra-lang
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Checks physical designs against their stated claims, with an exact-arithmetic certificate for every PASS and FAIL
|
|
5
|
+
Requires-Python: >=3.11
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Requires-Dist: numpy>=1.23.2
|
|
9
|
+
Requires-Dist: scipy>=1.9.2
|
|
10
|
+
Project-URL: Source, https://github.com/NooterraLabs/petra
|
|
11
|
+
Project-URL: Issues, https://github.com/NooterraLabs/petra/issues
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
|
|
14
|
+
# Petra
|
|
15
|
+
|
|
16
|
+
Petra checks a physical design against the claims written in it. A design is a short `.petra` file that describes a steel connection, a truss, a wire circuit or a bolted joint. Petra answers pass, fail, marginal or unknown, and backs every pass and fail with a certificate that a small kernel re-checks in exact arithmetic.
|
|
17
|
+
|
|
18
|
+
Petra checks the loads a design states. It does not choose them, and it does not replace the engineer who signs the design.
|
|
19
|
+
|
|
20
|
+
## Install
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
pip install petra-lang
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Use
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
petra new shear_tab > tab.petra
|
|
30
|
+
petra check tab.petra
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
`petra new` prints an example design to edit. `petra check` prints the verdict, the check that governs it, and every check behind it. `petra kinds` lists what Petra can check, and `petra docs` lists the documents that ship with it.
|
|
34
|
+
|
|
35
|
+
## Learn more
|
|
36
|
+
|
|
37
|
+
- [Language reference](https://github.com/NooterraLabs/petra/blob/v0.1.0/docs/reference.md)
|
|
38
|
+
- [Using Petra from Python](https://github.com/NooterraLabs/petra/blob/v0.1.0/petra/docs/api.md)
|
|
39
|
+
- [How the checker works](https://github.com/NooterraLabs/petra/blob/v0.1.0/docs/design.md)
|
|
40
|
+
- [Steel connections](https://github.com/NooterraLabs/petra/blob/v0.1.0/docs/steel_connections.md)
|
|
41
|
+
- [Roadmap and test results](https://github.com/NooterraLabs/petra/blob/v0.1.0/docs/plan.md)
|
|
42
|
+
|
|
43
|
+
## License
|
|
44
|
+
|
|
45
|
+
Code is under Apache-2.0 and docs are under Creative Commons Attribution 4.0. To send a change, read [contributing](https://github.com/NooterraLabs/petra/blob/v0.1.0/CONTRIBUTING.md).
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# Petra
|
|
2
|
+
|
|
3
|
+
Petra checks a physical design against the claims written in it. A design is a short `.petra` file that describes a steel connection, a truss, a wire circuit or a bolted joint. Petra answers pass, fail, marginal or unknown, and backs every pass and fail with a certificate that a small kernel re-checks in exact arithmetic.
|
|
4
|
+
|
|
5
|
+
Petra checks the loads a design states. It does not choose them, and it does not replace the engineer who signs the design.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pip install petra-lang
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Use
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
petra new shear_tab > tab.petra
|
|
17
|
+
petra check tab.petra
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
`petra new` prints an example design to edit. `petra check` prints the verdict, the check that governs it, and every check behind it. `petra kinds` lists what Petra can check, and `petra docs` lists the documents that ship with it.
|
|
21
|
+
|
|
22
|
+
## Learn more
|
|
23
|
+
|
|
24
|
+
- [Language reference](docs/reference.md)
|
|
25
|
+
- [Using Petra from Python](petra/docs/api.md)
|
|
26
|
+
- [How the checker works](docs/design.md)
|
|
27
|
+
- [Steel connections](docs/steel_connections.md)
|
|
28
|
+
- [Roadmap and test results](docs/plan.md)
|
|
29
|
+
|
|
30
|
+
## License
|
|
31
|
+
|
|
32
|
+
Code is under Apache-2.0 and docs are under Creative Commons Attribution 4.0. To send a change, read [contributing](CONTRIBUTING.md).
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
"""Petra's build backend: the PEP 517 wheel and sdist hooks and the PEP 660 editable hook,
|
|
2
|
+
standard library only. pyproject.toml names it with `requires = []`, so pip builds Petra
|
|
3
|
+
with no build packages and no network, under build isolation too.
|
|
4
|
+
|
|
5
|
+
The [project] table gives the core metadata (version 2.4), and a key this module does not
|
|
6
|
+
write is an error, never a silent omission. [tool.petra-build] `include` lists, as globs
|
|
7
|
+
from the project root, every file the wheel ships. The sdist holds those files and the
|
|
8
|
+
build inputs, so a wheel built from it ships the same files. Both archives carry fixed
|
|
9
|
+
timestamps, so one tree always builds the same bytes.
|
|
10
|
+
"""
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
import base64
|
|
14
|
+
import csv
|
|
15
|
+
import gzip
|
|
16
|
+
import hashlib
|
|
17
|
+
import io
|
|
18
|
+
import locale
|
|
19
|
+
import re
|
|
20
|
+
import tarfile
|
|
21
|
+
import zipfile
|
|
22
|
+
from pathlib import Path
|
|
23
|
+
from typing import Any
|
|
24
|
+
|
|
25
|
+
try:
|
|
26
|
+
import tomllib
|
|
27
|
+
except ModuleNotFoundError as exc:
|
|
28
|
+
raise RuntimeError("Petra needs Python 3.11 or later") from exc
|
|
29
|
+
|
|
30
|
+
ROOT = Path(__file__).resolve().parent.parent
|
|
31
|
+
|
|
32
|
+
WRITTEN = frozenset({"name", "version", "description", "readme", "requires-python", "license", "license-files", "dependencies", "urls", "scripts"})
|
|
33
|
+
"""The [project] keys the metadata carries."""
|
|
34
|
+
|
|
35
|
+
ZIP_EPOCH = (1980, 1, 1, 0, 0, 0)
|
|
36
|
+
"""The earliest time a zip entry can carry."""
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def _pyproject() -> tuple[dict[str, Any], list[str]]:
|
|
40
|
+
"""The [project] table and the include globs, checked."""
|
|
41
|
+
data = tomllib.loads((ROOT / "pyproject.toml").read_text(encoding="utf-8"))
|
|
42
|
+
project = data["project"]
|
|
43
|
+
unwritten = sorted(set(project) - WRITTEN)
|
|
44
|
+
if unwritten:
|
|
45
|
+
raise ValueError(f"petra_build does not write the [project] keys {unwritten}")
|
|
46
|
+
if not project["readme"].endswith(".md"):
|
|
47
|
+
raise ValueError("petra_build writes the readme as text/markdown, so it must be a .md file")
|
|
48
|
+
return project, data["tool"]["petra-build"]["include"]
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def _dist(project: dict[str, Any]) -> str:
|
|
52
|
+
"""The distribution name as archive file names spell it."""
|
|
53
|
+
return re.sub(r"[-_.]+", "_", project["name"]).lower()
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def _shipped(include: list[str]) -> list[str]:
|
|
57
|
+
"""The project-relative paths the wheel ships, sorted. A glob that matches no file is
|
|
58
|
+
an error, so a moved data file cannot drop out of the wheel unnoticed."""
|
|
59
|
+
paths: set[str] = set()
|
|
60
|
+
for pattern in include:
|
|
61
|
+
found = {p.relative_to(ROOT).as_posix() for p in ROOT.glob(pattern)
|
|
62
|
+
if p.is_file() and "__pycache__" not in p.relative_to(ROOT).parts}
|
|
63
|
+
if not found:
|
|
64
|
+
raise ValueError(f"[tool.petra-build] include glob {pattern!r} matches no file")
|
|
65
|
+
paths |= found
|
|
66
|
+
return sorted(paths)
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
RELATIVE_LINK = re.compile(r"\]\((?!https?://|#|mailto:)([^)\s]+)\)")
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def description(project: dict[str, Any]) -> str:
|
|
73
|
+
"""The readme as PyPI and an installed `petra docs readme` show it. Neither has the
|
|
74
|
+
repository beside it, so each relative link points into the repository at the release
|
|
75
|
+
tag `v<version>`."""
|
|
76
|
+
base = f"{project['urls']['Source']}/blob/v{project['version']}/"
|
|
77
|
+
readme = (ROOT / project["readme"]).read_text(encoding="utf-8")
|
|
78
|
+
return RELATIVE_LINK.sub(lambda m: f"]({base}{m.group(1)})", readme)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def _metadata(project: dict[str, Any]) -> bytes:
|
|
82
|
+
fields = [
|
|
83
|
+
("Metadata-Version", "2.4"),
|
|
84
|
+
("Name", project["name"]),
|
|
85
|
+
("Version", project["version"]),
|
|
86
|
+
("Summary", project["description"]),
|
|
87
|
+
("Requires-Python", project["requires-python"]),
|
|
88
|
+
("License-Expression", project["license"]),
|
|
89
|
+
*(("License-File", f) for f in project["license-files"]),
|
|
90
|
+
*(("Requires-Dist", d) for d in project["dependencies"]),
|
|
91
|
+
*(("Project-URL", f"{label}, {url}") for label, url in project["urls"].items()),
|
|
92
|
+
("Description-Content-Type", "text/markdown"),
|
|
93
|
+
]
|
|
94
|
+
return ("".join(f"{k}: {v}\n" for k, v in fields) + "\n" + description(project)).encode("utf-8")
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def _wheel(directory: str, project: dict[str, Any], payload: list[tuple[str, bytes]]) -> str:
|
|
98
|
+
"""Write the wheel of `payload` plus its .dist-info and return its file name."""
|
|
99
|
+
name, version = _dist(project), project["version"]
|
|
100
|
+
info = f"{name}-{version}.dist-info"
|
|
101
|
+
scripts = "".join(f"{k} = {v}\n" for k, v in project["scripts"].items())
|
|
102
|
+
files = [
|
|
103
|
+
*payload,
|
|
104
|
+
(f"{info}/METADATA", _metadata(project)),
|
|
105
|
+
(f"{info}/WHEEL", b"Wheel-Version: 1.0\nGenerator: petra_build\nRoot-Is-Purelib: true\nTag: py3-none-any\n"),
|
|
106
|
+
(f"{info}/entry_points.txt", f"[console_scripts]\n{scripts}".encode("utf-8")),
|
|
107
|
+
*((f"{info}/licenses/{f}", (ROOT / f).read_bytes()) for f in project["license-files"]),
|
|
108
|
+
]
|
|
109
|
+
record = io.StringIO()
|
|
110
|
+
rows = csv.writer(record, lineterminator="\n")
|
|
111
|
+
for path, data in files:
|
|
112
|
+
digest = base64.urlsafe_b64encode(hashlib.sha256(data).digest()).rstrip(b"=").decode("ascii")
|
|
113
|
+
rows.writerow([path, f"sha256={digest}", len(data)])
|
|
114
|
+
rows.writerow([f"{info}/RECORD", "", ""])
|
|
115
|
+
files.append((f"{info}/RECORD", record.getvalue().encode("utf-8")))
|
|
116
|
+
filename = f"{name}-{version}-py3-none-any.whl"
|
|
117
|
+
with zipfile.ZipFile(Path(directory) / filename, "w") as archive:
|
|
118
|
+
for path, data in files:
|
|
119
|
+
entry = zipfile.ZipInfo(path, ZIP_EPOCH)
|
|
120
|
+
entry.external_attr = 0o644 << 16
|
|
121
|
+
entry.compress_type = zipfile.ZIP_DEFLATED
|
|
122
|
+
archive.writestr(entry, data)
|
|
123
|
+
return filename
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def build_wheel(wheel_directory: str, config_settings: dict | None = None, metadata_directory: str | None = None) -> str:
|
|
127
|
+
project, include = _pyproject()
|
|
128
|
+
return _wheel(wheel_directory, project, [(p, (ROOT / p).read_bytes()) for p in _shipped(include)])
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def build_editable(wheel_directory: str, config_settings: dict | None = None, metadata_directory: str | None = None) -> str:
|
|
132
|
+
"""A wheel whose .pth file puts this source tree on sys.path, so edits take effect
|
|
133
|
+
without reinstalling."""
|
|
134
|
+
project, _ = _pyproject()
|
|
135
|
+
# Python 3.11 reads .pth files in the locale encoding; 3.13 tries UTF-8 first, then that.
|
|
136
|
+
line = f"{ROOT}\n".encode(locale.getpreferredencoding(False))
|
|
137
|
+
return _wheel(wheel_directory, project, [(f"_{_dist(project)}_editable.pth", line)])
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def build_sdist(sdist_directory: str, config_settings: dict | None = None) -> str:
|
|
141
|
+
project, include = _pyproject()
|
|
142
|
+
base = f"{_dist(project)}-{project['version']}"
|
|
143
|
+
inputs = {"pyproject.toml", Path(__file__).resolve().relative_to(ROOT).as_posix(), project["readme"], *project["license-files"]}
|
|
144
|
+
files = [("PKG-INFO", _metadata(project)), *((p, (ROOT / p).read_bytes()) for p in sorted(inputs | set(_shipped(include))))]
|
|
145
|
+
filename = f"{base}.tar.gz"
|
|
146
|
+
with open(Path(sdist_directory) / filename, "wb") as raw, \
|
|
147
|
+
gzip.GzipFile(filename=filename, fileobj=raw, mode="wb", mtime=0) as gz, \
|
|
148
|
+
tarfile.open(fileobj=gz, mode="w", format=tarfile.PAX_FORMAT) as tar:
|
|
149
|
+
for path, data in files:
|
|
150
|
+
entry = tarfile.TarInfo(f"{base}/{path}")
|
|
151
|
+
entry.size, entry.mode = len(data), 0o644
|
|
152
|
+
tar.addfile(entry, io.BytesIO(data))
|
|
153
|
+
return filename
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
def get_requires_for_build_wheel(config_settings: dict | None = None) -> list[str]:
|
|
157
|
+
return []
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
def get_requires_for_build_sdist(config_settings: dict | None = None) -> list[str]:
|
|
161
|
+
return []
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
def get_requires_for_build_editable(config_settings: dict | None = None) -> list[str]:
|
|
165
|
+
return []
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"""Petra: verdicts about physical designs as theorems relative to explicit premises.
|
|
2
|
+
|
|
3
|
+
import petra
|
|
4
|
+
report = petra.check_file("examples/truss_pass.petra")
|
|
5
|
+
print(report.render())
|
|
6
|
+
report.verdict # petra.Pass | petra.Fail | petra.Unknown | petra.Marginal
|
|
7
|
+
report.verdict.footprint # every non-proved premise the verdict used
|
|
8
|
+
report.findings # each obligation's numbers in the design's units (readout.py)
|
|
9
|
+
|
|
10
|
+
petra/docs/api.md documents this API and the JSON `petra check --json` prints, and
|
|
11
|
+
`petra docs api` prints it from any install. `petra docs` lists every document, the
|
|
12
|
+
language reference among them.
|
|
13
|
+
|
|
14
|
+
Trust layout:
|
|
15
|
+
petra.kernel mathematics only, stdlib only, the part a Lean kernel replaces
|
|
16
|
+
petra.models physics elaborators, trusted, each one a validated_model premise
|
|
17
|
+
petra.lang, petra.ir, petra.units, petra.registry (model, constants, catalog),
|
|
18
|
+
petra.premises, petra.coverage, petra.verdict, petra.pipeline trusted plumbing
|
|
19
|
+
everything else (solvers, library, certs, registry.deck and registry.consistency,
|
|
20
|
+
gym, bench, readout, envelope, cli) is untrusted: a bug there costs an UNKNOWN, never
|
|
21
|
+
a false PASS.
|
|
22
|
+
"""
|
|
23
|
+
from __future__ import annotations
|
|
24
|
+
|
|
25
|
+
from pathlib import Path
|
|
26
|
+
|
|
27
|
+
from .certs import CertStore
|
|
28
|
+
from .lang import load_design, parse_design
|
|
29
|
+
from .library import Library, certify_family
|
|
30
|
+
from .pipeline import Report, check_design, explain
|
|
31
|
+
from .registry import build_registry
|
|
32
|
+
from .solvers import SolverSource
|
|
33
|
+
from .verdict import Fail, Marginal, Pass, Unknown, Verdict
|
|
34
|
+
|
|
35
|
+
__version__ = "0.1.0"
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def check_file(path: str | Path, *, certs: str | Path | None = None, library: Library | None = None, solve: bool = True) -> Report:
|
|
39
|
+
"""Convenience shell over check_design: default registry, evidence sources in the
|
|
40
|
+
order certs -> library -> solvers, accepted evidence recorded into `certs` when given."""
|
|
41
|
+
registry = build_registry()
|
|
42
|
+
design = load_design(path, registry)
|
|
43
|
+
store = CertStore(certs) if certs is not None else None
|
|
44
|
+
sources = tuple(s for s in (store, library, SolverSource() if solve else None) if s is not None)
|
|
45
|
+
return check_design(design, registry, sources, sink=store, path=str(path))
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Benchmarks. Untrusted."""
|