pret 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.
- pret/__init__.py +38 -0
- pret/bridge.py +154 -0
- pret/cli/__init__.py +17 -0
- pret/cli/generate-py-stubs.js +509 -0
- pret/cli/prepack_command.py +48 -0
- pret/cli/stub_command.py +47 -0
- pret/cli/yarn-error.log +37 -0
- pret/hooks.py +333 -0
- pret/ipython_var_cleaner.py +62 -0
- pret/js-base/bundle.482c35a517080d4d8635.js +1 -0
- pret/js-base/index.html +8 -0
- pret/js-extension/package.json +80 -0
- pret/js-extension/schemas/pret/package.json.orig +76 -0
- pret/js-extension/schemas/pret/pret.json +7 -0
- pret/js-extension/static/687.0062096d9d29918ac9a0.js +1 -0
- pret/js-extension/static/688.46e0549bfc4eb41831e6.js +1 -0
- pret/js-extension/static/831.640951c39f6ddba8b75d.js +2 -0
- pret/js-extension/static/831.640951c39f6ddba8b75d.js.LICENSE.txt +24 -0
- pret/js-extension/static/894.177c58227d3572a8d420.js +1 -0
- pret/js-extension/static/remoteEntry.d35e72562dbac07e4f10.js +1 -0
- pret/js-extension/static/style.js +4 -0
- pret/js-extension/static/third-party-licenses.json +52 -0
- pret/main.py +349 -0
- pret/manager.py +367 -0
- pret/render.py +298 -0
- pret/serialize.py +627 -0
- pret/serve.py +83 -0
- pret/settings.py +16 -0
- pret/state.py +774 -0
- pret/ui/react.py +42336 -0
- pret/webpack.standalone.js +69 -0
- pret-0.1.0.data/data/share/jupyter/labextensions/pret/package.json +80 -0
- pret-0.1.0.data/data/share/jupyter/labextensions/pret/schemas/pret/package.json.orig +76 -0
- pret-0.1.0.data/data/share/jupyter/labextensions/pret/schemas/pret/pret.json +7 -0
- pret-0.1.0.data/data/share/jupyter/labextensions/pret/static/687.0062096d9d29918ac9a0.js +1 -0
- pret-0.1.0.data/data/share/jupyter/labextensions/pret/static/688.46e0549bfc4eb41831e6.js +1 -0
- pret-0.1.0.data/data/share/jupyter/labextensions/pret/static/831.640951c39f6ddba8b75d.js +2 -0
- pret-0.1.0.data/data/share/jupyter/labextensions/pret/static/831.640951c39f6ddba8b75d.js.LICENSE.txt +24 -0
- pret-0.1.0.data/data/share/jupyter/labextensions/pret/static/894.177c58227d3572a8d420.js +1 -0
- pret-0.1.0.data/data/share/jupyter/labextensions/pret/static/remoteEntry.d35e72562dbac07e4f10.js +1 -0
- pret-0.1.0.data/data/share/jupyter/labextensions/pret/static/style.js +4 -0
- pret-0.1.0.data/data/share/jupyter/labextensions/pret/static/third-party-licenses.json +52 -0
- pret-0.1.0.dist-info/METADATA +408 -0
- pret-0.1.0.dist-info/RECORD +47 -0
- pret-0.1.0.dist-info/WHEEL +4 -0
- pret-0.1.0.dist-info/entry_points.txt +8 -0
- pret-0.1.0.dist-info/licenses/LICENSE +201 -0
pret/__init__.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import pkgutil
|
|
2
|
+
|
|
3
|
+
__path__ = pkgutil.extend_path(__path__, __name__)
|
|
4
|
+
|
|
5
|
+
from . import ipython_var_cleaner # noqa: F401
|
|
6
|
+
from .bridge import js, pyodide
|
|
7
|
+
from .main import run
|
|
8
|
+
from .render import component, server_only
|
|
9
|
+
from .state import proxy
|
|
10
|
+
from .hooks import (
|
|
11
|
+
use_callback,
|
|
12
|
+
use_effect,
|
|
13
|
+
use_memo,
|
|
14
|
+
use_ref,
|
|
15
|
+
use_state,
|
|
16
|
+
use_tracked,
|
|
17
|
+
use_body_style,
|
|
18
|
+
use_event_callback,
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
__version__ = "0.1.0"
|
|
22
|
+
|
|
23
|
+
__all__ = [
|
|
24
|
+
"component",
|
|
25
|
+
"js",
|
|
26
|
+
"proxy",
|
|
27
|
+
"pyodide",
|
|
28
|
+
"run",
|
|
29
|
+
"server_only",
|
|
30
|
+
"use_callback",
|
|
31
|
+
"use_effect",
|
|
32
|
+
"use_memo",
|
|
33
|
+
"use_ref",
|
|
34
|
+
"use_state",
|
|
35
|
+
"use_tracked",
|
|
36
|
+
"use_body_style",
|
|
37
|
+
"use_event_callback",
|
|
38
|
+
]
|
pret/bridge.py
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
import functools
|
|
3
|
+
import sys
|
|
4
|
+
import weakref
|
|
5
|
+
from types import ModuleType
|
|
6
|
+
from weakref import WeakKeyDictionary
|
|
7
|
+
|
|
8
|
+
from pret.serialize import GlobalRef, pickle_as
|
|
9
|
+
|
|
10
|
+
js = ModuleType("js", None)
|
|
11
|
+
pyodide = ModuleType("pyodide", None)
|
|
12
|
+
sys.modules["js"] = js
|
|
13
|
+
sys.modules["pyodide"] = pyodide
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
weak_cache = weakref.WeakKeyDictionary()
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def weak_cached(fn):
|
|
20
|
+
# run pyodide.ffi.to_js(obj, **kwargs) or use a weak cache
|
|
21
|
+
# if obj is weakrefable
|
|
22
|
+
def wrapped(obj):
|
|
23
|
+
try:
|
|
24
|
+
value = weak_cache[obj]
|
|
25
|
+
except TypeError:
|
|
26
|
+
value = fn(obj)
|
|
27
|
+
except KeyError:
|
|
28
|
+
value = fn(obj)
|
|
29
|
+
try:
|
|
30
|
+
weak_cache[obj] = value
|
|
31
|
+
except TypeError:
|
|
32
|
+
pass
|
|
33
|
+
return value
|
|
34
|
+
|
|
35
|
+
return wrapped
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
@weak_cached
|
|
39
|
+
def cached_create_proxy(obj):
|
|
40
|
+
if isinstance(obj, (int, float, str, bool)) or obj is None:
|
|
41
|
+
return obj
|
|
42
|
+
return pyodide.ffi.create_proxy(obj)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
@weak_cached
|
|
46
|
+
def cached_deep_to_js(obj):
|
|
47
|
+
return pyodide.ffi.to_js(obj, depth=-1)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def make_create_proxy():
|
|
51
|
+
weak_references = WeakKeyDictionary()
|
|
52
|
+
|
|
53
|
+
def create_proxy_client(x, wrap_in_browser=None, _=None):
|
|
54
|
+
try:
|
|
55
|
+
res = weak_references[x]
|
|
56
|
+
except KeyError:
|
|
57
|
+
res = pyodide.ffi.create_proxy(x)
|
|
58
|
+
if wrap_in_browser is not None:
|
|
59
|
+
res = wrap_in_browser(res)
|
|
60
|
+
weak_references[x] = res
|
|
61
|
+
except TypeError:
|
|
62
|
+
res = pyodide.ffi.create_proxy(x)
|
|
63
|
+
if wrap_in_browser is not None:
|
|
64
|
+
res = wrap_in_browser(res)
|
|
65
|
+
|
|
66
|
+
return res
|
|
67
|
+
|
|
68
|
+
@pickle_as(create_proxy_client)
|
|
69
|
+
class UnpickleAsProxy:
|
|
70
|
+
def __init__(self, obj, wrap_in_browser=None, proxy_list=None):
|
|
71
|
+
assert proxy_list is None, (
|
|
72
|
+
"proxy_list is only supported in the browser, "
|
|
73
|
+
"i.e. inside your components"
|
|
74
|
+
)
|
|
75
|
+
self.obj = obj
|
|
76
|
+
self.wrap_in_browser = wrap_in_browser
|
|
77
|
+
|
|
78
|
+
def __reduce__(self):
|
|
79
|
+
return create_proxy_client, (self.obj, self.wrap_in_browser)
|
|
80
|
+
|
|
81
|
+
return UnpickleAsProxy
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def make_to_js():
|
|
85
|
+
weak_references = WeakKeyDictionary()
|
|
86
|
+
|
|
87
|
+
def to_js(x, wrap=False, **kwargs):
|
|
88
|
+
key = x
|
|
89
|
+
if wrap:
|
|
90
|
+
x = {"wrapped": x}
|
|
91
|
+
kwargs["depth"] = 1
|
|
92
|
+
try:
|
|
93
|
+
res = weak_references[key]
|
|
94
|
+
except KeyError:
|
|
95
|
+
res = pyodide.ffi.to_js(x, **kwargs)
|
|
96
|
+
weak_references[key] = res
|
|
97
|
+
except TypeError:
|
|
98
|
+
return pyodide.ffi.to_js(x, **kwargs)
|
|
99
|
+
|
|
100
|
+
return res
|
|
101
|
+
|
|
102
|
+
return to_js
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def auto_start_async(coro_func):
|
|
106
|
+
if coro_func is None:
|
|
107
|
+
return
|
|
108
|
+
|
|
109
|
+
@functools.wraps(coro_func)
|
|
110
|
+
def wrapper(*args, **kwargs):
|
|
111
|
+
loop = asyncio.get_event_loop()
|
|
112
|
+
task = loop.create_task(coro_func(*args, **kwargs))
|
|
113
|
+
return task
|
|
114
|
+
|
|
115
|
+
return wrapper
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def make_stub_js_module(
|
|
119
|
+
global_name,
|
|
120
|
+
py_package_name,
|
|
121
|
+
js_package_name,
|
|
122
|
+
package_version,
|
|
123
|
+
stub_qualified_name,
|
|
124
|
+
):
|
|
125
|
+
if sys.platform == "emscripten":
|
|
126
|
+
# running in Pyodide or other Emscripten based build
|
|
127
|
+
return
|
|
128
|
+
# Makes a dummy module with __name__ set to the module name
|
|
129
|
+
# so that it can be pickled and unpickled
|
|
130
|
+
full_global_name = "js." + global_name
|
|
131
|
+
|
|
132
|
+
def make_stub_js_function(name):
|
|
133
|
+
# Makes a dummy function with __module__ set to the module name
|
|
134
|
+
# so that it can be pickled and unpickled
|
|
135
|
+
ref = GlobalRef(module, name)
|
|
136
|
+
setattr(module, name, ref)
|
|
137
|
+
return ref
|
|
138
|
+
|
|
139
|
+
module = ModuleType(
|
|
140
|
+
full_global_name, f"Fake server side js module for {global_name}"
|
|
141
|
+
)
|
|
142
|
+
module.__file__ = f"<{full_global_name}>"
|
|
143
|
+
module.__getattr__ = make_stub_js_function
|
|
144
|
+
module._js_package_name = js_package_name
|
|
145
|
+
module._package_name = py_package_name
|
|
146
|
+
module._package_version = package_version
|
|
147
|
+
module._stub_qualified_name = stub_qualified_name
|
|
148
|
+
sys.modules[module.__name__] = module
|
|
149
|
+
setattr(js, global_name, module)
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
create_proxy = make_create_proxy()
|
|
153
|
+
|
|
154
|
+
to_js = make_to_js()
|
pret/cli/__init__.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import typer
|
|
2
|
+
|
|
3
|
+
from .stub_command import stub
|
|
4
|
+
from .prepack_command import prepack
|
|
5
|
+
|
|
6
|
+
app = typer.Typer()
|
|
7
|
+
app.command(name="stub")(stub)
|
|
8
|
+
app.command(name="prepack")(prepack)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@app.callback()
|
|
12
|
+
def callback():
|
|
13
|
+
pass
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
if __name__ == "__main__":
|
|
17
|
+
app()
|