forked from pygame-web/pygbag
-
Notifications
You must be signed in to change notification settings - Fork 1
/
__init__.py
86 lines (53 loc) · 1.5 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
""" packager+server for pygbag wasm loader """
" ^(⌒(oo)⌒)^ "
import sys
# some Linux distro are stuck in the past. Better safe than sorry
sys.stdout.reconfigure(encoding="utf-8")
from pathlib import Path
VERSION = "0.8.7"
# hack to test git cdn build without upgrading pygbag
# beware can have side effects when file packager behaviour must change !
if "--git" in sys.argv:
print(
"""
******* forcing git cdn *********
"""
)
VERSION = "0.0.0"
# make aio available
sys.path.append(str(Path(__file__).parent / "support/cross"))
# WaPy<=>CPython compat
import builtins
try:
# embed builtin module handles I/O on wasm
import embed
# aio function implemented only on stackless WaPy
sched_yield
except:
builtins.sched_yield = lambda: None
import sys, traceback
if not hasattr(sys, "print_exception"):
def print_exception(e, out=sys.stderr, **kw):
kw["file"] = out
traceback.print_exc(**kw)
sys.print_exception = print_exception
def iter_byte(ba):
for idx in range(len(ba)):
yield bytes([ba[idx]])
builtins.iter_byte = iter_byte
def iter_ord(ba):
for idx in range(len(ba)):
yield ba[idx]
builtins.iter_ord = iter_ord
def ESC(*argv, flush=True):
for arg in argv:
sys.__stdout__.write(chr(0x1B))
sys.__stdout__.write(arg)
if flush:
sys.stdout.flush()
def CSI(*argv):
for arg in argv:
ESC(f"[{arg}", flush=False)
sys.stdout.flush()
builtins.CSI = CSI
builtins.ESC = ESC