pumpkin-api-py 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- componentize_py_async_support/__init__.py +570 -0
- componentize_py_async_support/futures.py +149 -0
- componentize_py_async_support/streams.py +345 -0
- componentize_py_runtime.pyi +40 -0
- componentize_py_types.py +32 -0
- poll_loop.py +440 -0
- pumpkin_api/__init__.py +41 -0
- pumpkin_api/build.py +68 -0
- pumpkin_api/impl.py +355 -0
- pumpkin_api/wit/advancement.wit +41 -0
- pumpkin_api/wit/attributes.wit +56 -0
- pumpkin_api/wit/bedrock-packets.wit +1709 -0
- pumpkin_api/wit/biomes.wit +72 -0
- pumpkin_api/wit/block-entity.wit +423 -0
- pumpkin_api/wit/boss-bar.wit +83 -0
- pumpkin_api/wit/command.wit +244 -0
- pumpkin_api/wit/common.wit +261 -0
- pumpkin_api/wit/context.wit +61 -0
- pumpkin_api/wit/damage-types.wit +57 -0
- pumpkin_api/wit/data-components.wit +117 -0
- pumpkin_api/wit/datapack.wit +54 -0
- pumpkin_api/wit/display.wit +171 -0
- pumpkin_api/wit/enchantments.wit +102 -0
- pumpkin_api/wit/entity-statuses.wit +68 -0
- pumpkin_api/wit/entity-types.wit +164 -0
- pumpkin_api/wit/entity.wit +1 -0
- pumpkin_api/wit/event.wit +2435 -0
- pumpkin_api/wit/forms.wit +51 -0
- pumpkin_api/wit/game-events.wit +67 -0
- pumpkin_api/wit/game-rules.wit +69 -0
- pumpkin_api/wit/gui.wit +39 -0
- pumpkin_api/wit/i18n.wit +21 -0
- pumpkin_api/wit/inventory.wit +78 -0
- pumpkin_api/wit/ipc.wit +7 -0
- pumpkin_api/wit/item-stack.wit +104 -0
- pumpkin_api/wit/java-dialogs.wit +155 -0
- pumpkin_api/wit/java-packets.wit +1838 -0
- pumpkin_api/wit/log.wit +14 -0
- pumpkin_api/wit/metadata.wit +19 -0
- pumpkin_api/wit/particles.wit +131 -0
- pumpkin_api/wit/permission.wit +46 -0
- pumpkin_api/wit/player.wit +1432 -0
- pumpkin_api/wit/plugin.wit +121 -0
- pumpkin_api/wit/potions.wit +52 -0
- pumpkin_api/wit/recipe.wit +88 -0
- pumpkin_api/wit/scheduler.wit +24 -0
- pumpkin_api/wit/scoreboard.wit +111 -0
- pumpkin_api/wit/screens.wit +31 -0
- pumpkin_api/wit/server.wit +286 -0
- pumpkin_api/wit/sounds.wit +1987 -0
- pumpkin_api/wit/statistics.wit +94 -0
- pumpkin_api/wit/status-effect.wit +54 -0
- pumpkin_api/wit/text.wit +68 -0
- pumpkin_api/wit/uuid.wit +16 -0
- pumpkin_api/wit/world.wit +1050 -0
- pumpkin_api_py-0.1.0.dist-info/METADATA +53 -0
- pumpkin_api_py-0.1.0.dist-info/RECORD +108 -0
- pumpkin_api_py-0.1.0.dist-info/WHEEL +4 -0
- pumpkin_api_py-0.1.0.dist-info/entry_points.txt +2 -0
- pumpkin_api_py-0.1.0.dist-info/licenses/LICENSE-APACHE +176 -0
- pumpkin_api_py-0.1.0.dist-info/licenses/LICENSE-MIT +21 -0
- wit_world/__init__.py +114 -0
- wit_world/exports/__init__.py +19 -0
- wit_world/exports/metadata.py +24 -0
- wit_world/imports/__init__.py +0 -0
- wit_world/imports/advancement.py +56 -0
- wit_world/imports/attributes.py +66 -0
- wit_world/imports/bedrock_packets.py +2413 -0
- wit_world/imports/biomes.py +81 -0
- wit_world/imports/block_entity.py +1353 -0
- wit_world/imports/boss_bar.py +137 -0
- wit_world/imports/command.py +705 -0
- wit_world/imports/common.py +335 -0
- wit_world/imports/context.py +91 -0
- wit_world/imports/damage_types.py +66 -0
- wit_world/imports/data_components.py +126 -0
- wit_world/imports/datapack.py +124 -0
- wit_world/imports/display.py +295 -0
- wit_world/imports/enchantments.py +129 -0
- wit_world/imports/entity_statuses.py +77 -0
- wit_world/imports/entity_types.py +173 -0
- wit_world/imports/event.py +3558 -0
- wit_world/imports/forms.py +98 -0
- wit_world/imports/game_events.py +76 -0
- wit_world/imports/game_rules.py +88 -0
- wit_world/imports/gui.py +81 -0
- wit_world/imports/i18n.py +35 -0
- wit_world/imports/inventory.py +159 -0
- wit_world/imports/ipc.py +20 -0
- wit_world/imports/item_stack.py +206 -0
- wit_world/imports/java_dialogs.py +208 -0
- wit_world/imports/java_packets.py +3560 -0
- wit_world/imports/logging.py +30 -0
- wit_world/imports/particles.py +140 -0
- wit_world/imports/permission.py +71 -0
- wit_world/imports/player.py +1753 -0
- wit_world/imports/potions.py +61 -0
- wit_world/imports/recipe.py +120 -0
- wit_world/imports/scheduler.py +44 -0
- wit_world/imports/scoreboard.py +167 -0
- wit_world/imports/screens.py +40 -0
- wit_world/imports/server.py +493 -0
- wit_world/imports/sounds.py +1996 -0
- wit_world/imports/statistics.py +103 -0
- wit_world/imports/status_effect.py +63 -0
- wit_world/imports/text.py +156 -0
- wit_world/imports/uuid.py +36 -0
- wit_world/imports/world.py +1640 -0
poll_loop.py
ADDED
|
@@ -0,0 +1,440 @@
|
|
|
1
|
+
"""Defines a custom `asyncio` event loop backed by `wasi:io/poll#poll`.
|
|
2
|
+
|
|
3
|
+
This also includes helper classes and functions for working with `wasi:http`.
|
|
4
|
+
|
|
5
|
+
This is only useful for `wasi:http@0.2.x`; `wasi:http@0.3.x` uses a different
|
|
6
|
+
mechanism to model concurrency.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
import asyncio
|
|
10
|
+
import socket
|
|
11
|
+
import subprocess
|
|
12
|
+
|
|
13
|
+
from componentize_py_types import Ok, Err
|
|
14
|
+
from wit_world.imports import types, streams, poll, outgoing_handler
|
|
15
|
+
from wit_world.imports.types import (
|
|
16
|
+
IncomingBody,
|
|
17
|
+
OutgoingBody,
|
|
18
|
+
OutgoingRequest,
|
|
19
|
+
IncomingResponse,
|
|
20
|
+
)
|
|
21
|
+
from wit_world.imports.streams import StreamError_Closed, InputStream
|
|
22
|
+
from wit_world.imports.poll import Pollable
|
|
23
|
+
from typing import Optional, cast
|
|
24
|
+
|
|
25
|
+
# Maximum number of bytes to read at a time
|
|
26
|
+
READ_SIZE: int = 16 * 1024
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
async def send(request: OutgoingRequest) -> IncomingResponse:
|
|
30
|
+
"""Send the specified request and wait asynchronously for the response."""
|
|
31
|
+
|
|
32
|
+
future = outgoing_handler.handle(request, None)
|
|
33
|
+
|
|
34
|
+
while True:
|
|
35
|
+
response = future.get()
|
|
36
|
+
if response is None:
|
|
37
|
+
await register(cast(PollLoop, asyncio.get_event_loop()), future.subscribe())
|
|
38
|
+
else:
|
|
39
|
+
if isinstance(response, Ok):
|
|
40
|
+
if isinstance(response.value, Ok):
|
|
41
|
+
return response.value.value
|
|
42
|
+
else:
|
|
43
|
+
raise response.value
|
|
44
|
+
else:
|
|
45
|
+
raise response
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class Stream:
|
|
49
|
+
"""Reader abstraction over `wasi:http/types#incoming-body`."""
|
|
50
|
+
|
|
51
|
+
def __init__(self, body: IncomingBody):
|
|
52
|
+
self.body: Optional[IncomingBody] = body
|
|
53
|
+
self.stream: Optional[InputStream] = body.stream()
|
|
54
|
+
|
|
55
|
+
async def next(self) -> Optional[bytes]:
|
|
56
|
+
"""Wait for the next chunk of data to arrive on the stream.
|
|
57
|
+
|
|
58
|
+
This will return `None` when the end of the stream has been reached.
|
|
59
|
+
"""
|
|
60
|
+
while True:
|
|
61
|
+
try:
|
|
62
|
+
if self.stream is None:
|
|
63
|
+
return None
|
|
64
|
+
else:
|
|
65
|
+
buffer = self.stream.read(READ_SIZE)
|
|
66
|
+
if len(buffer) == 0:
|
|
67
|
+
await register(
|
|
68
|
+
cast(PollLoop, asyncio.get_event_loop()),
|
|
69
|
+
self.stream.subscribe(),
|
|
70
|
+
)
|
|
71
|
+
else:
|
|
72
|
+
return buffer
|
|
73
|
+
except Err as e:
|
|
74
|
+
if isinstance(e.value, StreamError_Closed):
|
|
75
|
+
if self.stream is not None:
|
|
76
|
+
self.stream.__exit__(None, None, None)
|
|
77
|
+
self.stream = None
|
|
78
|
+
if self.body is not None:
|
|
79
|
+
IncomingBody.finish(self.body)
|
|
80
|
+
self.body = None
|
|
81
|
+
else:
|
|
82
|
+
raise e
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
class Sink:
|
|
86
|
+
"""Writer abstraction over `wasi:http/types#outgoing-body`."""
|
|
87
|
+
|
|
88
|
+
def __init__(self, body: OutgoingBody):
|
|
89
|
+
self.body = body
|
|
90
|
+
self.stream = body.write()
|
|
91
|
+
|
|
92
|
+
async def send(self, chunk: bytes):
|
|
93
|
+
"""Write the specified bytes to the sink.
|
|
94
|
+
|
|
95
|
+
This may need to yield according to the backpressure requirements of the sink.
|
|
96
|
+
"""
|
|
97
|
+
offset = 0
|
|
98
|
+
flushing = False
|
|
99
|
+
while True:
|
|
100
|
+
count = self.stream.check_write()
|
|
101
|
+
if count == 0:
|
|
102
|
+
await register(
|
|
103
|
+
cast(PollLoop, asyncio.get_event_loop()), self.stream.subscribe()
|
|
104
|
+
)
|
|
105
|
+
elif offset == len(chunk):
|
|
106
|
+
if flushing:
|
|
107
|
+
return
|
|
108
|
+
else:
|
|
109
|
+
self.stream.flush()
|
|
110
|
+
flushing = True
|
|
111
|
+
else:
|
|
112
|
+
count = min(count, len(chunk) - offset)
|
|
113
|
+
self.stream.write(chunk[offset : offset + count])
|
|
114
|
+
offset += count
|
|
115
|
+
|
|
116
|
+
def close(self):
|
|
117
|
+
"""Close the stream, indicating no further data will be written."""
|
|
118
|
+
|
|
119
|
+
self.stream.__exit__(None, None, None)
|
|
120
|
+
self.stream = None
|
|
121
|
+
OutgoingBody.finish(self.body, None)
|
|
122
|
+
self.body = None
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
class PollLoop(asyncio.AbstractEventLoop):
|
|
126
|
+
"""Custom `asyncio` event loop backed by `wasi:io/poll#poll`."""
|
|
127
|
+
|
|
128
|
+
def __init__(self):
|
|
129
|
+
self.wakers = []
|
|
130
|
+
self.running = False
|
|
131
|
+
self.handles = []
|
|
132
|
+
self.exception = None
|
|
133
|
+
|
|
134
|
+
def get_debug(self):
|
|
135
|
+
return False
|
|
136
|
+
|
|
137
|
+
def run_until_complete(self, future):
|
|
138
|
+
future = asyncio.ensure_future(future, loop=self)
|
|
139
|
+
|
|
140
|
+
self.running = True
|
|
141
|
+
asyncio.events._set_running_loop(self)
|
|
142
|
+
while self.running and not future.done():
|
|
143
|
+
handles = self.handles
|
|
144
|
+
self.handles = []
|
|
145
|
+
for handle in handles:
|
|
146
|
+
if not handle._cancelled:
|
|
147
|
+
handle._run()
|
|
148
|
+
|
|
149
|
+
if self.wakers:
|
|
150
|
+
[pollables, wakers] = list(map(list, zip(*self.wakers)))
|
|
151
|
+
|
|
152
|
+
new_wakers = []
|
|
153
|
+
ready = [False] * len(pollables)
|
|
154
|
+
for index in poll.poll(pollables):
|
|
155
|
+
ready[index] = True
|
|
156
|
+
|
|
157
|
+
for (ready, pollable), waker in zip(zip(ready, pollables), wakers):
|
|
158
|
+
if ready:
|
|
159
|
+
pollable.__exit__(None, None, None)
|
|
160
|
+
waker.set_result(None)
|
|
161
|
+
else:
|
|
162
|
+
new_wakers.append((pollable, waker))
|
|
163
|
+
|
|
164
|
+
self.wakers = new_wakers
|
|
165
|
+
|
|
166
|
+
if self.exception is not None:
|
|
167
|
+
raise self.exception
|
|
168
|
+
|
|
169
|
+
return future.result()
|
|
170
|
+
|
|
171
|
+
def is_running(self):
|
|
172
|
+
return self.running
|
|
173
|
+
|
|
174
|
+
def is_closed(self):
|
|
175
|
+
return not self.running
|
|
176
|
+
|
|
177
|
+
def stop(self):
|
|
178
|
+
self.running = False
|
|
179
|
+
|
|
180
|
+
def close(self):
|
|
181
|
+
self.running = False
|
|
182
|
+
|
|
183
|
+
def shutdown_asyncgens(self):
|
|
184
|
+
pass
|
|
185
|
+
|
|
186
|
+
def call_exception_handler(self, context):
|
|
187
|
+
self.exception = context.get("exception", None)
|
|
188
|
+
|
|
189
|
+
def call_soon(self, callback, *args, context=None):
|
|
190
|
+
handle = asyncio.Handle(callback, args, self, context)
|
|
191
|
+
self.handles.append(handle)
|
|
192
|
+
return handle
|
|
193
|
+
|
|
194
|
+
def create_task(self, coroutine):
|
|
195
|
+
return asyncio.Task(coroutine, loop=self)
|
|
196
|
+
|
|
197
|
+
def create_future(self):
|
|
198
|
+
return asyncio.Future(loop=self)
|
|
199
|
+
|
|
200
|
+
# The remaining methods should be irrelevant for our purposes and thus unimplemented
|
|
201
|
+
|
|
202
|
+
def run_forever(self):
|
|
203
|
+
raise NotImplementedError
|
|
204
|
+
|
|
205
|
+
async def shutdown_default_executor(self):
|
|
206
|
+
raise NotImplementedError
|
|
207
|
+
|
|
208
|
+
def _timer_handle_cancelled(self, handle):
|
|
209
|
+
raise NotImplementedError
|
|
210
|
+
|
|
211
|
+
def call_later(self, delay, callback, *args, context=None):
|
|
212
|
+
raise NotImplementedError
|
|
213
|
+
|
|
214
|
+
def call_at(self, when, callback, *args, context=None):
|
|
215
|
+
raise NotImplementedError
|
|
216
|
+
|
|
217
|
+
def time(self):
|
|
218
|
+
raise NotImplementedError
|
|
219
|
+
|
|
220
|
+
def call_soon_threadsafe(self, callback, *args, context=None):
|
|
221
|
+
raise NotImplementedError
|
|
222
|
+
|
|
223
|
+
def run_in_executor(self, executor, func, *args):
|
|
224
|
+
raise NotImplementedError
|
|
225
|
+
|
|
226
|
+
def set_default_executor(self, executor):
|
|
227
|
+
raise NotImplementedError
|
|
228
|
+
|
|
229
|
+
async def getaddrinfo(self, host, port, *, family=0, type=0, proto=0, flags=0):
|
|
230
|
+
raise NotImplementedError
|
|
231
|
+
|
|
232
|
+
async def getnameinfo(self, sockaddr, flags=0):
|
|
233
|
+
raise NotImplementedError
|
|
234
|
+
|
|
235
|
+
async def create_connection(
|
|
236
|
+
self,
|
|
237
|
+
protocol_factory,
|
|
238
|
+
host=None,
|
|
239
|
+
port=None,
|
|
240
|
+
*,
|
|
241
|
+
ssl=None,
|
|
242
|
+
family=0,
|
|
243
|
+
proto=0,
|
|
244
|
+
flags=0,
|
|
245
|
+
sock=None,
|
|
246
|
+
local_addr=None,
|
|
247
|
+
server_hostname=None,
|
|
248
|
+
ssl_handshake_timeout=None,
|
|
249
|
+
ssl_shutdown_timeout=None,
|
|
250
|
+
happy_eyeballs_delay=None,
|
|
251
|
+
interleave=None,
|
|
252
|
+
):
|
|
253
|
+
raise NotImplementedError
|
|
254
|
+
|
|
255
|
+
async def create_server(
|
|
256
|
+
self,
|
|
257
|
+
protocol_factory,
|
|
258
|
+
host=None,
|
|
259
|
+
port=None,
|
|
260
|
+
*,
|
|
261
|
+
family=socket.AF_UNSPEC,
|
|
262
|
+
flags=socket.AI_PASSIVE,
|
|
263
|
+
sock=None,
|
|
264
|
+
backlog=100,
|
|
265
|
+
ssl=None,
|
|
266
|
+
reuse_address=None,
|
|
267
|
+
reuse_port=None,
|
|
268
|
+
ssl_handshake_timeout=None,
|
|
269
|
+
ssl_shutdown_timeout=None,
|
|
270
|
+
start_serving=True,
|
|
271
|
+
):
|
|
272
|
+
raise NotImplementedError
|
|
273
|
+
|
|
274
|
+
async def sendfile(self, transport, file, offset=0, count=None, *, fallback=True):
|
|
275
|
+
raise NotImplementedError
|
|
276
|
+
|
|
277
|
+
async def start_tls(
|
|
278
|
+
self,
|
|
279
|
+
transport,
|
|
280
|
+
protocol,
|
|
281
|
+
sslcontext,
|
|
282
|
+
*,
|
|
283
|
+
server_side=False,
|
|
284
|
+
server_hostname=None,
|
|
285
|
+
ssl_handshake_timeout=None,
|
|
286
|
+
ssl_shutdown_timeout=None,
|
|
287
|
+
):
|
|
288
|
+
raise NotImplementedError
|
|
289
|
+
|
|
290
|
+
async def create_unix_connection(
|
|
291
|
+
self,
|
|
292
|
+
protocol_factory,
|
|
293
|
+
path=None,
|
|
294
|
+
*,
|
|
295
|
+
ssl=None,
|
|
296
|
+
sock=None,
|
|
297
|
+
server_hostname=None,
|
|
298
|
+
ssl_handshake_timeout=None,
|
|
299
|
+
ssl_shutdown_timeout=None,
|
|
300
|
+
):
|
|
301
|
+
raise NotImplementedError
|
|
302
|
+
|
|
303
|
+
async def create_unix_server(
|
|
304
|
+
self,
|
|
305
|
+
protocol_factory,
|
|
306
|
+
path=None,
|
|
307
|
+
*,
|
|
308
|
+
sock=None,
|
|
309
|
+
backlog=100,
|
|
310
|
+
ssl=None,
|
|
311
|
+
ssl_handshake_timeout=None,
|
|
312
|
+
ssl_shutdown_timeout=None,
|
|
313
|
+
start_serving=True,
|
|
314
|
+
):
|
|
315
|
+
raise NotImplementedError
|
|
316
|
+
|
|
317
|
+
async def connect_accepted_socket(
|
|
318
|
+
self,
|
|
319
|
+
protocol_factory,
|
|
320
|
+
sock,
|
|
321
|
+
*,
|
|
322
|
+
ssl=None,
|
|
323
|
+
ssl_handshake_timeout=None,
|
|
324
|
+
ssl_shutdown_timeout=None,
|
|
325
|
+
):
|
|
326
|
+
raise NotImplementedError
|
|
327
|
+
|
|
328
|
+
async def create_datagram_endpoint(
|
|
329
|
+
self,
|
|
330
|
+
protocol_factory,
|
|
331
|
+
local_addr=None,
|
|
332
|
+
remote_addr=None,
|
|
333
|
+
*,
|
|
334
|
+
family=0,
|
|
335
|
+
proto=0,
|
|
336
|
+
flags=0,
|
|
337
|
+
reuse_address=None,
|
|
338
|
+
reuse_port=None,
|
|
339
|
+
allow_broadcast=None,
|
|
340
|
+
sock=None,
|
|
341
|
+
):
|
|
342
|
+
raise NotImplementedError
|
|
343
|
+
|
|
344
|
+
async def connect_read_pipe(self, protocol_factory, pipe):
|
|
345
|
+
raise NotImplementedError
|
|
346
|
+
|
|
347
|
+
async def connect_write_pipe(self, protocol_factory, pipe):
|
|
348
|
+
raise NotImplementedError
|
|
349
|
+
|
|
350
|
+
async def subprocess_shell(
|
|
351
|
+
self,
|
|
352
|
+
protocol_factory,
|
|
353
|
+
cmd,
|
|
354
|
+
*,
|
|
355
|
+
stdin=subprocess.PIPE,
|
|
356
|
+
stdout=subprocess.PIPE,
|
|
357
|
+
stderr=subprocess.PIPE,
|
|
358
|
+
**kwargs,
|
|
359
|
+
):
|
|
360
|
+
raise NotImplementedError
|
|
361
|
+
|
|
362
|
+
async def subprocess_exec(
|
|
363
|
+
self,
|
|
364
|
+
protocol_factory,
|
|
365
|
+
*args,
|
|
366
|
+
stdin=subprocess.PIPE,
|
|
367
|
+
stdout=subprocess.PIPE,
|
|
368
|
+
stderr=subprocess.PIPE,
|
|
369
|
+
**kwargs,
|
|
370
|
+
):
|
|
371
|
+
raise NotImplementedError
|
|
372
|
+
|
|
373
|
+
def add_reader(self, fd, callback, *args):
|
|
374
|
+
raise NotImplementedError
|
|
375
|
+
|
|
376
|
+
def remove_reader(self, fd):
|
|
377
|
+
raise NotImplementedError
|
|
378
|
+
|
|
379
|
+
def add_writer(self, fd, callback, *args):
|
|
380
|
+
raise NotImplementedError
|
|
381
|
+
|
|
382
|
+
def remove_writer(self, fd):
|
|
383
|
+
raise NotImplementedError
|
|
384
|
+
|
|
385
|
+
async def sock_recv(self, sock, nbytes):
|
|
386
|
+
raise NotImplementedError
|
|
387
|
+
|
|
388
|
+
async def sock_recv_into(self, sock, buf):
|
|
389
|
+
raise NotImplementedError
|
|
390
|
+
|
|
391
|
+
async def sock_recvfrom(self, sock, bufsize):
|
|
392
|
+
raise NotImplementedError
|
|
393
|
+
|
|
394
|
+
async def sock_recvfrom_into(self, sock, buf, nbytes=0):
|
|
395
|
+
raise NotImplementedError
|
|
396
|
+
|
|
397
|
+
async def sock_sendall(self, sock, data):
|
|
398
|
+
raise NotImplementedError
|
|
399
|
+
|
|
400
|
+
async def sock_sendto(self, sock, data, address):
|
|
401
|
+
raise NotImplementedError
|
|
402
|
+
|
|
403
|
+
async def sock_connect(self, sock, address):
|
|
404
|
+
raise NotImplementedError
|
|
405
|
+
|
|
406
|
+
async def sock_accept(self, sock):
|
|
407
|
+
raise NotImplementedError
|
|
408
|
+
|
|
409
|
+
async def sock_sendfile(self, sock, file, offset=0, count=None, *, fallback=None):
|
|
410
|
+
raise NotImplementedError
|
|
411
|
+
|
|
412
|
+
def add_signal_handler(self, sig, callback, *args):
|
|
413
|
+
raise NotImplementedError
|
|
414
|
+
|
|
415
|
+
def remove_signal_handler(self, sig):
|
|
416
|
+
raise NotImplementedError
|
|
417
|
+
|
|
418
|
+
def set_task_factory(self, factory):
|
|
419
|
+
raise NotImplementedError
|
|
420
|
+
|
|
421
|
+
def get_task_factory(self):
|
|
422
|
+
raise NotImplementedError
|
|
423
|
+
|
|
424
|
+
def get_exception_handler(self):
|
|
425
|
+
raise NotImplementedError
|
|
426
|
+
|
|
427
|
+
def set_exception_handler(self, handler):
|
|
428
|
+
raise NotImplementedError
|
|
429
|
+
|
|
430
|
+
def default_exception_handler(self, context):
|
|
431
|
+
raise NotImplementedError
|
|
432
|
+
|
|
433
|
+
def set_debug(self, enabled):
|
|
434
|
+
raise NotImplementedError
|
|
435
|
+
|
|
436
|
+
|
|
437
|
+
async def register(loop: PollLoop, pollable: Pollable):
|
|
438
|
+
waker = loop.create_future()
|
|
439
|
+
loop.wakers.append((pollable, waker))
|
|
440
|
+
await waker
|
pumpkin_api/__init__.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
from wit_world.exports import metadata
|
|
2
|
+
from wit_world.imports import (
|
|
3
|
+
block_entity,
|
|
4
|
+
command,
|
|
5
|
+
common,
|
|
6
|
+
context,
|
|
7
|
+
event,
|
|
8
|
+
gui,
|
|
9
|
+
i18n,
|
|
10
|
+
logging,
|
|
11
|
+
permission,
|
|
12
|
+
player,
|
|
13
|
+
scheduler,
|
|
14
|
+
scoreboard,
|
|
15
|
+
server,
|
|
16
|
+
text,
|
|
17
|
+
world,
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
from .impl import Plugin, register_plugin
|
|
21
|
+
|
|
22
|
+
__all__ = [
|
|
23
|
+
"Plugin",
|
|
24
|
+
"register_plugin",
|
|
25
|
+
"block_entity",
|
|
26
|
+
"command",
|
|
27
|
+
"common",
|
|
28
|
+
"context",
|
|
29
|
+
"event",
|
|
30
|
+
"gui",
|
|
31
|
+
"i18n",
|
|
32
|
+
"logging",
|
|
33
|
+
"metadata",
|
|
34
|
+
"permission",
|
|
35
|
+
"player",
|
|
36
|
+
"scheduler",
|
|
37
|
+
"server",
|
|
38
|
+
"scoreboard",
|
|
39
|
+
"text",
|
|
40
|
+
"world",
|
|
41
|
+
]
|
pumpkin_api/build.py
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
import os
|
|
3
|
+
import tempfile
|
|
4
|
+
|
|
5
|
+
import componentize_py
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def _build_entrypoint_wrapper(app_module: str, wrapper_dir: str) -> str:
|
|
9
|
+
wrapper_name = "_pumpkin_componentize_entry"
|
|
10
|
+
wrapper_path = os.path.join(wrapper_dir, f"{wrapper_name}.py")
|
|
11
|
+
|
|
12
|
+
with open(wrapper_path, "w", encoding="utf-8") as wrapper_file:
|
|
13
|
+
wrapper_file.write(
|
|
14
|
+
"from pathlib import Path\n"
|
|
15
|
+
"from pumpkin_api.impl import MetadataImpl, WitWorldImpl\n\n"
|
|
16
|
+
"WitWorld = WitWorldImpl\n"
|
|
17
|
+
"Metadata = MetadataImpl\n\n"
|
|
18
|
+
f"import {app_module}\n"
|
|
19
|
+
)
|
|
20
|
+
return wrapper_name
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def main():
|
|
24
|
+
parser = argparse.ArgumentParser(description="Build a Pumpkin Python plugin")
|
|
25
|
+
parser.add_argument(
|
|
26
|
+
"app_module", help="The python module containing the plugin (e.g. 'main')"
|
|
27
|
+
)
|
|
28
|
+
parser.add_argument(
|
|
29
|
+
"-o", "--output", default="plugin.wasm", help="Output wasm file name"
|
|
30
|
+
)
|
|
31
|
+
args = parser.parse_args()
|
|
32
|
+
|
|
33
|
+
import pumpkin_api
|
|
34
|
+
|
|
35
|
+
pkg_dir = os.path.dirname(pumpkin_api.__file__)
|
|
36
|
+
# In source checkout, they are in wit_files/repo/...
|
|
37
|
+
# In installed package, they are directly in wit_files/
|
|
38
|
+
wit_dir = os.path.join(pkg_dir, "..", "..", "wit", "v0.1")
|
|
39
|
+
if not os.path.exists(wit_dir):
|
|
40
|
+
wit_dir = os.path.join(pkg_dir, "wit")
|
|
41
|
+
|
|
42
|
+
# Pass the parent directory of pumpkin_api to componentize-py so it can resolve `pumpkin_api` module
|
|
43
|
+
# in case it's not installed in a standard site-packages (e.g. editable install or no venv)
|
|
44
|
+
pkg_parent_dir = os.path.dirname(pkg_dir)
|
|
45
|
+
|
|
46
|
+
with tempfile.TemporaryDirectory(prefix="pumpkin-api-build-") as wrapper_dir:
|
|
47
|
+
wrapper_module = _build_entrypoint_wrapper(args.app_module, wrapper_dir)
|
|
48
|
+
|
|
49
|
+
componentize_py.componentize(
|
|
50
|
+
wit_path=[wit_dir],
|
|
51
|
+
worlds=[],
|
|
52
|
+
features=[],
|
|
53
|
+
all_features=False,
|
|
54
|
+
world_module="wit_world",
|
|
55
|
+
python_path=[".", pkg_parent_dir, wrapper_dir],
|
|
56
|
+
module_worlds=[],
|
|
57
|
+
app_name=wrapper_module,
|
|
58
|
+
output_path=args.output,
|
|
59
|
+
stub_wasi=False,
|
|
60
|
+
import_interface_names=[],
|
|
61
|
+
export_interface_names=[],
|
|
62
|
+
full_names=False,
|
|
63
|
+
intersect_world=None,
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
if __name__ == "__main__":
|
|
68
|
+
main()
|