pyjs 0.0.2__tar.gz → 0.3.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.
- {pyjs-0.0.2 → pyjs-0.3.0}/PKG-INFO +29 -2
- {pyjs-0.0.2 → pyjs-0.3.0}/README.md +24 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/__init__.py +2 -2
- pyjs-0.3.0/pyjs/decorators.py +396 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/docs/ui.py +4 -6
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/javascript.py +67 -28
- pyjs-0.3.0/pyjs/lib/__init__.py +1 -0
- pyjs-0.3.0/pyjs/lib/pydantic/__init__.py +1 -0
- pyjs-0.3.0/pyjs/lib/pydantic/v2.py +199 -0
- pyjs-0.3.0/pyjs/nativescript/__init__.py +475 -0
- pyjs-0.3.0/pyjs/nativescript/collectionview.py +104 -0
- pyjs-0.3.0/pyjs/nativescript/keyboard.py +52 -0
- pyjs-0.3.0/pyjs/nativescript/masonry.py +399 -0
- pyjs-0.3.0/pyjs/nativescript/reorderable.py +293 -0
- pyjs-0.3.0/pyjs/nativescript/simulator.py +944 -0
- pyjs-0.3.0/pyjs/nativescript/transport.py +40 -0
- pyjs-0.3.0/pyjs/python.py +2225 -0
- pyjs-0.3.0/pyjs/server/__init__.py +1401 -0
- pyjs-0.3.0/pyjs/server/django/__init__.py +16 -0
- pyjs-0.3.0/pyjs/server/django/api.py +136 -0
- pyjs-0.3.0/pyjs/server/django/application.py +182 -0
- pyjs-0.3.0/pyjs/server/django/jsonapi.py +277 -0
- pyjs-0.3.0/pyjs/server/django/live.py +381 -0
- pyjs-0.3.0/pyjs/server/django/model.py +172 -0
- pyjs-0.3.0/pyjs/server/django/queryset.py +29 -0
- pyjs-0.3.0/pyjs/server/errors.py +129 -0
- pyjs-0.3.0/pyjs/server/jsonapi.py +267 -0
- pyjs-0.3.0/pyjs/server/live.py +167 -0
- pyjs-0.3.0/pyjs/server/protocol.py +7 -0
- pyjs-0.3.0/pyjs/server/transport.py +68 -0
- pyjs-0.3.0/pyjs/server/watch.py +623 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/skills/pyjs/SKILL.md +7 -1
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/state.py +1 -1
- pyjs-0.3.0/pyjs/stdlib/__init__.py +1 -0
- pyjs-0.3.0/pyjs/stdlib/dataclasses.py +168 -0
- pyjs-0.3.0/pyjs/stdlib/math.py +92 -0
- pyjs-0.3.0/pyjs/stdlib/typing.py +10 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/testing/android.py +69 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/testing/builder.py +9 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/testing/client/app.py +36 -24
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/testing/client/assertions.py +2 -2
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/testing/client/runtime.py +6 -6
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/testing/client/sidebar.py +3 -1
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/testing/client/state.py +2 -9
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/testing/client/viewer.py +8 -8
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/testing/daemon.py +51 -37
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/testing/helpers.py +4 -1
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/testing/pytest_plugin.py +15 -23
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/testing/web.py +69 -11
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/tooling/browser.py +27 -18
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/tooling/nativescript.py +54 -5
- pyjs-0.3.0/pyjs/transpiler/analyzer.py +5694 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/transpiler/diagnostics.py +23 -1
- pyjs-0.3.0/pyjs/transpiler/libraries.py +182 -0
- pyjs-0.3.0/pyjs/transpiler/objects.py +2403 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/transpiler/source.py +62 -2
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/transpiler/transpiler.py +488 -62
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/transpiler/utils.py +23 -4
- pyjs-0.3.0/pyjs/ui/__init__.py +70 -0
- pyjs-0.3.0/pyjs/ui/gesture.py +161 -0
- pyjs-0.3.0/pyjs/ui/interaction.py +681 -0
- pyjs-0.3.0/pyjs/ui/reorder_trace.py +359 -0
- pyjs-0.3.0/pyjs/ui/reorderable.py +255 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/web/clipboard.py +7 -7
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/web/console.py +1 -1
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/web/crypto.py +9 -6
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/web/dom.py +122 -132
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/web/domx.py +27 -24
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/web/dragdrop.py +5 -5
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/web/encoding.py +4 -4
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/web/events.py +36 -32
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/web/files.py +8 -8
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/web/geometry.py +6 -6
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/web/html.py +180 -180
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/web/indexeddb.py +126 -60
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/web/network.py +16 -15
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/web/serviceworker.py +33 -31
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/web/ssr.py +10 -8
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/web/storage.py +4 -4
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/web/streams.py +14 -14
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/web/svg.py +70 -70
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/web/timers.py +7 -7
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/web/ui/accordion.py +4 -2
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/web/ui/calendar.py +3 -1
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/web/ui/combobox.py +3 -1
- pyjs-0.3.0/pyjs/web/ui/date.py +55 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/web/ui/dialog.py +4 -2
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/web/ui/dropdown_menu.py +6 -4
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/web/ui/hover_card.py +2 -2
- pyjs-0.3.0/pyjs/web/ui/model.py +923 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/web/ui/popover.py +7 -5
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/web/ui/radio_group.py +3 -1
- pyjs-0.3.0/pyjs/web/ui/reorderable.py +201 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/web/ui/resizable.py +6 -4
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/web/ui/sidebar.py +3 -1
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/web/ui/sonner.py +3 -1
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/web/ui/tabs.py +4 -2
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/web/ui/toggle.py +3 -1
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/web/ui/tooltip.py +2 -2
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/web/url.py +3 -3
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/web/webgpu.py +51 -51
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs.egg-info/PKG-INFO +29 -2
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs.egg-info/SOURCES.txt +36 -2
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs.egg-info/requires.txt +5 -1
- {pyjs-0.0.2 → pyjs-0.3.0}/pyproject.toml +7 -2
- pyjs-0.0.2/pyjs/decorators.py +0 -245
- pyjs-0.0.2/pyjs/nativescript/__init__.py +0 -77
- pyjs-0.0.2/pyjs/python.py +0 -185
- pyjs-0.0.2/pyjs/server.py +0 -577
- pyjs-0.0.2/pyjs/transpiler/_builtins.py +0 -899
- pyjs-0.0.2/pyjs/transpiler/analyzer.py +0 -2034
- pyjs-0.0.2/pyjs/transpiler/objects.py +0 -1289
- {pyjs-0.0.2 → pyjs-0.3.0}/LICENSE +0 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/__main__.py +0 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/cli.py +0 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/docs/__init__.py +0 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/docs/builder.py +0 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/docs/cli.py +0 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/docs/config.py +0 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/docs/favicon.svg +0 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/docs/markdown.py +0 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/docs/models.py +0 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/docs/navigation.py +0 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/docs/style.css +0 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/scaffolding/__init__.py +0 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/scaffolding/templates/app/README.md.template +0 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/scaffolding/templates/app/__PYJS_SOURCE_ROOT__/__PYJS_PACKAGE__/__PYJS_PACKAGE__.py.template +0 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/scaffolding/templates/app/__PYJS_SOURCE_ROOT__/__PYJS_PACKAGE__/__init__.py.template +0 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/scaffolding/templates/app/__PYJS_SOURCE_ROOT__/__PYJS_PACKAGE__/__main__.py.template +0 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/scaffolding/templates/app/tests/test_app.py.template +0 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/scaffolding/templates/app/tests/test_browser_app.py.template +0 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/scaffolding/templates/app_test.py.template +0 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/testing/__init__.py +0 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/testing/artifacts.py +0 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/testing/assertion_rewriter.py +0 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/testing/capture.py +0 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/testing/client/__init__.py +0 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/testing/protocol.py +0 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/testing/webgpu.py +0 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/tooling/__init__.py +0 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/tooling/android.py +0 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/tooling/command.py +0 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/tooling/node.py +0 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/tooling/perf.py +0 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/transpiler/__init__.py +0 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/web/__init__.py +0 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/web/navigation.py +0 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/web/ui/__init__.py +0 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/web/ui/alert.py +0 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/web/ui/alert_dialog.py +0 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/web/ui/aspect_ratio.py +0 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/web/ui/attachment.py +0 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/web/ui/avatar.py +0 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/web/ui/badge.py +0 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/web/ui/breadcrumb.py +0 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/web/ui/bubble.py +0 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/web/ui/button.py +0 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/web/ui/card.py +0 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/web/ui/carousel.py +0 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/web/ui/chart.py +0 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/web/ui/checkbox.py +0 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/web/ui/collapsible.py +0 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/web/ui/command.py +0 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/web/ui/context_menu.py +0 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/web/ui/date_picker.py +0 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/web/ui/direction.py +0 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/web/ui/drawer.py +0 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/web/ui/empty.py +0 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/web/ui/field.py +0 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/web/ui/floating.py +0 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/web/ui/input.py +0 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/web/ui/input_group.py +0 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/web/ui/input_otp.py +0 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/web/ui/item.py +0 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/web/ui/kbd.py +0 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/web/ui/label.py +0 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/web/ui/marker.py +0 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/web/ui/menubar.py +0 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/web/ui/message.py +0 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/web/ui/message_scroller.py +0 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/web/ui/native_select.py +0 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/web/ui/navigation_menu.py +0 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/web/ui/pagination.py +0 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/web/ui/progress.py +0 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/web/ui/scroll_area.py +0 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/web/ui/select.py +0 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/web/ui/separator.py +0 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/web/ui/sheet.py +0 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/web/ui/skeleton.py +0 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/web/ui/slider.py +0 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/web/ui/spinner.py +0 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/web/ui/switch.py +0 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/web/ui/table.py +0 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/web/ui/text.py +0 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/web/ui/textarea.py +0 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs/web/ui/typography.py +0 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs.egg-info/dependency_links.txt +0 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs.egg-info/entry_points.txt +0 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/pyjs.egg-info/top_level.txt +0 -0
- {pyjs-0.0.2 → pyjs-0.3.0}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pyjs
|
|
3
|
-
Version: 0.0
|
|
3
|
+
Version: 0.3.0
|
|
4
4
|
Summary: Python to JavaScript transpiler.
|
|
5
5
|
Author-email: Lex Berezhny <lex@damoti.com>
|
|
6
6
|
License-Expression: BSD-3-Clause
|
|
@@ -26,11 +26,14 @@ Description-Content-Type: text/markdown
|
|
|
26
26
|
License-File: LICENSE
|
|
27
27
|
Requires-Dist: markdown>=3.8
|
|
28
28
|
Requires-Dist: pillow
|
|
29
|
+
Requires-Dist: pydantic<3,>=2
|
|
29
30
|
Requires-Dist: pyyaml>=6.0
|
|
30
31
|
Requires-Dist: pytest
|
|
31
32
|
Requires-Dist: websockets
|
|
32
33
|
Provides-Extra: examples
|
|
33
|
-
Requires-Dist: pyjs-examples==0.0
|
|
34
|
+
Requires-Dist: pyjs-examples==0.3.0; extra == "examples"
|
|
35
|
+
Provides-Extra: django
|
|
36
|
+
Requires-Dist: django<6.2,>=6.0; extra == "django"
|
|
34
37
|
Dynamic: license-file
|
|
35
38
|
|
|
36
39
|
# PyJS: Python to JavaScript
|
|
@@ -291,6 +294,11 @@ The analyzer preserves concrete element and key/value types for built-in collect
|
|
|
291
294
|
`list[T]`, `dict[K, V]`, and `tuple[...]`. User-defined generic specialization exists in the
|
|
292
295
|
analyzer but remains experimental and is not yet a stable application-facing feature.
|
|
293
296
|
|
|
297
|
+
Typed tuples and lists can be unpacked into local names. Tuple and literal-list
|
|
298
|
+
arity is checked during compilation; dynamic lists retain Python's runtime
|
|
299
|
+
arity errors. Nested, starred, and chained unpacking targets are not yet
|
|
300
|
+
supported.
|
|
301
|
+
|
|
294
302
|
### Async code and exceptions
|
|
295
303
|
|
|
296
304
|
Async functions and `await` lower to JavaScript promises. Typed browser APIs such as `fetch()`,
|
|
@@ -390,6 +398,25 @@ preview, and render assertions can compare screenshots against checked-in PNG ba
|
|
|
390
398
|
The built-in application server is run from Python source with `serve(__file__)`; the generated
|
|
391
399
|
starter and examples already provide this entry point.
|
|
392
400
|
|
|
401
|
+
NativeScript projects can declare external npm modules without editing the
|
|
402
|
+
generated build directory:
|
|
403
|
+
|
|
404
|
+
```python
|
|
405
|
+
from pyjs.nativescript import NativeScriptModule
|
|
406
|
+
from pyjs.tooling.nativescript import NativeScriptProject
|
|
407
|
+
|
|
408
|
+
widgets = NativeScriptModule("@example/widgets", "1.2.3", ("Widget",))
|
|
409
|
+
project = NativeScriptProject(
|
|
410
|
+
main,
|
|
411
|
+
name="Example",
|
|
412
|
+
app_id="org.example.app",
|
|
413
|
+
modules=(widgets,),
|
|
414
|
+
)
|
|
415
|
+
```
|
|
416
|
+
|
|
417
|
+
PyJS installs the pinned package and emits its CommonJS imports before the
|
|
418
|
+
transpiled application bundle.
|
|
419
|
+
|
|
393
420
|
## Current limitations and missing features
|
|
394
421
|
|
|
395
422
|
PyJS is intentionally a typed subset of Python, and the current releases remain pre-alpha:
|
|
@@ -256,6 +256,11 @@ The analyzer preserves concrete element and key/value types for built-in collect
|
|
|
256
256
|
`list[T]`, `dict[K, V]`, and `tuple[...]`. User-defined generic specialization exists in the
|
|
257
257
|
analyzer but remains experimental and is not yet a stable application-facing feature.
|
|
258
258
|
|
|
259
|
+
Typed tuples and lists can be unpacked into local names. Tuple and literal-list
|
|
260
|
+
arity is checked during compilation; dynamic lists retain Python's runtime
|
|
261
|
+
arity errors. Nested, starred, and chained unpacking targets are not yet
|
|
262
|
+
supported.
|
|
263
|
+
|
|
259
264
|
### Async code and exceptions
|
|
260
265
|
|
|
261
266
|
Async functions and `await` lower to JavaScript promises. Typed browser APIs such as `fetch()`,
|
|
@@ -355,6 +360,25 @@ preview, and render assertions can compare screenshots against checked-in PNG ba
|
|
|
355
360
|
The built-in application server is run from Python source with `serve(__file__)`; the generated
|
|
356
361
|
starter and examples already provide this entry point.
|
|
357
362
|
|
|
363
|
+
NativeScript projects can declare external npm modules without editing the
|
|
364
|
+
generated build directory:
|
|
365
|
+
|
|
366
|
+
```python
|
|
367
|
+
from pyjs.nativescript import NativeScriptModule
|
|
368
|
+
from pyjs.tooling.nativescript import NativeScriptProject
|
|
369
|
+
|
|
370
|
+
widgets = NativeScriptModule("@example/widgets", "1.2.3", ("Widget",))
|
|
371
|
+
project = NativeScriptProject(
|
|
372
|
+
main,
|
|
373
|
+
name="Example",
|
|
374
|
+
app_id="org.example.app",
|
|
375
|
+
modules=(widgets,),
|
|
376
|
+
)
|
|
377
|
+
```
|
|
378
|
+
|
|
379
|
+
PyJS installs the pinned package and emits its CommonJS imports before the
|
|
380
|
+
transpiled application bundle.
|
|
381
|
+
|
|
358
382
|
## Current limitations and missing features
|
|
359
383
|
|
|
360
384
|
PyJS is intentionally a typed subset of Python, and the current releases remain pre-alpha:
|
|
@@ -0,0 +1,396 @@
|
|
|
1
|
+
import annotationlib
|
|
2
|
+
import inspect
|
|
3
|
+
from collections.abc import Mapping
|
|
4
|
+
from functools import partial
|
|
5
|
+
from typing import Annotated, ClassVar, get_origin
|
|
6
|
+
|
|
7
|
+
DECORATIONS = {
|
|
8
|
+
# safe to analyze and transpile
|
|
9
|
+
"__js__", # bool
|
|
10
|
+
|
|
11
|
+
# include in output even if not visited
|
|
12
|
+
"__js_keep__", # bool
|
|
13
|
+
|
|
14
|
+
# use different implementation of a Python method on client by
|
|
15
|
+
# replacing it with the function in the decoration, which is then
|
|
16
|
+
# transpiled
|
|
17
|
+
"__js_client__", # function
|
|
18
|
+
|
|
19
|
+
# raw JavaScript function body, or a callable returning it
|
|
20
|
+
"__js_source__", # str | callable
|
|
21
|
+
"__js_source_imports__", # dict[str, class or function]
|
|
22
|
+
|
|
23
|
+
# returns JavaScript source as string, replaces the code at
|
|
24
|
+
# every call site where this function is called
|
|
25
|
+
"__js_inline__", # function
|
|
26
|
+
|
|
27
|
+
# runtime function called in place of the decorated interface
|
|
28
|
+
"__js_inline_call__", # function
|
|
29
|
+
|
|
30
|
+
# runtime function used when an inline function is referenced as a value
|
|
31
|
+
"__js_value__", # function
|
|
32
|
+
"__js_value_source__", # str
|
|
33
|
+
|
|
34
|
+
# functions referenced by an inline rewrite and retained in generated code
|
|
35
|
+
"__js_inline_dependencies__", # dict[str, function]
|
|
36
|
+
|
|
37
|
+
# returns JavaScript source as string, appending the code
|
|
38
|
+
# after the definition of the wrapped code object
|
|
39
|
+
"__js_append__", # function receiving reached generated member names
|
|
40
|
+
"__js_member_dependencies__", # generated member name to required class
|
|
41
|
+
|
|
42
|
+
# dispatch a builtin function through a special method on its first argument
|
|
43
|
+
"__js_dispatch__", # str
|
|
44
|
+
|
|
45
|
+
# compiler call analysis attached to the function it describes
|
|
46
|
+
"__js_analysis__", # callable
|
|
47
|
+
|
|
48
|
+
# dunder methods needed by a runtime implementation
|
|
49
|
+
"__js_runtime_dunders__", # tuple[str | int, tuple[str, ...]]
|
|
50
|
+
|
|
51
|
+
# safe to analyze but don't include in output
|
|
52
|
+
"__builtin__", # bool
|
|
53
|
+
|
|
54
|
+
# supplied by the JavaScript target rather than emitted
|
|
55
|
+
"__js_native__", # bool
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def is_cls_or_func(obj):
|
|
60
|
+
return inspect.isfunction(obj) or inspect.isclass(obj)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def has_inline_decorator(obj):
|
|
64
|
+
obj = getattr(obj, "__func__", obj)
|
|
65
|
+
decorations = getattr(obj, "__dict__", {})
|
|
66
|
+
return bool(
|
|
67
|
+
decorations.get("__js_inline__", False)
|
|
68
|
+
or decorations.get("__js_inline_call__", False)
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def has_source_decorator(obj):
|
|
73
|
+
return getattr(obj, "__dict__", {}).get("__js_source__", False)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def should_analyze_func_body(obj):
|
|
77
|
+
function = obj
|
|
78
|
+
obj = getattr(function, "py_obj", function)
|
|
79
|
+
cls = getattr(function, "cls", None)
|
|
80
|
+
if getattr(obj, "__dict__", {}).get("__js_native__", False) or (
|
|
81
|
+
cls is not None
|
|
82
|
+
and getattr(cls.py_obj, "__dict__", {}).get("__js_native__", False)
|
|
83
|
+
):
|
|
84
|
+
return False
|
|
85
|
+
return not (has_inline_decorator(obj) or has_source_decorator(obj))
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def has_keep_decorator(obj):
|
|
89
|
+
return getattr(obj, "__dict__", {}).get("__js_keep__", False)
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def should_include(obj):
|
|
93
|
+
runtime_implementation = getattr(obj, "is_runtime_implementation", False)
|
|
94
|
+
kept = has_keep_decorator(obj.py_obj)
|
|
95
|
+
if has_inline_decorator(obj.py_obj) and not kept and not runtime_implementation:
|
|
96
|
+
return False
|
|
97
|
+
is_builtin = getattr(obj.py_obj, "__dict__", {}).get("__builtin__", False)
|
|
98
|
+
if is_builtin and not runtime_implementation:
|
|
99
|
+
return False
|
|
100
|
+
return kept or bool(obj.visited)
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
class _Implementation:
|
|
104
|
+
def __init__(self, function, attribute: str, name: str):
|
|
105
|
+
self.function = function
|
|
106
|
+
self.attribute = attribute
|
|
107
|
+
self.name = name
|
|
108
|
+
|
|
109
|
+
def __call__(self, implementation):
|
|
110
|
+
if not callable(implementation):
|
|
111
|
+
raise TypeError(
|
|
112
|
+
f"@{self.function.__name__}.{self.name} requires a callable."
|
|
113
|
+
)
|
|
114
|
+
setattr(self.function, self.attribute, implementation)
|
|
115
|
+
return self.function
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def _compiled_callable(function) -> bool:
|
|
119
|
+
while isinstance(function, partial):
|
|
120
|
+
function = function.func
|
|
121
|
+
return bool(getattr(function, "__js__", False))
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
class _InlineImplementation(_Implementation):
|
|
125
|
+
def __init__(self, function):
|
|
126
|
+
super().__init__(function, "__js_inline__", "inline")
|
|
127
|
+
|
|
128
|
+
def __call__(self, implementation=None, *, dependencies=None):
|
|
129
|
+
if implementation is None:
|
|
130
|
+
if dependencies is None:
|
|
131
|
+
raise TypeError(
|
|
132
|
+
f"@{self.function.__name__}.inline requires a callable."
|
|
133
|
+
)
|
|
134
|
+
|
|
135
|
+
def decorate(implementation):
|
|
136
|
+
return self(implementation, dependencies=dependencies)
|
|
137
|
+
|
|
138
|
+
return decorate
|
|
139
|
+
if _compiled_callable(implementation):
|
|
140
|
+
raise TypeError(
|
|
141
|
+
"An inline source generator cannot be marked @js. "
|
|
142
|
+
"Use @js.inline(call=helper) to call a runtime helper."
|
|
143
|
+
)
|
|
144
|
+
if not callable(implementation):
|
|
145
|
+
raise TypeError(
|
|
146
|
+
f"@{self.function.__name__}.inline requires a callable."
|
|
147
|
+
)
|
|
148
|
+
_set_inline(self.function, implementation, dependencies)
|
|
149
|
+
return self.function
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
class _ValueImplementation(_Implementation):
|
|
153
|
+
def __init__(self, function):
|
|
154
|
+
super().__init__(function, "__js_value__", "value")
|
|
155
|
+
|
|
156
|
+
def __call__(self, implementation):
|
|
157
|
+
if not inspect.isfunction(implementation):
|
|
158
|
+
raise TypeError(
|
|
159
|
+
f"@{self.function.__name__}.value requires a function."
|
|
160
|
+
)
|
|
161
|
+
implementation.__js__ = True
|
|
162
|
+
return super().__call__(implementation)
|
|
163
|
+
|
|
164
|
+
def source(self, source: str):
|
|
165
|
+
if not isinstance(source, str):
|
|
166
|
+
raise TypeError("A value source implementation must be a string.")
|
|
167
|
+
self.function.__js_value_source__ = source
|
|
168
|
+
return self.function
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
class _AnalysisImplementation(_Implementation):
|
|
172
|
+
def __init__(self, function):
|
|
173
|
+
super().__init__(function, "__js_analysis__", "analyze")
|
|
174
|
+
|
|
175
|
+
def __call__(self, implementation):
|
|
176
|
+
if _compiled_callable(implementation):
|
|
177
|
+
raise TypeError(
|
|
178
|
+
"A call-analysis hook cannot be marked @js because it runs "
|
|
179
|
+
"only in the compiler."
|
|
180
|
+
)
|
|
181
|
+
return super().__call__(implementation)
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
def _attach_implementation_api(function):
|
|
185
|
+
if "client" not in function.__dict__:
|
|
186
|
+
function.client = _Implementation(function, "__js_client__", "client")
|
|
187
|
+
if "inline" not in function.__dict__:
|
|
188
|
+
function.inline = _InlineImplementation(function)
|
|
189
|
+
if "value" not in function.__dict__:
|
|
190
|
+
function.value = _ValueImplementation(function)
|
|
191
|
+
if "analyze" not in function.__dict__:
|
|
192
|
+
function.analyze = _AnalysisImplementation(function)
|
|
193
|
+
|
|
194
|
+
def source(source):
|
|
195
|
+
if not isinstance(source, str) and not callable(source):
|
|
196
|
+
raise TypeError(
|
|
197
|
+
"A JavaScript source implementation must be a string or callable."
|
|
198
|
+
)
|
|
199
|
+
function.__js_source__ = source
|
|
200
|
+
return function
|
|
201
|
+
|
|
202
|
+
function.source = source
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
def _class_instance_annotations(cls: type) -> dict[str, object]:
|
|
206
|
+
annotations = annotationlib.get_annotations(
|
|
207
|
+
cls,
|
|
208
|
+
format=annotationlib.Format.FORWARDREF,
|
|
209
|
+
)
|
|
210
|
+
annotate = cls.__annotate__
|
|
211
|
+
globals_ = annotate.__globals__ if annotate is not None else {}
|
|
212
|
+
for name, annotation in annotations.items():
|
|
213
|
+
if isinstance(annotation, annotationlib.ForwardRef):
|
|
214
|
+
annotations[name] = annotation.evaluate(
|
|
215
|
+
globals=globals_,
|
|
216
|
+
locals={cls.__name__: cls},
|
|
217
|
+
owner=None,
|
|
218
|
+
)
|
|
219
|
+
return {
|
|
220
|
+
name: annotation
|
|
221
|
+
for name, annotation in annotations.items()
|
|
222
|
+
if name not in vars(cls) and get_origin(annotation) is not ClassVar
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
def js(obj):
|
|
227
|
+
obj.__js__ = True
|
|
228
|
+
if inspect.isclass(obj):
|
|
229
|
+
if "__pyjs_instance_annotations__" not in vars(obj):
|
|
230
|
+
obj.__pyjs_instance_annotations__ = _class_instance_annotations(obj)
|
|
231
|
+
else:
|
|
232
|
+
_attach_implementation_api(obj)
|
|
233
|
+
return obj
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
def _set_inline(function, source, dependencies=None):
|
|
237
|
+
if isinstance(source, str):
|
|
238
|
+
template = source.replace("{*args}", "{_args_suffix}")
|
|
239
|
+
function.__js_inline__ = lambda **kwargs: template.format(**kwargs)
|
|
240
|
+
elif callable(source):
|
|
241
|
+
if _compiled_callable(source):
|
|
242
|
+
raise TypeError(
|
|
243
|
+
"An @js.inline source generator cannot be marked @js. "
|
|
244
|
+
"Use @js.inline(call=helper) to call a runtime helper."
|
|
245
|
+
)
|
|
246
|
+
function.__js_inline__ = source
|
|
247
|
+
else:
|
|
248
|
+
raise TypeError("@js.inline requires a source string or callable.")
|
|
249
|
+
|
|
250
|
+
if dependencies is None:
|
|
251
|
+
return
|
|
252
|
+
target = function.__qualname__
|
|
253
|
+
if not isinstance(dependencies, Mapping):
|
|
254
|
+
raise TypeError(f"@js.inline dependencies for {target!r} must be a mapping.")
|
|
255
|
+
invalid_names = [
|
|
256
|
+
name
|
|
257
|
+
for name in dependencies
|
|
258
|
+
if not isinstance(name, str) or not name.isidentifier()
|
|
259
|
+
]
|
|
260
|
+
if invalid_names:
|
|
261
|
+
names = ", ".join(repr(name) for name in invalid_names)
|
|
262
|
+
raise TypeError(
|
|
263
|
+
f"@js.inline dependency names for {target!r} must be Python "
|
|
264
|
+
f"identifiers; invalid: {names}."
|
|
265
|
+
)
|
|
266
|
+
invalid_dependencies = [
|
|
267
|
+
(name, type(dependency).__name__)
|
|
268
|
+
for name, dependency in dependencies.items()
|
|
269
|
+
if not inspect.isfunction(dependency)
|
|
270
|
+
]
|
|
271
|
+
if invalid_dependencies:
|
|
272
|
+
values = ", ".join(
|
|
273
|
+
f"{name!r} ({type_name})"
|
|
274
|
+
for name, type_name in invalid_dependencies
|
|
275
|
+
)
|
|
276
|
+
raise TypeError(
|
|
277
|
+
f"@js.inline dependencies for {target!r} must be functions; "
|
|
278
|
+
f"invalid: {values}."
|
|
279
|
+
)
|
|
280
|
+
reserved = {
|
|
281
|
+
"_arg_strs",
|
|
282
|
+
"_arg_types",
|
|
283
|
+
"_keyword_strs",
|
|
284
|
+
"_args_joined",
|
|
285
|
+
"_args_suffix",
|
|
286
|
+
"self",
|
|
287
|
+
}
|
|
288
|
+
parameter_names = set(inspect.signature(function).parameters)
|
|
289
|
+
conflicts = set(dependencies) & (reserved | parameter_names)
|
|
290
|
+
if conflicts:
|
|
291
|
+
raise TypeError(
|
|
292
|
+
f"@js.inline dependency names for {target!r} conflict with call "
|
|
293
|
+
f"arguments: {', '.join(sorted(conflicts))}."
|
|
294
|
+
)
|
|
295
|
+
function.__js_inline_dependencies__ = dict(dependencies)
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
def _js_inline(source=None, *, call=None, dependencies=None):
|
|
299
|
+
if (source is None) == (call is None):
|
|
300
|
+
raise TypeError("@js.inline requires exactly one of source or call.")
|
|
301
|
+
if call is not None:
|
|
302
|
+
if dependencies is not None:
|
|
303
|
+
raise TypeError(
|
|
304
|
+
"@js.inline(call=...) does not accept separate dependencies."
|
|
305
|
+
)
|
|
306
|
+
if not inspect.isfunction(call):
|
|
307
|
+
raise TypeError("@js.inline call target must be a function marked @js.")
|
|
308
|
+
if not getattr(call, "__js__", False):
|
|
309
|
+
raise TypeError("@js.inline call target must be marked @js.")
|
|
310
|
+
if has_inline_decorator(call):
|
|
311
|
+
raise TypeError("@js.inline call target must emit a runtime function.")
|
|
312
|
+
|
|
313
|
+
def decorate(obj):
|
|
314
|
+
obj = js(obj)
|
|
315
|
+
if call is not None:
|
|
316
|
+
obj.__js_inline_call__ = call
|
|
317
|
+
else:
|
|
318
|
+
_set_inline(obj, source, dependencies)
|
|
319
|
+
return obj
|
|
320
|
+
|
|
321
|
+
return decorate
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
def _js_native(obj):
|
|
325
|
+
if is_cls_or_func(obj):
|
|
326
|
+
obj = js(obj)
|
|
327
|
+
else:
|
|
328
|
+
obj.__js__ = True
|
|
329
|
+
obj.__static__ = True
|
|
330
|
+
obj.__builtin__ = True
|
|
331
|
+
obj.__js_native__ = True
|
|
332
|
+
return obj
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
def _js_keep(obj):
|
|
336
|
+
if inspect.isclass(obj) or "." not in obj.__qualname__:
|
|
337
|
+
raise TypeError("@js.keep is only supported for class methods.")
|
|
338
|
+
obj = js(obj)
|
|
339
|
+
obj.__js_keep__ = True
|
|
340
|
+
return obj
|
|
341
|
+
|
|
342
|
+
|
|
343
|
+
def _js_dispatch(method_name: str):
|
|
344
|
+
if not (
|
|
345
|
+
isinstance(method_name, str)
|
|
346
|
+
and method_name.startswith("__")
|
|
347
|
+
and method_name.endswith("__")
|
|
348
|
+
):
|
|
349
|
+
raise TypeError("@js.dispatch requires a dunder method name.")
|
|
350
|
+
|
|
351
|
+
def decorate(obj):
|
|
352
|
+
obj = js(obj)
|
|
353
|
+
obj.__js_dispatch__ = method_name
|
|
354
|
+
return obj
|
|
355
|
+
|
|
356
|
+
return decorate
|
|
357
|
+
|
|
358
|
+
|
|
359
|
+
def _js_runtime_dunders(*method_names: str, item_of: int | str):
|
|
360
|
+
if item_of != "self" and not (
|
|
361
|
+
isinstance(item_of, int) and not isinstance(item_of, bool) and item_of >= 0
|
|
362
|
+
):
|
|
363
|
+
raise TypeError(
|
|
364
|
+
"@js.runtime_dunders item_of must be 'self' or an argument index."
|
|
365
|
+
)
|
|
366
|
+
if not method_names or any(
|
|
367
|
+
not isinstance(name, str)
|
|
368
|
+
or not name.startswith("__")
|
|
369
|
+
or not name.endswith("__")
|
|
370
|
+
for name in method_names
|
|
371
|
+
):
|
|
372
|
+
raise TypeError(
|
|
373
|
+
"@js.runtime_dunders requires one or more dunder method names."
|
|
374
|
+
)
|
|
375
|
+
|
|
376
|
+
def decorate(obj):
|
|
377
|
+
obj = js(obj)
|
|
378
|
+
obj.__js_runtime_dunders__ = (item_of, method_names)
|
|
379
|
+
return obj
|
|
380
|
+
|
|
381
|
+
return decorate
|
|
382
|
+
|
|
383
|
+
|
|
384
|
+
def nojs(cls_func):
|
|
385
|
+
cls_func.__js__ = False
|
|
386
|
+
return cls_func
|
|
387
|
+
|
|
388
|
+
|
|
389
|
+
js.inline = _js_inline
|
|
390
|
+
js.native = _js_native
|
|
391
|
+
js.keep = _js_keep
|
|
392
|
+
js.dispatch = _js_dispatch
|
|
393
|
+
js.runtime_dunders = _js_runtime_dunders
|
|
394
|
+
|
|
395
|
+
|
|
396
|
+
type JS[T] = Annotated[T, js]
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
from typing import TypedDict
|
|
2
|
-
|
|
3
1
|
from pyjs import js
|
|
4
|
-
from pyjs.javascript import JSON
|
|
2
|
+
from pyjs.javascript import JSON, JSONObject
|
|
5
3
|
from pyjs.web.dom import document, localStorage, navigator, window
|
|
6
4
|
from pyjs.web.domx import (
|
|
7
5
|
CustomElement,
|
|
@@ -17,7 +15,7 @@ from pyjs.web.events import Event, EventTarget, KeyboardEvent
|
|
|
17
15
|
from pyjs.web.html import HTMLElement
|
|
18
16
|
|
|
19
17
|
|
|
20
|
-
class SearchRecord(
|
|
18
|
+
class SearchRecord(JSONObject):
|
|
21
19
|
title: str
|
|
22
20
|
section: str
|
|
23
21
|
text: str
|
|
@@ -29,7 +27,7 @@ class DocsEventListener:
|
|
|
29
27
|
def __init__(self, callback: callable):
|
|
30
28
|
self.callback = callback
|
|
31
29
|
|
|
32
|
-
@js
|
|
30
|
+
@js.keep
|
|
33
31
|
def handleEvent(self, event: Event):
|
|
34
32
|
self.callback(event)
|
|
35
33
|
|
|
@@ -40,7 +38,7 @@ class CodeCopyListener:
|
|
|
40
38
|
self.button = button_element
|
|
41
39
|
self.code = code_element
|
|
42
40
|
|
|
43
|
-
@js
|
|
41
|
+
@js.keep
|
|
44
42
|
async def handleEvent(self, event: Event):
|
|
45
43
|
text = self.code.textContent
|
|
46
44
|
if text is None:
|