webcompy-cli 0.0.14__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.
- webcompy_cli/__init__.py +20 -0
- webcompy_cli/_argparser.py +232 -0
- webcompy_cli/_browser_probes.py +648 -0
- webcompy_cli/_browser_test_harness.py +554 -0
- webcompy_cli/_build.py +425 -0
- webcompy_cli/_console_types.py +15 -0
- webcompy_cli/_dependency_resolver.py +301 -0
- webcompy_cli/_dualrun_pytest_plugin.py +130 -0
- webcompy_cli/_exception.py +9 -0
- webcompy_cli/_generate.py +224 -0
- webcompy_cli/_init_project.py +54 -0
- webcompy_cli/_inspect.py +741 -0
- webcompy_cli/_inspect_pyexec.py +244 -0
- webcompy_cli/_lock.py +82 -0
- webcompy_cli/_lockfile.py +396 -0
- webcompy_cli/_lockfile_sync.py +343 -0
- webcompy_cli/_output.py +150 -0
- webcompy_cli/_prebuild.py +661 -0
- webcompy_cli/_pwa.py +474 -0
- webcompy_cli/_pyodide_downloader.py +113 -0
- webcompy_cli/_pyodide_lock.py +74 -0
- webcompy_cli/_runtime_downloader.py +222 -0
- webcompy_cli/_server.py +568 -0
- webcompy_cli/_static_files.py +27 -0
- webcompy_cli/_utils.py +72 -0
- webcompy_cli/_version_sweep.py +213 -0
- webcompy_cli/_wheel_builder.py +509 -0
- webcompy_cli/config/__init__.py +23 -0
- webcompy_cli/config/_build_config.py +168 -0
- webcompy_cli/config/_pwa_config.py +203 -0
- webcompy_cli/config/_server_config.py +53 -0
- webcompy_cli/py.typed +0 -0
- webcompy_cli/template_data/app/__init__.py +0 -0
- webcompy_cli/template_data/app/app.py +22 -0
- webcompy_cli/template_data/app/components/__init__.py +0 -0
- webcompy_cli/template_data/app/components/fizzbuzz.py +117 -0
- webcompy_cli/template_data/app/components/home.py +15 -0
- webcompy_cli/template_data/app/components/input.py +34 -0
- webcompy_cli/template_data/app/components/navigation.py +36 -0
- webcompy_cli/template_data/app/components/not_found.py +22 -0
- webcompy_cli/template_data/app/components/root.py +16 -0
- webcompy_cli/template_data/app/router.py +17 -0
- webcompy_cli/template_data/webcompy_config.py +12 -0
- webcompy_cli-0.0.14.dist-info/METADATA +53 -0
- webcompy_cli-0.0.14.dist-info/RECORD +47 -0
- webcompy_cli-0.0.14.dist-info/WHEEL +4 -0
- webcompy_cli-0.0.14.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
"""Build configuration for WebComPy projects."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from collections.abc import Callable, Sequence
|
|
6
|
+
from dataclasses import dataclass, field
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
from types import ModuleType
|
|
9
|
+
from typing import Literal
|
|
10
|
+
|
|
11
|
+
from webcompy_cli.config._pwa_config import PWAConfig
|
|
12
|
+
from webcompy_cli.config._server_config import LockfileSyncConfig, WebComPyServerConfig
|
|
13
|
+
from webcompy_server._static_route import StaticRoute
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class _Sentinel:
|
|
17
|
+
pass
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
_UNSET: _Sentinel = _Sentinel()
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@dataclass
|
|
24
|
+
class WebComPyBuildConfig:
|
|
25
|
+
"""Build configuration for a WebComPy application package.
|
|
26
|
+
|
|
27
|
+
Collects all options controlling dependency resolution, wheel
|
|
28
|
+
building, resource handling, and serving. ``app_package_path`` and
|
|
29
|
+
``app`` are derived from ``app_module``/``app_var`` in
|
|
30
|
+
``__post_init__``.
|
|
31
|
+
|
|
32
|
+
Args:
|
|
33
|
+
app_module: Python module containing the application instance.
|
|
34
|
+
app_var: Attribute name of the application inside ``app_module``.
|
|
35
|
+
dependencies: Explicit browser dependency names, or ``None`` to
|
|
36
|
+
discover from ``pyproject.toml``.
|
|
37
|
+
dependencies_from: Optional dependency group name in
|
|
38
|
+
``pyproject.toml`` to resolve ``dependencies`` from.
|
|
39
|
+
resources: Glob patterns selecting resource files, or ``None`` for
|
|
40
|
+
the default includes. An empty list disables resources.
|
|
41
|
+
resource_exclude: Glob patterns excluding resource files.
|
|
42
|
+
version: Application version string, or ``None`` for ``"0.0.0"``.
|
|
43
|
+
serve_all_deps: Whether to bundle all pure-Python dependencies
|
|
44
|
+
into the app wheel.
|
|
45
|
+
wasm_serving: How WASM packages are served, or ``None`` to
|
|
46
|
+
resolve from ``standalone``.
|
|
47
|
+
runtime_serving: How the PyScript/Pyodide runtime is served, or
|
|
48
|
+
``None`` to resolve from ``standalone``.
|
|
49
|
+
standalone: Whether to serve all assets locally.
|
|
50
|
+
wheel_mode: Wheel bundling mode.
|
|
51
|
+
resource_transfer: How resource files are transferred to the
|
|
52
|
+
browser.
|
|
53
|
+
dist: Output directory for the static site.
|
|
54
|
+
static_files_dir: Directory housing static files relative to the
|
|
55
|
+
app package path.
|
|
56
|
+
prebuild_dir: Default directory for materialized prebuild outputs,
|
|
57
|
+
resolved relative to ``app_package_path`` when relative.
|
|
58
|
+
prerender: Build-time prerender depth policy (``"none"``,
|
|
59
|
+
``"static"``, or ``"all"``).
|
|
60
|
+
lockfile_sync_config: Configuration for lock file synchronization.
|
|
61
|
+
server: Server configuration.
|
|
62
|
+
pwa: Progressive Web App build configuration.
|
|
63
|
+
static_routes: Optional zero-argument callable returning virtual
|
|
64
|
+
``StaticRoute`` endpoints to serve and export during SSG.
|
|
65
|
+
|
|
66
|
+
Attributes:
|
|
67
|
+
app_module: Python module containing the application instance.
|
|
68
|
+
app_var: Attribute name of the application inside ``app_module``.
|
|
69
|
+
app: The application instance resolved from ``app_module``/
|
|
70
|
+
``app_var``.
|
|
71
|
+
app_package_path: Directory containing the application package,
|
|
72
|
+
derived from ``app_module``.
|
|
73
|
+
dependencies: Explicit browser dependency names, or ``None`` to
|
|
74
|
+
discover from ``pyproject.toml``.
|
|
75
|
+
dependencies_from: Optional dependency group name in
|
|
76
|
+
``pyproject.toml`` to resolve ``dependencies`` from.
|
|
77
|
+
resources: Glob patterns selecting resource files, or ``None`` for
|
|
78
|
+
the default includes.
|
|
79
|
+
resource_exclude: Glob patterns excluding resource files.
|
|
80
|
+
version: Application version string, or ``None`` for ``"0.0.0"``.
|
|
81
|
+
serve_all_deps: Whether to bundle all pure-Python dependencies
|
|
82
|
+
into the app wheel.
|
|
83
|
+
wasm_serving: How WASM packages are served.
|
|
84
|
+
runtime_serving: How the PyScript/Pyodide runtime is served.
|
|
85
|
+
standalone: Whether to serve all assets locally.
|
|
86
|
+
wheel_mode: Wheel bundling mode.
|
|
87
|
+
resource_transfer: How resource files are transferred.
|
|
88
|
+
dist: Output directory for the static site.
|
|
89
|
+
static_files_dir: Directory housing static files.
|
|
90
|
+
prebuild_dir: Default output directory for prebuilt artifacts.
|
|
91
|
+
prerender: Build-time prerender depth policy.
|
|
92
|
+
lockfile_sync_config: Configuration for lock file synchronization.
|
|
93
|
+
server: Server configuration.
|
|
94
|
+
pwa: Progressive Web App build configuration.
|
|
95
|
+
static_routes: Optional zero-argument callable returning virtual
|
|
96
|
+
``StaticRoute`` endpoints.
|
|
97
|
+
|
|
98
|
+
"""
|
|
99
|
+
|
|
100
|
+
app_module: ModuleType
|
|
101
|
+
app_var: str = "app"
|
|
102
|
+
dependencies: list[str] | None = None
|
|
103
|
+
dependencies_from: str | None = None
|
|
104
|
+
resources: list[str] | None = None
|
|
105
|
+
resource_exclude: list[str] | None = None
|
|
106
|
+
version: str | None = None
|
|
107
|
+
serve_all_deps: bool = True
|
|
108
|
+
wasm_serving: Literal["cdn", "local"] | None = None
|
|
109
|
+
runtime_serving: Literal["cdn", "local"] | None = None
|
|
110
|
+
standalone: bool = False
|
|
111
|
+
wheel_mode: Literal["bundled", "split"] = "bundled"
|
|
112
|
+
resource_transfer: Literal["used", "all-text"] = "used"
|
|
113
|
+
dist: str = "dist"
|
|
114
|
+
static_files_dir: str = "static"
|
|
115
|
+
prebuild_dir: str = ".webcompy-build"
|
|
116
|
+
prerender: Literal["none", "static", "all"] = "none"
|
|
117
|
+
lockfile_sync_config: LockfileSyncConfig | None = None
|
|
118
|
+
server: WebComPyServerConfig = field(default_factory=WebComPyServerConfig)
|
|
119
|
+
pwa: PWAConfig = field(default_factory=PWAConfig)
|
|
120
|
+
static_routes: Callable[[], Sequence[StaticRoute]] | None = None
|
|
121
|
+
|
|
122
|
+
def __post_init__(self):
|
|
123
|
+
if self.resource_transfer not in ("used", "all-text"):
|
|
124
|
+
from webcompy.exception import WebComPyException
|
|
125
|
+
|
|
126
|
+
raise WebComPyException(
|
|
127
|
+
f"Invalid resource_transfer: {self.resource_transfer!r}. Valid values: 'used', 'all-text'"
|
|
128
|
+
)
|
|
129
|
+
if self.prerender not in ("none", "static", "all"):
|
|
130
|
+
from webcompy.exception import WebComPyException
|
|
131
|
+
|
|
132
|
+
raise WebComPyException(f"Invalid prerender: {self.prerender!r}. Valid values: 'none', 'static', 'all'")
|
|
133
|
+
if not isinstance(self.prebuild_dir, str) or not self.prebuild_dir.strip():
|
|
134
|
+
from webcompy.exception import WebComPyException
|
|
135
|
+
|
|
136
|
+
raise WebComPyException("Invalid prebuild_dir: must be a non-empty path string")
|
|
137
|
+
self.app_package_path = Path(self.app_module.__file__).parent # type: ignore[arg-type]
|
|
138
|
+
self.app = getattr(self.app_module, self.app_var)
|
|
139
|
+
self._explicit_wasm_serving: Literal["cdn", "local"] | _Sentinel = (
|
|
140
|
+
self.wasm_serving if self.wasm_serving is not None else _UNSET
|
|
141
|
+
)
|
|
142
|
+
self._explicit_runtime_serving: Literal["cdn", "local"] | _Sentinel = (
|
|
143
|
+
self.runtime_serving if self.runtime_serving is not None else _UNSET
|
|
144
|
+
)
|
|
145
|
+
self.resolve_standalone()
|
|
146
|
+
|
|
147
|
+
def resolve_standalone(self):
|
|
148
|
+
"""Resolve implicit serving modes from the ``standalone`` flag."""
|
|
149
|
+
|
|
150
|
+
if self.standalone:
|
|
151
|
+
import sys
|
|
152
|
+
|
|
153
|
+
if self.serve_all_deps is False:
|
|
154
|
+
print("Warning: standalone=True forces serve_all_deps=True", file=sys.stderr, flush=True)
|
|
155
|
+
self.serve_all_deps = True
|
|
156
|
+
self.wasm_serving = (
|
|
157
|
+
"local" if isinstance(self._explicit_wasm_serving, _Sentinel) else self._explicit_wasm_serving
|
|
158
|
+
)
|
|
159
|
+
self.runtime_serving = (
|
|
160
|
+
"local" if isinstance(self._explicit_runtime_serving, _Sentinel) else self._explicit_runtime_serving
|
|
161
|
+
)
|
|
162
|
+
else:
|
|
163
|
+
self.wasm_serving = (
|
|
164
|
+
"cdn" if isinstance(self._explicit_wasm_serving, _Sentinel) else self._explicit_wasm_serving
|
|
165
|
+
)
|
|
166
|
+
self.runtime_serving = (
|
|
167
|
+
"cdn" if isinstance(self._explicit_runtime_serving, _Sentinel) else self._explicit_runtime_serving
|
|
168
|
+
)
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
"""Progressive Web App configuration dataclasses for build-time generation."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass, field
|
|
6
|
+
from pathlib import Path, PurePosixPath
|
|
7
|
+
from typing import Literal, TypeAlias
|
|
8
|
+
|
|
9
|
+
from webcompy.exception import WebComPyException
|
|
10
|
+
|
|
11
|
+
RuntimeCachingStrategy: TypeAlias = Literal["cache-first", "network-first", "stale-while-revalidate"]
|
|
12
|
+
"""Caching strategy applied to requests matching a runtime caching rule."""
|
|
13
|
+
|
|
14
|
+
_VALID_STRATEGIES = ("cache-first", "network-first", "stale-while-revalidate")
|
|
15
|
+
_VALID_PRECACHE_MODES = ("auto", "none")
|
|
16
|
+
_VALID_DISPLAYS = ("fullscreen", "standalone", "minimal-ui", "browser")
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@dataclass
|
|
20
|
+
class ManifestIcon:
|
|
21
|
+
"""An icon entry in the Web App Manifest.
|
|
22
|
+
|
|
23
|
+
Args:
|
|
24
|
+
src: URL of the icon, resolved relative to the application base
|
|
25
|
+
URL. Typically a path inside the static files directory.
|
|
26
|
+
sizes: Space-separated icon sizes (e.g. ``"192x192 512x512"``).
|
|
27
|
+
type: Optional MIME type of the icon resource.
|
|
28
|
+
purpose: Optional icon purpose (e.g. ``"maskable"``).
|
|
29
|
+
|
|
30
|
+
Attributes:
|
|
31
|
+
src: URL of the icon, resolved relative to the application base URL.
|
|
32
|
+
sizes: Space-separated icon sizes.
|
|
33
|
+
type: Optional MIME type of the icon resource.
|
|
34
|
+
purpose: Optional icon purpose.
|
|
35
|
+
|
|
36
|
+
"""
|
|
37
|
+
|
|
38
|
+
src: str
|
|
39
|
+
sizes: str
|
|
40
|
+
type: str | None = None
|
|
41
|
+
purpose: str | None = None
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
@dataclass
|
|
45
|
+
class ManifestConfig:
|
|
46
|
+
"""Web App Manifest metadata serialized to ``manifest.webmanifest``.
|
|
47
|
+
|
|
48
|
+
Args:
|
|
49
|
+
name: Human-readable application name.
|
|
50
|
+
short_name: Optional shortened name for launchers.
|
|
51
|
+
icons: Icon entries referenced by the manifest.
|
|
52
|
+
display: Display mode; one of ``fullscreen``, ``standalone``,
|
|
53
|
+
``minimal-ui`` or ``browser``.
|
|
54
|
+
theme_color: Optional default theme color.
|
|
55
|
+
background_color: Optional splash background color.
|
|
56
|
+
start_url: Optional start URL; defaults to the app base URL.
|
|
57
|
+
scope: Optional navigation scope; defaults to the app base URL.
|
|
58
|
+
|
|
59
|
+
Attributes:
|
|
60
|
+
name: Human-readable application name.
|
|
61
|
+
short_name: Optional shortened name for launchers.
|
|
62
|
+
icons: Icon entries referenced by the manifest.
|
|
63
|
+
display: Display mode.
|
|
64
|
+
theme_color: Optional default theme color.
|
|
65
|
+
background_color: Optional splash background color.
|
|
66
|
+
start_url: Optional start URL; defaults to the app base URL.
|
|
67
|
+
scope: Optional navigation scope; defaults to the app base URL.
|
|
68
|
+
|
|
69
|
+
"""
|
|
70
|
+
|
|
71
|
+
name: str
|
|
72
|
+
short_name: str | None = None
|
|
73
|
+
icons: list[ManifestIcon] = field(default_factory=list)
|
|
74
|
+
display: str = "standalone"
|
|
75
|
+
theme_color: str | None = None
|
|
76
|
+
background_color: str | None = None
|
|
77
|
+
start_url: str | None = None
|
|
78
|
+
scope: str | None = None
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
@dataclass
|
|
82
|
+
class RuntimeCachingRule:
|
|
83
|
+
"""A runtime caching rule matched against same-origin requests.
|
|
84
|
+
|
|
85
|
+
Args:
|
|
86
|
+
pattern: Same-origin URL pattern; a path prefix or a glob with
|
|
87
|
+
``*`` (single segment) and ``**`` (any depth). Matched against
|
|
88
|
+
the request path relative to the app scope (always starting
|
|
89
|
+
with ``/``); a missing leading slash is added at generation
|
|
90
|
+
time. Matching uses the full URL, so different query strings
|
|
91
|
+
are cached independently.
|
|
92
|
+
strategy: Caching strategy applied to matching requests; one of
|
|
93
|
+
``cache-first``, ``network-first`` or
|
|
94
|
+
``stale-while-revalidate``.
|
|
95
|
+
max_entries: Optional maximum number of entries kept in the rule's
|
|
96
|
+
cache before eviction trims it.
|
|
97
|
+
max_age: Optional maximum cached entry age in seconds; enforced
|
|
98
|
+
best-effort within a worker lifetime.
|
|
99
|
+
|
|
100
|
+
Attributes:
|
|
101
|
+
pattern: Same-origin URL pattern.
|
|
102
|
+
strategy: Caching strategy applied to matching requests.
|
|
103
|
+
max_entries: Optional maximum number of cached entries.
|
|
104
|
+
max_age: Optional maximum cached entry age in seconds.
|
|
105
|
+
|
|
106
|
+
"""
|
|
107
|
+
|
|
108
|
+
pattern: str
|
|
109
|
+
strategy: RuntimeCachingStrategy
|
|
110
|
+
max_entries: int | None = None
|
|
111
|
+
max_age: int | None = None
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
@dataclass
|
|
115
|
+
class PWAConfig:
|
|
116
|
+
"""Progressive Web App build configuration (disabled by default).
|
|
117
|
+
|
|
118
|
+
Args:
|
|
119
|
+
enabled: Whether PWA support is active; defaults to ``False``.
|
|
120
|
+
manifest: Manifest metadata; required when ``enabled`` is true.
|
|
121
|
+
precache: Precache mode, ``"auto"`` (enumerate build output) or
|
|
122
|
+
``"none"`` (empty precache manifest).
|
|
123
|
+
precache_runtime: Opt-in to precaching the Python runtime files,
|
|
124
|
+
which logs a build-time size warning.
|
|
125
|
+
runtime: Runtime caching rules applied to same-origin requests.
|
|
126
|
+
fallback_path: Optional path (relative to the static files
|
|
127
|
+
directory) of an offline fallback page overriding the
|
|
128
|
+
framework default.
|
|
129
|
+
|
|
130
|
+
Attributes:
|
|
131
|
+
enabled: Whether PWA support is active.
|
|
132
|
+
manifest: Manifest metadata; ``None`` when not configured.
|
|
133
|
+
precache: Precache mode (``"auto"`` or ``"none"``).
|
|
134
|
+
precache_runtime: Whether the Python runtime is precached.
|
|
135
|
+
runtime: Runtime caching rules.
|
|
136
|
+
fallback_path: Optional offline fallback page path.
|
|
137
|
+
|
|
138
|
+
"""
|
|
139
|
+
|
|
140
|
+
enabled: bool = False
|
|
141
|
+
manifest: ManifestConfig | None = None
|
|
142
|
+
precache: Literal["auto", "none"] = "auto"
|
|
143
|
+
precache_runtime: bool = False
|
|
144
|
+
runtime: list[RuntimeCachingRule] = field(default_factory=list)
|
|
145
|
+
fallback_path: str | None = None
|
|
146
|
+
|
|
147
|
+
def validate(self, *, app_package_path: Path, static_files_dir: str) -> None:
|
|
148
|
+
"""Validate this configuration at build start.
|
|
149
|
+
|
|
150
|
+
A no-op when PWA is disabled. Called by the build pipeline before
|
|
151
|
+
artifacts are resolved so errors surface with actionable messages.
|
|
152
|
+
|
|
153
|
+
Args:
|
|
154
|
+
app_package_path: Filesystem path of the application package,
|
|
155
|
+
used to resolve the static files directory.
|
|
156
|
+
static_files_dir: Static files directory relative to the
|
|
157
|
+
application package path.
|
|
158
|
+
|
|
159
|
+
Raises:
|
|
160
|
+
WebComPyException: If any configured value is invalid or an
|
|
161
|
+
inconsistent combination is used.
|
|
162
|
+
|
|
163
|
+
"""
|
|
164
|
+
if not self.enabled:
|
|
165
|
+
return
|
|
166
|
+
if self.manifest is None:
|
|
167
|
+
raise WebComPyException("PWAConfig.enabled is True but no manifest is configured: set PWAConfig.manifest")
|
|
168
|
+
if self.precache not in _VALID_PRECACHE_MODES:
|
|
169
|
+
raise WebComPyException(
|
|
170
|
+
f"Invalid PWAConfig.precache: {self.precache!r}. Valid values: {_VALID_PRECACHE_MODES}"
|
|
171
|
+
)
|
|
172
|
+
if self.precache == "none" and self.precache_runtime:
|
|
173
|
+
raise WebComPyException(
|
|
174
|
+
"PWAConfig.precache_runtime cannot be enabled with precache='none': there is no precache to add runtime files to"
|
|
175
|
+
)
|
|
176
|
+
if self.manifest.display not in _VALID_DISPLAYS:
|
|
177
|
+
raise WebComPyException(
|
|
178
|
+
f"Invalid ManifestConfig.display: {self.manifest.display!r}. Valid values: {_VALID_DISPLAYS}"
|
|
179
|
+
)
|
|
180
|
+
for index, rule in enumerate(self.runtime):
|
|
181
|
+
label = f"PWAConfig.runtime[{index}]"
|
|
182
|
+
if not rule.pattern:
|
|
183
|
+
raise WebComPyException(f"{label}.pattern must be a non-empty path prefix or glob")
|
|
184
|
+
if "://" in rule.pattern:
|
|
185
|
+
raise WebComPyException(f"{label}.pattern must be a same-origin path pattern, got {rule.pattern!r}")
|
|
186
|
+
if rule.strategy not in _VALID_STRATEGIES:
|
|
187
|
+
raise WebComPyException(
|
|
188
|
+
f"{label}.strategy is invalid: {rule.strategy!r}. Valid values: {_VALID_STRATEGIES}"
|
|
189
|
+
)
|
|
190
|
+
for key in ("max_entries", "max_age"):
|
|
191
|
+
value = getattr(rule, key)
|
|
192
|
+
if value is not None and (isinstance(value, bool) or not isinstance(value, int) or value <= 0):
|
|
193
|
+
raise WebComPyException(f"{label}.{key} must be a positive int or None, got {value!r}")
|
|
194
|
+
if self.fallback_path is not None:
|
|
195
|
+
fallback = PurePosixPath(self.fallback_path)
|
|
196
|
+
if fallback.is_absolute() or ".." in fallback.parts or not str(fallback):
|
|
197
|
+
raise WebComPyException(
|
|
198
|
+
f"PWAConfig.fallback_path must be a relative path inside the static files directory, got {self.fallback_path!r}"
|
|
199
|
+
)
|
|
200
|
+
static_dir = app_package_path / static_files_dir
|
|
201
|
+
candidate = static_dir.joinpath(*fallback.parts)
|
|
202
|
+
if not candidate.is_file():
|
|
203
|
+
raise WebComPyException(f"PWAConfig.fallback_path does not exist: {candidate}")
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"""Server configuration dataclasses."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from collections.abc import Callable
|
|
6
|
+
from dataclasses import dataclass
|
|
7
|
+
from typing import TYPE_CHECKING
|
|
8
|
+
|
|
9
|
+
if TYPE_CHECKING:
|
|
10
|
+
from starlette.types import ASGIApp
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@dataclass
|
|
14
|
+
class WebComPyServerConfig:
|
|
15
|
+
"""Configuration for the development server and ASGI mounts.
|
|
16
|
+
|
|
17
|
+
Args:
|
|
18
|
+
port: TCP port the server listens on.
|
|
19
|
+
dev: Whether to run in development mode with live reload.
|
|
20
|
+
mounts: Callable returning additional ``{prefix: app}`` ASGI mounts.
|
|
21
|
+
|
|
22
|
+
Attributes:
|
|
23
|
+
port: TCP port the server listens on.
|
|
24
|
+
dev: Whether to run in development mode with live reload.
|
|
25
|
+
mounts: Callable returning additional ``{prefix: app}`` ASGI mounts.
|
|
26
|
+
|
|
27
|
+
"""
|
|
28
|
+
|
|
29
|
+
port: int = 8080
|
|
30
|
+
dev: bool = False
|
|
31
|
+
mounts: Callable[[], dict[str, ASGIApp]] | None = None
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
@dataclass
|
|
35
|
+
class LockfileSyncConfig:
|
|
36
|
+
"""Configuration for syncing the lock file with project manifests.
|
|
37
|
+
|
|
38
|
+
Args:
|
|
39
|
+
requirements_path: Path to the ``requirements.txt`` file used for
|
|
40
|
+
``sync`` and ``export``, or ``None`` to auto-discover.
|
|
41
|
+
sync_group: Optional dependency group name in ``pyproject.toml``
|
|
42
|
+
to compare against the lock file.
|
|
43
|
+
|
|
44
|
+
Attributes:
|
|
45
|
+
requirements_path: Path to the ``requirements.txt`` file used for
|
|
46
|
+
``sync`` and ``export``, or ``None`` to auto-discover.
|
|
47
|
+
sync_group: Optional dependency group name in ``pyproject.toml``
|
|
48
|
+
to compare against the lock file.
|
|
49
|
+
|
|
50
|
+
"""
|
|
51
|
+
|
|
52
|
+
requirements_path: str | None = None
|
|
53
|
+
sync_group: str | None = None
|
webcompy_cli/py.typed
ADDED
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"""Template application entry point."""
|
|
2
|
+
|
|
3
|
+
from webcompy.app import WebComPyApp, WebComPyAppConfig
|
|
4
|
+
|
|
5
|
+
from .components.root import AppRoot
|
|
6
|
+
from .router import router
|
|
7
|
+
|
|
8
|
+
app = WebComPyApp(
|
|
9
|
+
root_component=AppRoot,
|
|
10
|
+
router=router,
|
|
11
|
+
config=WebComPyAppConfig(base_url="/"),
|
|
12
|
+
)
|
|
13
|
+
app.set_head(
|
|
14
|
+
{
|
|
15
|
+
"title": "WebComPy Template",
|
|
16
|
+
"meta": {
|
|
17
|
+
"charset": {
|
|
18
|
+
"charset": "utf-8",
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
}
|
|
22
|
+
)
|
|
File without changes
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"""Template FizzBuzz demo component."""
|
|
2
|
+
|
|
3
|
+
from webcompy.components import (
|
|
4
|
+
ComponentContext,
|
|
5
|
+
define_component,
|
|
6
|
+
on_before_rendering,
|
|
7
|
+
)
|
|
8
|
+
from webcompy.elements import DOMEvent, html, repeat, switch
|
|
9
|
+
from webcompy.router import RouterContext
|
|
10
|
+
from webcompy.signal import Signal, use_computed, use_state
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@define_component()
|
|
14
|
+
def FizzbuzzList(context: ComponentContext[Signal[int]]):
|
|
15
|
+
@use_computed
|
|
16
|
+
def numbers():
|
|
17
|
+
li: list[str] = []
|
|
18
|
+
for n in range(1, context.props.value + 1):
|
|
19
|
+
if n % 15 == 0:
|
|
20
|
+
li.append("FizzBuzz")
|
|
21
|
+
elif n % 5 == 0:
|
|
22
|
+
li.append("Fizz")
|
|
23
|
+
elif n % 3 == 0:
|
|
24
|
+
li.append("Buzz")
|
|
25
|
+
else:
|
|
26
|
+
li.append(str(n))
|
|
27
|
+
return li
|
|
28
|
+
|
|
29
|
+
return html.DIV(
|
|
30
|
+
{},
|
|
31
|
+
html.UL(
|
|
32
|
+
{},
|
|
33
|
+
repeat(numbers, lambda s: html.LI({}, s)),
|
|
34
|
+
),
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
FizzbuzzList.scoped_style = {
|
|
39
|
+
"ul": {
|
|
40
|
+
"border": "dashed 2px #668ad8",
|
|
41
|
+
"background": "#f1f8ff",
|
|
42
|
+
"padding": "0.5em 0.5em 0.5em 2em",
|
|
43
|
+
},
|
|
44
|
+
"ul > li:nth-child(3n)": {
|
|
45
|
+
"color": "red",
|
|
46
|
+
},
|
|
47
|
+
"ul > li:nth-child(5n)": {
|
|
48
|
+
"color": "blue",
|
|
49
|
+
},
|
|
50
|
+
"ul > li:nth-child(15n)": {
|
|
51
|
+
"color": "purple",
|
|
52
|
+
},
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
@define_component()
|
|
57
|
+
def FizzbuzzPage(context: ComponentContext[RouterContext]):
|
|
58
|
+
context.set_title("FizzBuzz - WebComPy Template")
|
|
59
|
+
|
|
60
|
+
opened = use_state(lambda: True)
|
|
61
|
+
count = use_state(lambda: 10)
|
|
62
|
+
|
|
63
|
+
@use_computed
|
|
64
|
+
def toggle_button_text():
|
|
65
|
+
return "Hide" if opened.value else "Open"
|
|
66
|
+
|
|
67
|
+
@on_before_rendering
|
|
68
|
+
def reset_count():
|
|
69
|
+
count.value = 10
|
|
70
|
+
|
|
71
|
+
def add(ev: DOMEvent):
|
|
72
|
+
count.value += 1
|
|
73
|
+
|
|
74
|
+
def pop(ev: DOMEvent):
|
|
75
|
+
if count.value > 0:
|
|
76
|
+
count.value -= 1
|
|
77
|
+
|
|
78
|
+
def toggle(ev: DOMEvent):
|
|
79
|
+
opened.value = not opened.value
|
|
80
|
+
|
|
81
|
+
return html.DIV(
|
|
82
|
+
{},
|
|
83
|
+
html.H2(
|
|
84
|
+
{},
|
|
85
|
+
"FizzBuzz",
|
|
86
|
+
),
|
|
87
|
+
html.P(
|
|
88
|
+
{},
|
|
89
|
+
html.BUTTON(
|
|
90
|
+
{"@click": toggle},
|
|
91
|
+
toggle_button_text,
|
|
92
|
+
),
|
|
93
|
+
html.BUTTON(
|
|
94
|
+
{"@click": add},
|
|
95
|
+
"Add",
|
|
96
|
+
),
|
|
97
|
+
html.BUTTON(
|
|
98
|
+
{"@click": pop},
|
|
99
|
+
"Pop",
|
|
100
|
+
),
|
|
101
|
+
),
|
|
102
|
+
html.P(
|
|
103
|
+
{},
|
|
104
|
+
"Count: ",
|
|
105
|
+
count,
|
|
106
|
+
),
|
|
107
|
+
switch(
|
|
108
|
+
{
|
|
109
|
+
"case": opened,
|
|
110
|
+
"generator": lambda: FizzbuzzList(props=count),
|
|
111
|
+
},
|
|
112
|
+
default=lambda: html.DIV(
|
|
113
|
+
{},
|
|
114
|
+
"FizzBuzz Hidden",
|
|
115
|
+
),
|
|
116
|
+
),
|
|
117
|
+
)
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"""Template home page component."""
|
|
2
|
+
|
|
3
|
+
from webcompy.components import ComponentContext, define_component
|
|
4
|
+
from webcompy.elements import html
|
|
5
|
+
from webcompy.router import RouterContext
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@define_component()
|
|
9
|
+
def HomePage(context: ComponentContext[RouterContext]):
|
|
10
|
+
context.set_title("WebCompy Template")
|
|
11
|
+
|
|
12
|
+
return html.H3(
|
|
13
|
+
{},
|
|
14
|
+
"WebCompy Template",
|
|
15
|
+
)
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"""Template text input demo component."""
|
|
2
|
+
|
|
3
|
+
from webcompy.components import ComponentContext, define_component
|
|
4
|
+
from webcompy.elements import DOMEvent, html
|
|
5
|
+
from webcompy.router import RouterContext
|
|
6
|
+
from webcompy.signal import use_state
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@define_component()
|
|
10
|
+
def InOutSample(context: ComponentContext[RouterContext]):
|
|
11
|
+
context.set_title("Text Input Sample - WebCompy Template")
|
|
12
|
+
|
|
13
|
+
text = use_state(lambda: "")
|
|
14
|
+
|
|
15
|
+
def on_input(ev: DOMEvent):
|
|
16
|
+
assert ev.target is not None
|
|
17
|
+
text.value = ev.target.value
|
|
18
|
+
|
|
19
|
+
return html.DIV(
|
|
20
|
+
{},
|
|
21
|
+
html.H4({}, "Text Input Sample"),
|
|
22
|
+
html.P(
|
|
23
|
+
{},
|
|
24
|
+
"Input: ",
|
|
25
|
+
html.INPUT(
|
|
26
|
+
{"type": "text", "@input": on_input},
|
|
27
|
+
),
|
|
28
|
+
),
|
|
29
|
+
html.P(
|
|
30
|
+
{},
|
|
31
|
+
"Output: ",
|
|
32
|
+
text,
|
|
33
|
+
),
|
|
34
|
+
)
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"""Template navigation component."""
|
|
2
|
+
|
|
3
|
+
from webcompy.components import ComponentContext, define_component
|
|
4
|
+
from webcompy.elements import html
|
|
5
|
+
from webcompy.router import RouterLink
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@define_component()
|
|
9
|
+
def SiteNavigation(context: ComponentContext[None]):
|
|
10
|
+
return html.NAV(
|
|
11
|
+
{},
|
|
12
|
+
html.UL(
|
|
13
|
+
{},
|
|
14
|
+
html.LI(
|
|
15
|
+
{},
|
|
16
|
+
RouterLink(
|
|
17
|
+
to="/",
|
|
18
|
+
text=["Home"],
|
|
19
|
+
),
|
|
20
|
+
),
|
|
21
|
+
html.LI(
|
|
22
|
+
{},
|
|
23
|
+
RouterLink(
|
|
24
|
+
to="/fizzbuzz",
|
|
25
|
+
text=["FizzBuzz"],
|
|
26
|
+
),
|
|
27
|
+
),
|
|
28
|
+
html.LI(
|
|
29
|
+
{},
|
|
30
|
+
RouterLink(
|
|
31
|
+
to="/input",
|
|
32
|
+
text=["Text Input Sample"],
|
|
33
|
+
),
|
|
34
|
+
),
|
|
35
|
+
),
|
|
36
|
+
)
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"""Template not-found page component."""
|
|
2
|
+
|
|
3
|
+
from webcompy.components import ComponentContext, define_component
|
|
4
|
+
from webcompy.elements import html
|
|
5
|
+
from webcompy.router import RouterContext
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@define_component()
|
|
9
|
+
def NotFound(context: ComponentContext[RouterContext]):
|
|
10
|
+
context.set_title("NotFound - WebCompy Template")
|
|
11
|
+
|
|
12
|
+
return html.DIV(
|
|
13
|
+
{},
|
|
14
|
+
html.H3(
|
|
15
|
+
{},
|
|
16
|
+
"NotFound",
|
|
17
|
+
),
|
|
18
|
+
html.PRE(
|
|
19
|
+
{},
|
|
20
|
+
context.props.path,
|
|
21
|
+
),
|
|
22
|
+
)
|