zombieos-zsharp 1.4.1.1__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.
- zombieos_zsharp-1.4.1.1/LICENSE +201 -0
- zombieos_zsharp-1.4.1.1/PKG-INFO +164 -0
- zombieos_zsharp-1.4.1.1/README.md +152 -0
- zombieos_zsharp-1.4.1.1/pyproject.toml +20 -0
- zombieos_zsharp-1.4.1.1/setup.cfg +4 -0
- zombieos_zsharp-1.4.1.1/src/zombieos_zsharp.egg-info/PKG-INFO +164 -0
- zombieos_zsharp-1.4.1.1/src/zombieos_zsharp.egg-info/SOURCES.txt +10 -0
- zombieos_zsharp-1.4.1.1/src/zombieos_zsharp.egg-info/dependency_links.txt +1 -0
- zombieos_zsharp-1.4.1.1/src/zombieos_zsharp.egg-info/top_level.txt +1 -0
- zombieos_zsharp-1.4.1.1/src/zsharp/__init__.py +323 -0
- zombieos_zsharp-1.4.1.1/tests/test_runtime.py +85 -0
- zombieos_zsharp-1.4.1.1/tests/test_zsharp.py +303 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 ZombieOS
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: zombieos-zsharp
|
|
3
|
+
Version: 1.4.1.1
|
|
4
|
+
Summary: Call public Z# functions from standalone Python
|
|
5
|
+
Author: ZombieOS
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://zsharp.zombieos.com
|
|
8
|
+
Requires-Python: >=3.9
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Dynamic: license-file
|
|
12
|
+
|
|
13
|
+
# Z# for Python
|
|
14
|
+
|
|
15
|
+
Call a Z# function from a regular Python program using the installed ZVM
|
|
16
|
+
1.4.1.1 or later. The package has no Python runtime dependencies and does not
|
|
17
|
+
download or install ZVM. Install the matching ZVM separately from the
|
|
18
|
+
[official Z# website](https://zsharp.zombieos.com).
|
|
19
|
+
|
|
20
|
+
The PyPI distribution is named `zombieos-zsharp`. Once it has been published,
|
|
21
|
+
install it into your Python environment with:
|
|
22
|
+
|
|
23
|
+
```sh
|
|
24
|
+
python -m pip install zombieos-zsharp
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
The Python import remains `from zsharp import call`. The unrelated PyPI
|
|
28
|
+
distribution named `zsharp` is not ZombieOS's Z# bridge.
|
|
29
|
+
|
|
30
|
+
Install this local package into your Python environment:
|
|
31
|
+
|
|
32
|
+
```sh
|
|
33
|
+
python -m pip install /path/to/Z\#/python
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
When the environment already has setuptools 77.0.3 or later, an offline editable
|
|
37
|
+
installation is also available:
|
|
38
|
+
|
|
39
|
+
```sh
|
|
40
|
+
python -m pip install --no-index --no-build-isolation --no-deps -e /path/to/Z\#/python
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
For example, `/path/to/project/Math.zsharp` can contain:
|
|
44
|
+
|
|
45
|
+
```zsharp
|
|
46
|
+
zsharp = type.script
|
|
47
|
+
|
|
48
|
+
noticed room Calculator[] (
|
|
49
|
+
noticed number Add[number Left, number Right] (
|
|
50
|
+
feed(Left + Right):
|
|
51
|
+
)
|
|
52
|
+
)
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
The project must also have its normal `project.zsettings`. From Python:
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
from zsharp import call
|
|
59
|
+
|
|
60
|
+
answer = call("Math:Calculator:Add", 20, 22, project="/path/to/project")
|
|
61
|
+
print(answer) # 42
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Reuse a project and runtime configuration with `ZSharp`:
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
from zsharp import ZSharp
|
|
68
|
+
|
|
69
|
+
project = ZSharp(
|
|
70
|
+
project="/path/to/project",
|
|
71
|
+
executable="/path/to/zsharp", # optional
|
|
72
|
+
timeout=30, # seconds; None disables the limit
|
|
73
|
+
)
|
|
74
|
+
answer = project.call("Math:Calculator:Add", 20, 22)
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
`call(target, *arguments, project=None, executable=None, timeout=30)` defaults
|
|
78
|
+
to the current directory. Targets have exactly three parts:
|
|
79
|
+
`File:Room:Function`. The file may be `Math`, `Math.zsharp`, or a relative path
|
|
80
|
+
such as `tools/Math`; it must remain inside the project. The room and function
|
|
81
|
+
must be `noticed`. Ordinary brains and typed functions are supported.
|
|
82
|
+
|
|
83
|
+
Runtime discovery checks an explicit `executable`, `ZSHARP_EXECUTABLE`, the
|
|
84
|
+
current PATH, and the default user installation. That includes
|
|
85
|
+
`~/.local/bin/zsharp`, and on Windows
|
|
86
|
+
`%LOCALAPPDATA%\ZombieOS\ZSharp\bin\zsharp.exe`.
|
|
87
|
+
|
|
88
|
+
Each call starts a fresh VM, initializes the project, invokes the selected
|
|
89
|
+
function, and exits. `Start` and `Shutdown` are not called automatically;
|
|
90
|
+
globals and live objects do not persist between calls. No source wrapper is
|
|
91
|
+
generated. Native `Print` output and errors go to Python's stdout and stderr;
|
|
92
|
+
the return value travels in a separate result file.
|
|
93
|
+
|
|
94
|
+
Python `str`, `bool`, `None`, `int`, finite `float`, `Decimal`, and string-keyed
|
|
95
|
+
records use the existing Z# value bridge. Return values include plain records
|
|
96
|
+
and supported Z# arrays; integer numbers become `int`, while numbers with a
|
|
97
|
+
decimal point or exponent become `decimal.Decimal` so precision is preserved.
|
|
98
|
+
The VM currently accepts homogeneous text/number/object arrays, including
|
|
99
|
+
arrays nested in records. Z# does not yet declare direct array parameters;
|
|
100
|
+
put array data in an `object` record when passing it into a function. Mixed,
|
|
101
|
+
boolean, null, or nested arrays are not supported by the VM. Live room or
|
|
102
|
+
foreign object handles cannot be returned from a one-shot call. Calls have a
|
|
103
|
+
1 MiB request/result limit, a nesting limit of 32, and at most 1024 arguments.
|
|
104
|
+
|
|
105
|
+
```python
|
|
106
|
+
from zsharp import ZSharpError
|
|
107
|
+
|
|
108
|
+
try:
|
|
109
|
+
result = project.call("Math:Calculator:Add", 20, 22, timeout=5)
|
|
110
|
+
except ZSharpError as error:
|
|
111
|
+
print(error)
|
|
112
|
+
# error.stdout, error.stderr, error.returncode, error.timed_out
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
Invalid Python argument types, non-finite numbers, and malformed targets raise
|
|
116
|
+
`TypeError` or `ValueError`. Runtime discovery, native diagnostics, invalid
|
|
117
|
+
responses, and timeouts raise `ZSharpError`. A timeout terminates the ZVM
|
|
118
|
+
subprocess and returns promptly. A foreign worker already executing Python,
|
|
119
|
+
Java, or another language may finish its current call before noticing that
|
|
120
|
+
the VM has exited. The package launches an argument list without a shell.
|
|
121
|
+
|
|
122
|
+
Inside a Python module already running under ZVM, the worker continues to
|
|
123
|
+
provide its own `from zsharp import export, call` callback API. That callback
|
|
124
|
+
uses the active VM synchronously; installing this standalone package does not
|
|
125
|
+
change it.
|
|
126
|
+
|
|
127
|
+
Run the package tests without installing it:
|
|
128
|
+
|
|
129
|
+
```sh
|
|
130
|
+
python -m unittest discover -s python/tests -v
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## Publishing from GitHub
|
|
134
|
+
|
|
135
|
+
The repository workflow is **Publish Python package**, stored in
|
|
136
|
+
`.github/workflows/publish-python-package.yml`. It runs manually. With the
|
|
137
|
+
`publish` box unchecked, it tests the package on Python 3.9 and 3.14, checks
|
|
138
|
+
that Python/ZVM versions match, builds and validates both distribution files,
|
|
139
|
+
and saves them as a workflow artifact. Checking `publish` also uploads those
|
|
140
|
+
files to PyPI through a separate job using Trusted Publishing.
|
|
141
|
+
|
|
142
|
+
For the first release, configure a pending publisher on PyPI with these values:
|
|
143
|
+
|
|
144
|
+
| Field | Value |
|
|
145
|
+
| --- | --- |
|
|
146
|
+
| PyPI project name | `zombieos-zsharp` |
|
|
147
|
+
| GitHub owner | `ZombieOS` |
|
|
148
|
+
| Repository | `ZSharp` |
|
|
149
|
+
| Workflow name | `publish-python-package.yml` |
|
|
150
|
+
| Environment name | `pypi` |
|
|
151
|
+
|
|
152
|
+
The workflow file must be pushed to GitHub's default branch before it appears
|
|
153
|
+
under Actions.
|
|
154
|
+
The `pypi` environment in PyPI must match the workflow's environment name.
|
|
155
|
+
This workflow uses GitHub's identity token; no PyPI API token secret is needed.
|
|
156
|
+
|
|
157
|
+
Release the matching native ZVM (1.4.1.1 for this first Python package) before
|
|
158
|
+
running **Publish Python package** with `publish` checked. Older ZVM releases
|
|
159
|
+
do not implement the required `call` command. Adding the workflow and
|
|
160
|
+
configuring the publisher can happen beforehand; neither step publishes the
|
|
161
|
+
package. A normal commit or GitHub release does not start this workflow.
|
|
162
|
+
|
|
163
|
+
See [PyPI's Trusted Publishing guide](https://docs.pypi.org/trusted-publishers/using-a-publisher/)
|
|
164
|
+
and [creating a project with a pending publisher](https://docs.pypi.org/trusted-publishers/creating-a-project-through-oidc/).
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
# Z# for Python
|
|
2
|
+
|
|
3
|
+
Call a Z# function from a regular Python program using the installed ZVM
|
|
4
|
+
1.4.1.1 or later. The package has no Python runtime dependencies and does not
|
|
5
|
+
download or install ZVM. Install the matching ZVM separately from the
|
|
6
|
+
[official Z# website](https://zsharp.zombieos.com).
|
|
7
|
+
|
|
8
|
+
The PyPI distribution is named `zombieos-zsharp`. Once it has been published,
|
|
9
|
+
install it into your Python environment with:
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
python -m pip install zombieos-zsharp
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
The Python import remains `from zsharp import call`. The unrelated PyPI
|
|
16
|
+
distribution named `zsharp` is not ZombieOS's Z# bridge.
|
|
17
|
+
|
|
18
|
+
Install this local package into your Python environment:
|
|
19
|
+
|
|
20
|
+
```sh
|
|
21
|
+
python -m pip install /path/to/Z\#/python
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
When the environment already has setuptools 77.0.3 or later, an offline editable
|
|
25
|
+
installation is also available:
|
|
26
|
+
|
|
27
|
+
```sh
|
|
28
|
+
python -m pip install --no-index --no-build-isolation --no-deps -e /path/to/Z\#/python
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
For example, `/path/to/project/Math.zsharp` can contain:
|
|
32
|
+
|
|
33
|
+
```zsharp
|
|
34
|
+
zsharp = type.script
|
|
35
|
+
|
|
36
|
+
noticed room Calculator[] (
|
|
37
|
+
noticed number Add[number Left, number Right] (
|
|
38
|
+
feed(Left + Right):
|
|
39
|
+
)
|
|
40
|
+
)
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
The project must also have its normal `project.zsettings`. From Python:
|
|
44
|
+
|
|
45
|
+
```python
|
|
46
|
+
from zsharp import call
|
|
47
|
+
|
|
48
|
+
answer = call("Math:Calculator:Add", 20, 22, project="/path/to/project")
|
|
49
|
+
print(answer) # 42
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Reuse a project and runtime configuration with `ZSharp`:
|
|
53
|
+
|
|
54
|
+
```python
|
|
55
|
+
from zsharp import ZSharp
|
|
56
|
+
|
|
57
|
+
project = ZSharp(
|
|
58
|
+
project="/path/to/project",
|
|
59
|
+
executable="/path/to/zsharp", # optional
|
|
60
|
+
timeout=30, # seconds; None disables the limit
|
|
61
|
+
)
|
|
62
|
+
answer = project.call("Math:Calculator:Add", 20, 22)
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
`call(target, *arguments, project=None, executable=None, timeout=30)` defaults
|
|
66
|
+
to the current directory. Targets have exactly three parts:
|
|
67
|
+
`File:Room:Function`. The file may be `Math`, `Math.zsharp`, or a relative path
|
|
68
|
+
such as `tools/Math`; it must remain inside the project. The room and function
|
|
69
|
+
must be `noticed`. Ordinary brains and typed functions are supported.
|
|
70
|
+
|
|
71
|
+
Runtime discovery checks an explicit `executable`, `ZSHARP_EXECUTABLE`, the
|
|
72
|
+
current PATH, and the default user installation. That includes
|
|
73
|
+
`~/.local/bin/zsharp`, and on Windows
|
|
74
|
+
`%LOCALAPPDATA%\ZombieOS\ZSharp\bin\zsharp.exe`.
|
|
75
|
+
|
|
76
|
+
Each call starts a fresh VM, initializes the project, invokes the selected
|
|
77
|
+
function, and exits. `Start` and `Shutdown` are not called automatically;
|
|
78
|
+
globals and live objects do not persist between calls. No source wrapper is
|
|
79
|
+
generated. Native `Print` output and errors go to Python's stdout and stderr;
|
|
80
|
+
the return value travels in a separate result file.
|
|
81
|
+
|
|
82
|
+
Python `str`, `bool`, `None`, `int`, finite `float`, `Decimal`, and string-keyed
|
|
83
|
+
records use the existing Z# value bridge. Return values include plain records
|
|
84
|
+
and supported Z# arrays; integer numbers become `int`, while numbers with a
|
|
85
|
+
decimal point or exponent become `decimal.Decimal` so precision is preserved.
|
|
86
|
+
The VM currently accepts homogeneous text/number/object arrays, including
|
|
87
|
+
arrays nested in records. Z# does not yet declare direct array parameters;
|
|
88
|
+
put array data in an `object` record when passing it into a function. Mixed,
|
|
89
|
+
boolean, null, or nested arrays are not supported by the VM. Live room or
|
|
90
|
+
foreign object handles cannot be returned from a one-shot call. Calls have a
|
|
91
|
+
1 MiB request/result limit, a nesting limit of 32, and at most 1024 arguments.
|
|
92
|
+
|
|
93
|
+
```python
|
|
94
|
+
from zsharp import ZSharpError
|
|
95
|
+
|
|
96
|
+
try:
|
|
97
|
+
result = project.call("Math:Calculator:Add", 20, 22, timeout=5)
|
|
98
|
+
except ZSharpError as error:
|
|
99
|
+
print(error)
|
|
100
|
+
# error.stdout, error.stderr, error.returncode, error.timed_out
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Invalid Python argument types, non-finite numbers, and malformed targets raise
|
|
104
|
+
`TypeError` or `ValueError`. Runtime discovery, native diagnostics, invalid
|
|
105
|
+
responses, and timeouts raise `ZSharpError`. A timeout terminates the ZVM
|
|
106
|
+
subprocess and returns promptly. A foreign worker already executing Python,
|
|
107
|
+
Java, or another language may finish its current call before noticing that
|
|
108
|
+
the VM has exited. The package launches an argument list without a shell.
|
|
109
|
+
|
|
110
|
+
Inside a Python module already running under ZVM, the worker continues to
|
|
111
|
+
provide its own `from zsharp import export, call` callback API. That callback
|
|
112
|
+
uses the active VM synchronously; installing this standalone package does not
|
|
113
|
+
change it.
|
|
114
|
+
|
|
115
|
+
Run the package tests without installing it:
|
|
116
|
+
|
|
117
|
+
```sh
|
|
118
|
+
python -m unittest discover -s python/tests -v
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## Publishing from GitHub
|
|
122
|
+
|
|
123
|
+
The repository workflow is **Publish Python package**, stored in
|
|
124
|
+
`.github/workflows/publish-python-package.yml`. It runs manually. With the
|
|
125
|
+
`publish` box unchecked, it tests the package on Python 3.9 and 3.14, checks
|
|
126
|
+
that Python/ZVM versions match, builds and validates both distribution files,
|
|
127
|
+
and saves them as a workflow artifact. Checking `publish` also uploads those
|
|
128
|
+
files to PyPI through a separate job using Trusted Publishing.
|
|
129
|
+
|
|
130
|
+
For the first release, configure a pending publisher on PyPI with these values:
|
|
131
|
+
|
|
132
|
+
| Field | Value |
|
|
133
|
+
| --- | --- |
|
|
134
|
+
| PyPI project name | `zombieos-zsharp` |
|
|
135
|
+
| GitHub owner | `ZombieOS` |
|
|
136
|
+
| Repository | `ZSharp` |
|
|
137
|
+
| Workflow name | `publish-python-package.yml` |
|
|
138
|
+
| Environment name | `pypi` |
|
|
139
|
+
|
|
140
|
+
The workflow file must be pushed to GitHub's default branch before it appears
|
|
141
|
+
under Actions.
|
|
142
|
+
The `pypi` environment in PyPI must match the workflow's environment name.
|
|
143
|
+
This workflow uses GitHub's identity token; no PyPI API token secret is needed.
|
|
144
|
+
|
|
145
|
+
Release the matching native ZVM (1.4.1.1 for this first Python package) before
|
|
146
|
+
running **Publish Python package** with `publish` checked. Older ZVM releases
|
|
147
|
+
do not implement the required `call` command. Adding the workflow and
|
|
148
|
+
configuring the publisher can happen beforehand; neither step publishes the
|
|
149
|
+
package. A normal commit or GitHub release does not start this workflow.
|
|
150
|
+
|
|
151
|
+
See [PyPI's Trusted Publishing guide](https://docs.pypi.org/trusted-publishers/using-a-publisher/)
|
|
152
|
+
and [creating a project with a pending publisher](https://docs.pypi.org/trusted-publishers/creating-a-project-through-oidc/).
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77.0.3"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "zombieos-zsharp"
|
|
7
|
+
version = "1.4.1.1"
|
|
8
|
+
description = "Call public Z# functions from standalone Python"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.9"
|
|
11
|
+
authors = [{name = "ZombieOS"}]
|
|
12
|
+
license = "Apache-2.0"
|
|
13
|
+
license-files = ["LICENSE"]
|
|
14
|
+
dependencies = []
|
|
15
|
+
|
|
16
|
+
[project.urls]
|
|
17
|
+
Homepage = "https://zsharp.zombieos.com"
|
|
18
|
+
|
|
19
|
+
[tool.setuptools.packages.find]
|
|
20
|
+
where = ["src"]
|