dars-framework 1.0.62__tar.gz → 1.2.7__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.
- dars_framework-1.2.7/MANIFEST.in +7 -0
- dars_framework-1.2.7/PKG-INFO +245 -0
- dars_framework-1.2.7/README.md +228 -0
- {dars_framework-1.0.62 → dars_framework-1.2.7}/dars/all.py +14 -2
- dars_framework-1.2.7/dars/cli/doctor/__init__.py +1 -0
- dars_framework-1.2.7/dars/cli/doctor/detect.py +154 -0
- dars_framework-1.2.7/dars/cli/doctor/doctor.py +160 -0
- dars_framework-1.2.7/dars/cli/doctor/installers.py +100 -0
- dars_framework-1.2.7/dars/cli/doctor/persist.py +62 -0
- dars_framework-1.2.7/dars/cli/doctor/preflight.py +33 -0
- dars_framework-1.2.7/dars/cli/doctor/ui.py +67 -0
- dars_framework-1.2.7/dars/cli/main.py +1131 -0
- {dars_framework-1.0.62 → dars_framework-1.2.7}/dars/cli/preview.py +22 -1
- {dars_framework-1.0.62 → dars_framework-1.2.7}/dars/cli/translations.py +143 -1
- {dars_framework-1.0.62 → dars_framework-1.2.7}/dars/components/advanced/accordion.py +4 -3
- {dars_framework-1.0.62 → dars_framework-1.2.7}/dars/components/advanced/card.py +1 -1
- {dars_framework-1.0.62 → dars_framework-1.2.7}/dars/components/advanced/modal.py +1 -1
- {dars_framework-1.0.62 → dars_framework-1.2.7}/dars/components/advanced/navbar.py +1 -1
- {dars_framework-1.0.62 → dars_framework-1.2.7}/dars/components/advanced/table.py +5 -4
- {dars_framework-1.0.62 → dars_framework-1.2.7}/dars/components/advanced/tabs.py +5 -4
- {dars_framework-1.0.62 → dars_framework-1.2.7}/dars/components/basic/checkbox.py +3 -2
- {dars_framework-1.0.62 → dars_framework-1.2.7}/dars/components/basic/container.py +3 -2
- {dars_framework-1.0.62 → dars_framework-1.2.7}/dars/components/basic/image.py +1 -1
- {dars_framework-1.0.62 → dars_framework-1.2.7}/dars/components/basic/input.py +3 -2
- {dars_framework-1.0.62 → dars_framework-1.2.7}/dars/components/basic/link.py +1 -1
- dars_framework-1.2.7/dars/components/basic/markdown.py +86 -0
- {dars_framework-1.0.62 → dars_framework-1.2.7}/dars/components/basic/page.py +3 -3
- {dars_framework-1.0.62 → dars_framework-1.2.7}/dars/components/basic/progressbar.py +4 -3
- {dars_framework-1.0.62 → dars_framework-1.2.7}/dars/components/basic/radiobutton.py +3 -2
- {dars_framework-1.0.62 → dars_framework-1.2.7}/dars/components/basic/select.py +4 -3
- {dars_framework-1.0.62 → dars_framework-1.2.7}/dars/components/basic/spinner.py +2 -1
- {dars_framework-1.0.62 → dars_framework-1.2.7}/dars/components/basic/text.py +3 -2
- {dars_framework-1.0.62 → dars_framework-1.2.7}/dars/components/basic/textarea.py +1 -1
- {dars_framework-1.0.62 → dars_framework-1.2.7}/dars/components/basic/tooltip.py +5 -4
- dars_framework-1.2.7/dars/config.py +137 -0
- {dars_framework-1.0.62 → dars_framework-1.2.7}/dars/core/app.py +406 -105
- dars_framework-1.2.7/dars/core/component.py +291 -0
- {dars_framework-1.0.62 → dars_framework-1.2.7}/dars/core/events.py +11 -10
- dars_framework-1.2.7/dars/core/js_bridge.py +159 -0
- {dars_framework-1.0.62 → dars_framework-1.2.7}/dars/core/properties.py +4 -4
- dars_framework-1.2.7/dars/core/state.py +309 -0
- dars_framework-1.2.7/dars/dars_tests/apps_test/health_check.py +56 -0
- dars_framework-1.2.7/dars/dars_tests/run_tests.py +275 -0
- dars_framework-1.2.7/dars/dars_tests/tests/test_advanced_components.py +69 -0
- dars_framework-1.2.7/dars/dars_tests/tests/test_basic_components.py +88 -0
- dars_framework-1.2.7/dars/dars_tests/tests/test_core_and_cli.py +17 -0
- dars_framework-1.2.7/dars/dars_tests/tests/test_layout_components.py +58 -0
- dars_framework-1.2.7/dars/dars_tests/tests/test_version_check.py +21 -0
- dars_framework-1.2.7/dars/docs/app.md +290 -0
- dars_framework-1.2.7/dars/docs/cli.md +80 -0
- dars_framework-1.2.7/dars/docs/components.md +1679 -0
- dars_framework-1.2.7/dars/docs/custom_components.md +30 -0
- dars_framework-1.2.7/dars/docs/events.md +45 -0
- dars_framework-1.2.7/dars/docs/exporters.md +162 -0
- dars_framework-1.2.7/dars/docs/getting_started.md +79 -0
- dars_framework-1.2.7/dars/docs/index.md +18 -0
- dars_framework-1.2.7/dars/docs/scripts.md +593 -0
- dars_framework-1.2.7/dars/docs/state_management.md +57 -0
- {dars_framework-1.0.62 → dars_framework-1.2.7}/dars/exporters/base.py +31 -4
- dars_framework-1.2.7/dars/exporters/web/html_css_js.py +2733 -0
- dars_framework-1.2.7/dars/exporters/web/vdom.py +251 -0
- dars_framework-1.2.7/dars/js_lib.py +206 -0
- {dars_framework-1.0.62 → dars_framework-1.2.7}/dars/scripts/dscript.py +2 -2
- {dars_framework-1.0.62 → dars_framework-1.2.7}/dars/scripts/script.py +12 -11
- dars_framework-1.2.7/dars/security.py +242 -0
- dars_framework-1.2.7/dars/templates/__pycache__/__init__.cpython-311.pyc +0 -0
- dars_framework-1.2.7/dars/templates/examples/README.md +4 -0
- dars_framework-1.2.7/dars/templates/examples/__pycache__/dynamic_event_demo.cpython-311.pyc +0 -0
- {dars_framework-1.0.62/dars/templates/examples/advanced → dars_framework-1.2.7/dars/templates/examples/advanced/Modal_Demo}/advanced_modal_demo.py +2 -2
- {dars_framework-1.0.62/dars/templates/examples/advanced → dars_framework-1.2.7/dars/templates/examples/advanced/SimpleDashboard}/dashboard.py +1 -4
- dars_framework-1.2.7/dars/templates/examples/advanced/dState/state_mods_demo.py +68 -0
- {dars_framework-1.0.62/dars/templates/examples/basic → dars_framework-1.2.7/dars/templates/examples/basic/Forms}/form_components.py +2 -2
- dars_framework-1.2.7/dars/templates/examples/basic/HelloWorld/hello_world.py +56 -0
- {dars_framework-1.0.62/dars/templates/examples/basic → dars_framework-1.2.7/dars/templates/examples/basic/Layouts}/flex_layout_responsive.py +1 -1
- {dars_framework-1.0.62/dars/templates/examples/basic → dars_framework-1.2.7/dars/templates/examples/basic/Layouts}/grid_layout_responsive.py +2 -3
- {dars_framework-1.0.62/dars/templates/examples/basic → dars_framework-1.2.7/dars/templates/examples/basic/Layouts}/layout_multipage_demo.py +1 -1
- {dars_framework-1.0.62/dars/templates/examples/basic → dars_framework-1.2.7/dars/templates/examples/basic/Multipage}/multipage_example.py +1 -4
- dars_framework-1.2.7/dars/templates/examples/basic/PWA/icon-192x192.png +0 -0
- dars_framework-1.2.7/dars/templates/examples/basic/PWA/icon-512x512.png +0 -0
- {dars_framework-1.0.62/dars/templates/examples/basic → dars_framework-1.2.7/dars/templates/examples/basic/PWA}/pwa_custom_icons.py +7 -3
- dars_framework-1.2.7/dars/templates/examples/basic/__init__.py +0 -0
- dars_framework-1.2.7/dars/templates/examples/demo/__pycache__/complete_app.cpython-311.pyc +0 -0
- dars_framework-1.2.7/dars/templates/examples/demo/complete_app.py +21 -0
- dars_framework-1.2.7/dars/templates/examples/markdown/MarkdownTemplate/README.md +159 -0
- dars_framework-1.2.7/dars/templates/examples/markdown/MarkdownTemplate/markdown_template.py +21 -0
- dars_framework-1.2.7/dars/templates/examples/markdown/MarkdownTemplate/other_docs.md +1 -0
- dars_framework-1.2.7/dars/templates/examples/markdown/__init__.py +0 -0
- dars_framework-1.2.7/dars/templates/html/__init__.py +0 -0
- {dars_framework-1.0.62 → dars_framework-1.2.7}/dars/version.py +2 -2
- dars_framework-1.2.7/dars_framework.egg-info/PKG-INFO +245 -0
- dars_framework-1.2.7/dars_framework.egg-info/SOURCES.txt +122 -0
- dars_framework-1.2.7/dars_framework.egg-info/requires.txt +7 -0
- dars_framework-1.2.7/pyproject.toml +21 -0
- dars_framework-1.0.62/PKG-INFO +0 -148
- dars_framework-1.0.62/README.md +0 -115
- dars_framework-1.0.62/dars/cli/main.py +0 -659
- dars_framework-1.0.62/dars/core/component.py +0 -172
- dars_framework-1.0.62/dars/templates/examples/basic/hello_world.py +0 -104
- dars_framework-1.0.62/dars/templates/examples/demo/complete_app.py +0 -720
- dars_framework-1.0.62/dars_framework.egg-info/PKG-INFO +0 -148
- dars_framework-1.0.62/dars_framework.egg-info/SOURCES.txt +0 -76
- dars_framework-1.0.62/dars_framework.egg-info/requires.txt +0 -2
- dars_framework-1.0.62/pyproject.toml +0 -20
- {dars_framework-1.0.62 → dars_framework-1.2.7}/LICENSE +0 -0
- {dars_framework-1.0.62 → dars_framework-1.2.7}/dars/__init__.py +0 -0
- {dars_framework-1.0.62 → dars_framework-1.2.7}/dars/cli/__init__.py +0 -0
- {dars_framework-1.0.62 → dars_framework-1.2.7}/dars/cli/hot_reload.py +0 -0
- {dars_framework-1.0.62 → dars_framework-1.2.7}/dars/components/__init__.py +0 -0
- {dars_framework-1.0.62 → dars_framework-1.2.7}/dars/components/advanced/__init__.py +0 -0
- {dars_framework-1.0.62 → dars_framework-1.2.7}/dars/components/basic/__init__.py +0 -0
- {dars_framework-1.0.62 → dars_framework-1.2.7}/dars/components/basic/button.py +0 -0
- {dars_framework-1.0.62 → dars_framework-1.2.7}/dars/components/basic/datepicker.py +0 -0
- {dars_framework-1.0.62 → dars_framework-1.2.7}/dars/components/basic/slider.py +0 -0
- {dars_framework-1.0.62 → dars_framework-1.2.7}/dars/components/layout/__init__.py +0 -0
- {dars_framework-1.0.62 → dars_framework-1.2.7}/dars/components/layout/anchor.py +0 -0
- {dars_framework-1.0.62 → dars_framework-1.2.7}/dars/components/layout/flex.py +0 -0
- {dars_framework-1.0.62 → dars_framework-1.2.7}/dars/components/layout/grid.py +0 -0
- {dars_framework-1.0.62 → dars_framework-1.2.7}/dars/core/__init__.py +0 -0
- {dars_framework-1.0.62 → dars_framework-1.2.7}/dars/docs/__init__.py +0 -0
- {dars_framework-1.0.62 → dars_framework-1.2.7}/dars/exporters/__init__.py +0 -0
- /dars_framework-1.0.62/dars/exporters/web/html_css_js.py → /dars_framework-1.2.7/dars/exporters/web/OLD/html_css_js_OLD4.py +0 -0
- {dars_framework-1.0.62 → dars_framework-1.2.7}/dars/exporters/web/OLD/html_css_js_old.py +0 -0
- {dars_framework-1.0.62 → dars_framework-1.2.7}/dars/exporters/web/OLD/html_css_js_old2.py +0 -0
- {dars_framework-1.0.62 → dars_framework-1.2.7}/dars/exporters/web/__init__.py +0 -0
- {dars_framework-1.0.62 → dars_framework-1.2.7}/dars/scripts/__init__.py +0 -0
- {dars_framework-1.0.62 → dars_framework-1.2.7}/dars/templates/__init__.py +0 -0
- {dars_framework-1.0.62/dars/templates/examples/advanced → dars_framework-1.2.7/dars/templates/examples/advanced/SimpleModermWeb}/modern_web_app.py +0 -0
- {dars_framework-1.0.62/dars/templates/examples/advanced → dars_framework-1.2.7/dars/templates/examples/advanced/VariousComponents}/all_components_demo.py +0 -0
- {dars_framework-1.0.62/dars/templates/html → dars_framework-1.2.7/dars/templates/examples/advanced}/__init__.py +0 -0
- {dars_framework-1.0.62/dars/templates/examples/basic → dars_framework-1.2.7/dars/templates/examples/basic/Forms}/simple_form.py +0 -0
- {dars_framework-1.0.62 → dars_framework-1.2.7}/dars_framework.egg-info/dependency_links.txt +0 -0
- {dars_framework-1.0.62 → dars_framework-1.2.7}/dars_framework.egg-info/entry_points.txt +0 -0
- {dars_framework-1.0.62 → dars_framework-1.2.7}/dars_framework.egg-info/top_level.txt +0 -0
- {dars_framework-1.0.62 → dars_framework-1.2.7}/setup.cfg +0 -0
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: dars_framework
|
|
3
|
+
Version: 1.2.7
|
|
4
|
+
Summary: Dars is a Python UI framework for building modern, interactive web apps with only Python code. Write your interface in Python, export it to static HTML/CSS/JS, and deploy anywhere.
|
|
5
|
+
Author-email: ztamdev <ztadevs@gmail.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Requires-Dist: rich==14.2.0
|
|
10
|
+
Requires-Dist: bs4==0.0.2
|
|
11
|
+
Requires-Dist: uvicorn==0.35.0
|
|
12
|
+
Requires-Dist: fastapi==0.116.1
|
|
13
|
+
Requires-Dist: markdown2==2.5.4
|
|
14
|
+
Requires-Dist: requests==2.32.5
|
|
15
|
+
Requires-Dist: rjsmin==1.2.5
|
|
16
|
+
Dynamic: license-file
|
|
17
|
+
|
|
18
|
+
<h1 align="center">Dars Framework</h1>
|
|
19
|
+
|
|
20
|
+
<p align="center">
|
|
21
|
+
<img src="./Dars-logo.png" alt="Dars Framework Logo" width="200" />
|
|
22
|
+
</p>
|
|
23
|
+
|
|
24
|
+
<p align="center">
|
|
25
|
+
<em>Dars is a Python UI framework for building modern, interactive web apps with Python code. Write your interface in Python, export it to static HTML/CSS/JS, and deploy anywhere.</em>
|
|
26
|
+
</p>
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
pip install dars-framework
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
> Some Javascript or frontend stack required.
|
|
33
|
+
|
|
34
|
+
Try dars without installing nothing just visit the [Dars Playground](https://dars-playground.vercel.app/)
|
|
35
|
+
|
|
36
|
+
## How It Works
|
|
37
|
+
- Build your UI using Python classes and components (like Text, Button, Container, Page, etc).
|
|
38
|
+
- Preview instantly with hot-reload using `app.rTimeCompile()`.
|
|
39
|
+
- Export your app to static web files with a single CLI command.
|
|
40
|
+
- Use multipage, layouts, scripts, and more—see docs for advanced features.
|
|
41
|
+
- For more information visit the [Documentation](https://ztamdev.github.io/Dars-Framework/documentation.html)
|
|
42
|
+
|
|
43
|
+
## Quick Example: Your First App
|
|
44
|
+
```python
|
|
45
|
+
from dars.all import *
|
|
46
|
+
|
|
47
|
+
app = App(title="Hello World", theme="dark")
|
|
48
|
+
# Crear componentes
|
|
49
|
+
index = Page(
|
|
50
|
+
Text(
|
|
51
|
+
text="Hello World",
|
|
52
|
+
style={
|
|
53
|
+
'font-size': '48px',
|
|
54
|
+
'color': '#2c3e50',
|
|
55
|
+
'margin-bottom': '20px',
|
|
56
|
+
'font-weight': 'bold',
|
|
57
|
+
'text-align': 'center'
|
|
58
|
+
}
|
|
59
|
+
),
|
|
60
|
+
Text(
|
|
61
|
+
text="Hello World",
|
|
62
|
+
style={
|
|
63
|
+
'font-size': '20px',
|
|
64
|
+
'color': '#7f8c8d',
|
|
65
|
+
'margin-bottom': '40px',
|
|
66
|
+
'text-align': 'center'
|
|
67
|
+
}
|
|
68
|
+
),
|
|
69
|
+
|
|
70
|
+
Button(
|
|
71
|
+
text="Click Me!",
|
|
72
|
+
on_click= dScript("alert('Hello World')"),
|
|
73
|
+
on_mouse_enter=dScript("this.style.backgroundColor = '#2980b9';"),
|
|
74
|
+
on_mouse_leave=dScript("this.style.backgroundColor = '#3498db';"),
|
|
75
|
+
style={
|
|
76
|
+
'background-color': '#3498db',
|
|
77
|
+
'color': 'white',
|
|
78
|
+
'padding': '15px 30px',
|
|
79
|
+
'border': 'none',
|
|
80
|
+
'border-radius': '8px',
|
|
81
|
+
'font-size': '18px',
|
|
82
|
+
'cursor': 'pointer',
|
|
83
|
+
'transition': 'background-color 0.3s'
|
|
84
|
+
}
|
|
85
|
+
),
|
|
86
|
+
style={
|
|
87
|
+
'display': 'flex',
|
|
88
|
+
'flex-direction': 'column',
|
|
89
|
+
'align-items': 'center',
|
|
90
|
+
'justify-content': 'center',
|
|
91
|
+
'min-height': '100vh',
|
|
92
|
+
'background-color': '#f0f2f5',
|
|
93
|
+
'font-family': 'Arial, sans-serif'
|
|
94
|
+
}
|
|
95
|
+
)
|
|
96
|
+
index.attr()
|
|
97
|
+
app.add_page("index", index, title="Hello World", index=True)
|
|
98
|
+
|
|
99
|
+
if __name__ == "__main__":
|
|
100
|
+
app.rTimeCompile()
|
|
101
|
+
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
---
|
|
105
|
+
|
|
106
|
+
## Reactivity and State System
|
|
107
|
+
|
|
108
|
+
**Dars Framework** includes a built-in **reactive state system** (`dState` / `cState`) that allows dynamic and modular DOM updates directly from Python.
|
|
109
|
+
It enables fully event-driven interfaces without requiring manual JavaScript.
|
|
110
|
+
|
|
111
|
+
### Key Concepts
|
|
112
|
+
|
|
113
|
+
* **`dState(name, component, states)`**
|
|
114
|
+
Creates a reactive state controller bound to a specific component and a list of possible states.
|
|
115
|
+
|
|
116
|
+
* **`cState(idx, mods=[...])`**
|
|
117
|
+
Defines rules (modifications) that are automatically applied when entering a specific state.
|
|
118
|
+
|
|
119
|
+
* **`Mod` Helpers**
|
|
120
|
+
A compact way to modify DOM elements on state changes: `inc`, `dec`, `set`, `toggle_class`, `append_text`, `prepend_text`, `goto`, and more.
|
|
121
|
+
|
|
122
|
+
* **Deferred Mutations**
|
|
123
|
+
Using `component.attr(..., defer=True)` or `component.mod(...)` inside a `cComp=True` state defers HTML updates until an event occurs, preventing authoring-time mutations.
|
|
124
|
+
|
|
125
|
+
### Example Template
|
|
126
|
+
|
|
127
|
+
A complete example demonstrating `dState`, `cState`, `Mod`, and deferred updates is available [here](https://github.com/ZtaMDev/Dars-Framework/blob/CrystalMain/dars/templates/examples/advanced/dState/state_mods_demo.py)
|
|
128
|
+
|
|
129
|
+
<img width="384" height="187" alt="imagen" src="https://github.com/user-attachments/assets/7750ee7f-768f-48da-94df-2fa00339a99c" /> <img width="361" height="215" alt="imagen" src="https://github.com/user-attachments/assets/9b8a3e67-2424-49b4-aee0-9f1c0f747d66" />
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
### Features
|
|
134
|
+
|
|
135
|
+
* Reactive Mod system with compact `Mod` helpers
|
|
136
|
+
* Unified event model — any component can use `on_*` props (`on_click`, `on_input`, `on_change`, etc.)
|
|
137
|
+
* Deferred rendering for safer, predictable state transitions (`cComp=True`)
|
|
138
|
+
* Navigation between states using `goto`, including relative moves (`'+1'`, `'-1'`)
|
|
139
|
+
* Consistent, event-time mutation flow for reliable behavior
|
|
140
|
+
* Secure minification for production bundles (strong JS/CSS minifier integrated into the build pipeline)
|
|
141
|
+
|
|
142
|
+
---
|
|
143
|
+
|
|
144
|
+
## CLI Usage
|
|
145
|
+
| Command | What it does |
|
|
146
|
+
|-----------------------------------------|--------------------------------------------|
|
|
147
|
+
| `dars export my_app.py --format html` | Export app to HTML/CSS/JS in `./my_app_web` |
|
|
148
|
+
| `dars preview ./my_app_web` | Preview exported app locally |
|
|
149
|
+
| `dars init my_project` | Create a new Dars project (also creates dars.config.json) |
|
|
150
|
+
| `dars init --update` | Create/Update dars.config.json in current dir |
|
|
151
|
+
| `dars build` | Build using dars.config.json (entry/outdir/format) |
|
|
152
|
+
| `dars config validate` | Validate dars.config.json and print report |
|
|
153
|
+
| `dars info my_app.py` | Show info about your app |
|
|
154
|
+
| `dars formats` | List supported export formats |
|
|
155
|
+
| `dars --help` | Show help and all CLI options |
|
|
156
|
+
|
|
157
|
+
Tip: use `dars doctor` to review optional tooling that can enhance bundling/minification.
|
|
158
|
+
|
|
159
|
+
## More
|
|
160
|
+
|
|
161
|
+
- Visit dars [official website](https://ztamdev.github.io/Dars-Framework/)
|
|
162
|
+
- Visit the dars official [Documentation](https://ztamdev.github.io/Dars-Framework/documentation.html) now on separate website.
|
|
163
|
+
- Try dars without installing nothing just visit the [Dars Playground](https://dars-playground.vercel.app/)
|
|
164
|
+
|
|
165
|
+
## Local Execution and Live Preview
|
|
166
|
+
|
|
167
|
+
To test your app locally before exporting, use the hot-reload preview from any Python file that defines your app:
|
|
168
|
+
|
|
169
|
+
```python
|
|
170
|
+
if __name__ == "__main__":
|
|
171
|
+
app.rTimeCompile()
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
Then run your file directly:
|
|
175
|
+
|
|
176
|
+
```bash
|
|
177
|
+
python my_app.py
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
This will start a local server at http://localhost:8000 so you can view your app in the browser—no manual export needed. You can change the port with:
|
|
181
|
+
|
|
182
|
+
```bash
|
|
183
|
+
python my_app.py --port 8088
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
---
|
|
187
|
+
|
|
188
|
+
You can also use the CLI preview command on an exported app:
|
|
189
|
+
|
|
190
|
+
```bash
|
|
191
|
+
dars preview ./my_exported_app
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
This will start a local server at http://localhost:8000 to view your exported app in the browser.
|
|
195
|
+
|
|
196
|
+
---
|
|
197
|
+
|
|
198
|
+
## Project Configuration (dars.config.json)
|
|
199
|
+
|
|
200
|
+
Dars can read build/export settings from a `dars.config.json` at your project root. It is created automatically by `dars init`, and you can add it to existing projects with `dars init --update`.
|
|
201
|
+
|
|
202
|
+
Example default:
|
|
203
|
+
|
|
204
|
+
```json
|
|
205
|
+
{
|
|
206
|
+
"entry": "main.py",
|
|
207
|
+
"format": "html",
|
|
208
|
+
"outdir": "dist",
|
|
209
|
+
"publicDir": null,
|
|
210
|
+
"include": [],
|
|
211
|
+
"exclude": ["**/__pycache__", ".git", ".venv", "node_modules"],
|
|
212
|
+
"bundle": true,
|
|
213
|
+
"viteMinify": true
|
|
214
|
+
}
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
- `entry`: Python entry file. Used by `dars build` and `dars export config`.
|
|
218
|
+
- `format`: Export format. Currently only `html` is supported.
|
|
219
|
+
- `outdir`: Output directory. Used by `dars build` and default for `dars export` when not overridden.
|
|
220
|
+
- `publicDir`: Folder (e.g., `public/` or `assets/`) copied into the output. If null, it is autodetected.
|
|
221
|
+
- `include`/`exclude`: Basic filters for copying from `publicDir`.
|
|
222
|
+
- `bundle`: Reserved for future use. CLI exports and build already bundle appropriately.
|
|
223
|
+
- `viteMinify`: Toggle the Vite-based minifier for JS. When `false`, the build uses esbuild-based minification. If neither is available, a conservative Python fallback is used.
|
|
224
|
+
|
|
225
|
+
Validate your config:
|
|
226
|
+
|
|
227
|
+
```bash
|
|
228
|
+
dars config validate
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
Build using config:
|
|
232
|
+
|
|
233
|
+
```bash
|
|
234
|
+
dars build
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
Export using the config entry and outdir:
|
|
238
|
+
|
|
239
|
+
```bash
|
|
240
|
+
dars export config --format html
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
---
|
|
244
|
+
|
|
245
|
+
See LandingPage docs for details: state_management.md, events.md, scripts.md.
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
<h1 align="center">Dars Framework</h1>
|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
<img src="./Dars-logo.png" alt="Dars Framework Logo" width="200" />
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
<p align="center">
|
|
8
|
+
<em>Dars is a Python UI framework for building modern, interactive web apps with Python code. Write your interface in Python, export it to static HTML/CSS/JS, and deploy anywhere.</em>
|
|
9
|
+
</p>
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pip install dars-framework
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
> Some Javascript or frontend stack required.
|
|
16
|
+
|
|
17
|
+
Try dars without installing nothing just visit the [Dars Playground](https://dars-playground.vercel.app/)
|
|
18
|
+
|
|
19
|
+
## How It Works
|
|
20
|
+
- Build your UI using Python classes and components (like Text, Button, Container, Page, etc).
|
|
21
|
+
- Preview instantly with hot-reload using `app.rTimeCompile()`.
|
|
22
|
+
- Export your app to static web files with a single CLI command.
|
|
23
|
+
- Use multipage, layouts, scripts, and more—see docs for advanced features.
|
|
24
|
+
- For more information visit the [Documentation](https://ztamdev.github.io/Dars-Framework/documentation.html)
|
|
25
|
+
|
|
26
|
+
## Quick Example: Your First App
|
|
27
|
+
```python
|
|
28
|
+
from dars.all import *
|
|
29
|
+
|
|
30
|
+
app = App(title="Hello World", theme="dark")
|
|
31
|
+
# Crear componentes
|
|
32
|
+
index = Page(
|
|
33
|
+
Text(
|
|
34
|
+
text="Hello World",
|
|
35
|
+
style={
|
|
36
|
+
'font-size': '48px',
|
|
37
|
+
'color': '#2c3e50',
|
|
38
|
+
'margin-bottom': '20px',
|
|
39
|
+
'font-weight': 'bold',
|
|
40
|
+
'text-align': 'center'
|
|
41
|
+
}
|
|
42
|
+
),
|
|
43
|
+
Text(
|
|
44
|
+
text="Hello World",
|
|
45
|
+
style={
|
|
46
|
+
'font-size': '20px',
|
|
47
|
+
'color': '#7f8c8d',
|
|
48
|
+
'margin-bottom': '40px',
|
|
49
|
+
'text-align': 'center'
|
|
50
|
+
}
|
|
51
|
+
),
|
|
52
|
+
|
|
53
|
+
Button(
|
|
54
|
+
text="Click Me!",
|
|
55
|
+
on_click= dScript("alert('Hello World')"),
|
|
56
|
+
on_mouse_enter=dScript("this.style.backgroundColor = '#2980b9';"),
|
|
57
|
+
on_mouse_leave=dScript("this.style.backgroundColor = '#3498db';"),
|
|
58
|
+
style={
|
|
59
|
+
'background-color': '#3498db',
|
|
60
|
+
'color': 'white',
|
|
61
|
+
'padding': '15px 30px',
|
|
62
|
+
'border': 'none',
|
|
63
|
+
'border-radius': '8px',
|
|
64
|
+
'font-size': '18px',
|
|
65
|
+
'cursor': 'pointer',
|
|
66
|
+
'transition': 'background-color 0.3s'
|
|
67
|
+
}
|
|
68
|
+
),
|
|
69
|
+
style={
|
|
70
|
+
'display': 'flex',
|
|
71
|
+
'flex-direction': 'column',
|
|
72
|
+
'align-items': 'center',
|
|
73
|
+
'justify-content': 'center',
|
|
74
|
+
'min-height': '100vh',
|
|
75
|
+
'background-color': '#f0f2f5',
|
|
76
|
+
'font-family': 'Arial, sans-serif'
|
|
77
|
+
}
|
|
78
|
+
)
|
|
79
|
+
index.attr()
|
|
80
|
+
app.add_page("index", index, title="Hello World", index=True)
|
|
81
|
+
|
|
82
|
+
if __name__ == "__main__":
|
|
83
|
+
app.rTimeCompile()
|
|
84
|
+
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
---
|
|
88
|
+
|
|
89
|
+
## Reactivity and State System
|
|
90
|
+
|
|
91
|
+
**Dars Framework** includes a built-in **reactive state system** (`dState` / `cState`) that allows dynamic and modular DOM updates directly from Python.
|
|
92
|
+
It enables fully event-driven interfaces without requiring manual JavaScript.
|
|
93
|
+
|
|
94
|
+
### Key Concepts
|
|
95
|
+
|
|
96
|
+
* **`dState(name, component, states)`**
|
|
97
|
+
Creates a reactive state controller bound to a specific component and a list of possible states.
|
|
98
|
+
|
|
99
|
+
* **`cState(idx, mods=[...])`**
|
|
100
|
+
Defines rules (modifications) that are automatically applied when entering a specific state.
|
|
101
|
+
|
|
102
|
+
* **`Mod` Helpers**
|
|
103
|
+
A compact way to modify DOM elements on state changes: `inc`, `dec`, `set`, `toggle_class`, `append_text`, `prepend_text`, `goto`, and more.
|
|
104
|
+
|
|
105
|
+
* **Deferred Mutations**
|
|
106
|
+
Using `component.attr(..., defer=True)` or `component.mod(...)` inside a `cComp=True` state defers HTML updates until an event occurs, preventing authoring-time mutations.
|
|
107
|
+
|
|
108
|
+
### Example Template
|
|
109
|
+
|
|
110
|
+
A complete example demonstrating `dState`, `cState`, `Mod`, and deferred updates is available [here](https://github.com/ZtaMDev/Dars-Framework/blob/CrystalMain/dars/templates/examples/advanced/dState/state_mods_demo.py)
|
|
111
|
+
|
|
112
|
+
<img width="384" height="187" alt="imagen" src="https://github.com/user-attachments/assets/7750ee7f-768f-48da-94df-2fa00339a99c" /> <img width="361" height="215" alt="imagen" src="https://github.com/user-attachments/assets/9b8a3e67-2424-49b4-aee0-9f1c0f747d66" />
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
### Features
|
|
117
|
+
|
|
118
|
+
* Reactive Mod system with compact `Mod` helpers
|
|
119
|
+
* Unified event model — any component can use `on_*` props (`on_click`, `on_input`, `on_change`, etc.)
|
|
120
|
+
* Deferred rendering for safer, predictable state transitions (`cComp=True`)
|
|
121
|
+
* Navigation between states using `goto`, including relative moves (`'+1'`, `'-1'`)
|
|
122
|
+
* Consistent, event-time mutation flow for reliable behavior
|
|
123
|
+
* Secure minification for production bundles (strong JS/CSS minifier integrated into the build pipeline)
|
|
124
|
+
|
|
125
|
+
---
|
|
126
|
+
|
|
127
|
+
## CLI Usage
|
|
128
|
+
| Command | What it does |
|
|
129
|
+
|-----------------------------------------|--------------------------------------------|
|
|
130
|
+
| `dars export my_app.py --format html` | Export app to HTML/CSS/JS in `./my_app_web` |
|
|
131
|
+
| `dars preview ./my_app_web` | Preview exported app locally |
|
|
132
|
+
| `dars init my_project` | Create a new Dars project (also creates dars.config.json) |
|
|
133
|
+
| `dars init --update` | Create/Update dars.config.json in current dir |
|
|
134
|
+
| `dars build` | Build using dars.config.json (entry/outdir/format) |
|
|
135
|
+
| `dars config validate` | Validate dars.config.json and print report |
|
|
136
|
+
| `dars info my_app.py` | Show info about your app |
|
|
137
|
+
| `dars formats` | List supported export formats |
|
|
138
|
+
| `dars --help` | Show help and all CLI options |
|
|
139
|
+
|
|
140
|
+
Tip: use `dars doctor` to review optional tooling that can enhance bundling/minification.
|
|
141
|
+
|
|
142
|
+
## More
|
|
143
|
+
|
|
144
|
+
- Visit dars [official website](https://ztamdev.github.io/Dars-Framework/)
|
|
145
|
+
- Visit the dars official [Documentation](https://ztamdev.github.io/Dars-Framework/documentation.html) now on separate website.
|
|
146
|
+
- Try dars without installing nothing just visit the [Dars Playground](https://dars-playground.vercel.app/)
|
|
147
|
+
|
|
148
|
+
## Local Execution and Live Preview
|
|
149
|
+
|
|
150
|
+
To test your app locally before exporting, use the hot-reload preview from any Python file that defines your app:
|
|
151
|
+
|
|
152
|
+
```python
|
|
153
|
+
if __name__ == "__main__":
|
|
154
|
+
app.rTimeCompile()
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
Then run your file directly:
|
|
158
|
+
|
|
159
|
+
```bash
|
|
160
|
+
python my_app.py
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
This will start a local server at http://localhost:8000 so you can view your app in the browser—no manual export needed. You can change the port with:
|
|
164
|
+
|
|
165
|
+
```bash
|
|
166
|
+
python my_app.py --port 8088
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
---
|
|
170
|
+
|
|
171
|
+
You can also use the CLI preview command on an exported app:
|
|
172
|
+
|
|
173
|
+
```bash
|
|
174
|
+
dars preview ./my_exported_app
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
This will start a local server at http://localhost:8000 to view your exported app in the browser.
|
|
178
|
+
|
|
179
|
+
---
|
|
180
|
+
|
|
181
|
+
## Project Configuration (dars.config.json)
|
|
182
|
+
|
|
183
|
+
Dars can read build/export settings from a `dars.config.json` at your project root. It is created automatically by `dars init`, and you can add it to existing projects with `dars init --update`.
|
|
184
|
+
|
|
185
|
+
Example default:
|
|
186
|
+
|
|
187
|
+
```json
|
|
188
|
+
{
|
|
189
|
+
"entry": "main.py",
|
|
190
|
+
"format": "html",
|
|
191
|
+
"outdir": "dist",
|
|
192
|
+
"publicDir": null,
|
|
193
|
+
"include": [],
|
|
194
|
+
"exclude": ["**/__pycache__", ".git", ".venv", "node_modules"],
|
|
195
|
+
"bundle": true,
|
|
196
|
+
"viteMinify": true
|
|
197
|
+
}
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
- `entry`: Python entry file. Used by `dars build` and `dars export config`.
|
|
201
|
+
- `format`: Export format. Currently only `html` is supported.
|
|
202
|
+
- `outdir`: Output directory. Used by `dars build` and default for `dars export` when not overridden.
|
|
203
|
+
- `publicDir`: Folder (e.g., `public/` or `assets/`) copied into the output. If null, it is autodetected.
|
|
204
|
+
- `include`/`exclude`: Basic filters for copying from `publicDir`.
|
|
205
|
+
- `bundle`: Reserved for future use. CLI exports and build already bundle appropriately.
|
|
206
|
+
- `viteMinify`: Toggle the Vite-based minifier for JS. When `false`, the build uses esbuild-based minification. If neither is available, a conservative Python fallback is used.
|
|
207
|
+
|
|
208
|
+
Validate your config:
|
|
209
|
+
|
|
210
|
+
```bash
|
|
211
|
+
dars config validate
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
Build using config:
|
|
215
|
+
|
|
216
|
+
```bash
|
|
217
|
+
dars build
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
Export using the config entry and outdir:
|
|
221
|
+
|
|
222
|
+
```bash
|
|
223
|
+
dars export config --format html
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
---
|
|
227
|
+
|
|
228
|
+
See LandingPage docs for details: state_management.md, events.md, scripts.md.
|
|
@@ -24,6 +24,7 @@ from dars.components.basic.spinner import Spinner
|
|
|
24
24
|
from dars.components.basic.text import Text
|
|
25
25
|
from dars.components.basic.textarea import Textarea
|
|
26
26
|
from dars.components.basic.tooltip import Tooltip
|
|
27
|
+
from dars.components.basic.markdown import Markdown
|
|
27
28
|
|
|
28
29
|
# Advanced Components
|
|
29
30
|
from dars.components.advanced.accordion import Accordion
|
|
@@ -33,6 +34,7 @@ from dars.components.advanced.navbar import Navbar
|
|
|
33
34
|
from dars.components.advanced.table import Table
|
|
34
35
|
from dars.components.advanced.tabs import Tabs
|
|
35
36
|
|
|
37
|
+
|
|
36
38
|
# Layout
|
|
37
39
|
from dars.components.layout.grid import GridLayout, LayoutBase
|
|
38
40
|
from dars.components.layout.flex import FlexLayout
|
|
@@ -42,10 +44,16 @@ from dars.scripts.script import *
|
|
|
42
44
|
from dars.scripts.dscript import dScript
|
|
43
45
|
|
|
44
46
|
# Exporters (optional, for direct use)
|
|
45
|
-
|
|
47
|
+
from dars.exporters.web.html_css_js import HTMLCSSJSExporter
|
|
48
|
+
from dars.core.events import EventTypes
|
|
49
|
+
from dars.core.events import EventHandler, EventEmitter, EventManager
|
|
46
50
|
|
|
51
|
+
from dars.version import __version__
|
|
52
|
+
from dars.dars_tests import *
|
|
53
|
+
from dars.dars_tests.run_tests import run_app_tests, run_unit_tests, main
|
|
47
54
|
# CLI (optional, for advanced usage)
|
|
48
55
|
# from dars.cli.main import main as dars_cli_main
|
|
56
|
+
from dars.core.state import dState, Mod
|
|
49
57
|
|
|
50
58
|
__all__ = [
|
|
51
59
|
'App', 'Component', 'EventManager',
|
|
@@ -53,5 +61,9 @@ __all__ = [
|
|
|
53
61
|
'RadioButton', 'Select', 'Slider', 'Spinner', 'Text', 'Textarea', 'Tooltip',
|
|
54
62
|
'Accordion', 'Card', 'Modal', 'Navbar', 'Table', 'Tabs',
|
|
55
63
|
'GridLayout', 'FlexLayout', 'LayoutBase', 'AnchorPoint',
|
|
56
|
-
'InlineScript', 'FileScript', 'dScript',
|
|
64
|
+
'InlineScript', 'FileScript', 'dScript', 'HTMLCSSJSExporter',
|
|
65
|
+
'EventTypes', 'EventHandler', 'EventEmitter', 'EventManager', 'Markdown',
|
|
66
|
+
'__version__',
|
|
67
|
+
'run_app_tests', 'run_unit_tests', 'main',
|
|
68
|
+
'dState', 'Mod',
|
|
57
69
|
]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# dars.cli.doctor package
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import os, subprocess, sys, re
|
|
2
|
+
from typing import Tuple, Optional, List, Dict
|
|
3
|
+
from dars.core.js_bridge import has_bun, has_node, _run as js_run
|
|
4
|
+
|
|
5
|
+
SEMVER_RE = re.compile(r"v?(\d+)\.(\d+)\.(\d+)")
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def _run(cmd: List[str]) -> Tuple[int, str, str]:
|
|
9
|
+
try:
|
|
10
|
+
p = subprocess.run(cmd, capture_output=True, text=True, shell=False)
|
|
11
|
+
return p.returncode, p.stdout.strip(), p.stderr.strip()
|
|
12
|
+
except Exception as e:
|
|
13
|
+
return 1, "", str(e)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def which(bin_name: str) -> Optional[str]:
|
|
17
|
+
if os.name == 'nt':
|
|
18
|
+
code, out, _ = _run(["where", bin_name])
|
|
19
|
+
else:
|
|
20
|
+
code, out, _ = _run(["which", bin_name])
|
|
21
|
+
if code == 0 and out:
|
|
22
|
+
return out.splitlines()[0].strip()
|
|
23
|
+
return None
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def parse_semver(s: str) -> Optional[str]:
|
|
27
|
+
m = SEMVER_RE.search(s or "")
|
|
28
|
+
if not m:
|
|
29
|
+
return None
|
|
30
|
+
return f"{m.group(1)}.{m.group(2)}.{m.group(3)}"
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def detect_node() -> Dict[str, Optional[str]]:
|
|
34
|
+
path = which("node")
|
|
35
|
+
if not path:
|
|
36
|
+
return {"ok": False, "version": None, "path": None}
|
|
37
|
+
code, out, _ = _run([path, "--version"]) # prints like v18.19.1
|
|
38
|
+
ver = parse_semver(out)
|
|
39
|
+
return {"ok": bool(ver), "version": ver, "path": path}
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def detect_esbuild() -> Dict[str, Optional[str]]:
|
|
43
|
+
# Prefer bun x esbuild --version
|
|
44
|
+
if has_bun():
|
|
45
|
+
code, out, err = js_run(["bun", "x", "esbuild", "--version"]) # type: ignore
|
|
46
|
+
if code == 0:
|
|
47
|
+
return {"ok": True, "version": out.strip() or "unknown", "path": "bun x esbuild"}
|
|
48
|
+
# Node fallback
|
|
49
|
+
if has_node():
|
|
50
|
+
code, out, err = js_run(["npx", "--yes", "esbuild", "--version"]) # type: ignore
|
|
51
|
+
if code == 0:
|
|
52
|
+
return {"ok": True, "version": out.strip() or "unknown", "path": "npx esbuild"}
|
|
53
|
+
return {"ok": False, "version": None, "path": None}
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def detect_vite() -> Dict[str, Optional[str]]:
|
|
57
|
+
# Prefer bun x vite --version
|
|
58
|
+
if has_bun():
|
|
59
|
+
code, out, err = js_run(["bun", "x", "vite", "--version"]) # type: ignore
|
|
60
|
+
if code == 0:
|
|
61
|
+
return {"ok": True, "version": out.strip() or "unknown", "path": "bun x vite"}
|
|
62
|
+
if has_node():
|
|
63
|
+
code, out, err = js_run(["npx", "--yes", "vite", "--version"]) # type: ignore
|
|
64
|
+
if code == 0:
|
|
65
|
+
return {"ok": True, "version": out.strip() or "unknown", "path": "npx vite"}
|
|
66
|
+
return {"ok": False, "version": None, "path": None}
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def detect_bun() -> Dict[str, Optional[str]]:
|
|
70
|
+
path = which("bun")
|
|
71
|
+
if not path:
|
|
72
|
+
return {"ok": False, "version": None, "path": None}
|
|
73
|
+
code, out, _ = _run([path, "--version"]) # prints like 1.1.24
|
|
74
|
+
ver = parse_semver(out) or out.strip()
|
|
75
|
+
return {"ok": bool(ver), "version": ver, "path": path}
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def read_pyproject_deps(pyproject_path: Optional[str] = None) -> List[str]:
|
|
79
|
+
"""Extract [project].dependencies items as a list of requirement strings.
|
|
80
|
+
Avoids pulling unrelated keys (e.g., license).
|
|
81
|
+
"""
|
|
82
|
+
path = pyproject_path or os.path.join(os.getcwd(), "pyproject.toml")
|
|
83
|
+
if not os.path.isfile(path):
|
|
84
|
+
return []
|
|
85
|
+
try:
|
|
86
|
+
with open(path, 'r', encoding='utf-8') as f:
|
|
87
|
+
lines = f.readlines()
|
|
88
|
+
reqs: List[str] = []
|
|
89
|
+
in_project = False
|
|
90
|
+
in_array = False
|
|
91
|
+
buf: List[str] = []
|
|
92
|
+
for raw in lines:
|
|
93
|
+
l = raw.strip()
|
|
94
|
+
# Track project table
|
|
95
|
+
if l.startswith('['):
|
|
96
|
+
in_project = (l == '[project]')
|
|
97
|
+
# leaving dependencies array if we hit a new table
|
|
98
|
+
if l != '[project]':
|
|
99
|
+
in_array = False
|
|
100
|
+
continue
|
|
101
|
+
if not in_project:
|
|
102
|
+
continue
|
|
103
|
+
# Find dependencies array start
|
|
104
|
+
if not in_array and l.startswith('dependencies') and '=' in l:
|
|
105
|
+
# Could be inline or multiline
|
|
106
|
+
# Normalize to everything after '='
|
|
107
|
+
after = l.split('=', 1)[1].strip()
|
|
108
|
+
if after.startswith('[') and after.endswith(']'):
|
|
109
|
+
# Inline array
|
|
110
|
+
buf = [after]
|
|
111
|
+
in_array = False
|
|
112
|
+
elif after.startswith('['):
|
|
113
|
+
buf = [after]
|
|
114
|
+
in_array = True
|
|
115
|
+
else:
|
|
116
|
+
# Malformed; skip
|
|
117
|
+
buf = []
|
|
118
|
+
in_array = False
|
|
119
|
+
# If inline, fall-through to extraction below
|
|
120
|
+
elif in_array:
|
|
121
|
+
buf.append(l)
|
|
122
|
+
if ']' in l:
|
|
123
|
+
in_array = False
|
|
124
|
+
# When we have a complete buffer (inline or closed multiline), extract
|
|
125
|
+
if buf and not in_array:
|
|
126
|
+
content = ' '.join(buf)
|
|
127
|
+
# Extract quoted items within brackets
|
|
128
|
+
m = re.findall(r'"([^"\\]*(?:\\.[^"\\]*)*)"', content)
|
|
129
|
+
for item in m:
|
|
130
|
+
if item:
|
|
131
|
+
reqs.append(item)
|
|
132
|
+
buf = []
|
|
133
|
+
return reqs
|
|
134
|
+
except Exception:
|
|
135
|
+
return []
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def check_python_deps(requirements: List[str]) -> Dict[str, List[str]]:
|
|
139
|
+
missing: List[str] = []
|
|
140
|
+
try:
|
|
141
|
+
try:
|
|
142
|
+
import importlib.metadata as md # py3.8+
|
|
143
|
+
except Exception:
|
|
144
|
+
import importlib_metadata as md # type: ignore
|
|
145
|
+
for spec in requirements:
|
|
146
|
+
name = spec.split("==")[0].split(">=")[0].split("<=")[0]
|
|
147
|
+
try:
|
|
148
|
+
md.version(name)
|
|
149
|
+
except Exception:
|
|
150
|
+
missing.append(spec)
|
|
151
|
+
except Exception:
|
|
152
|
+
# if detection fails, don't block
|
|
153
|
+
pass
|
|
154
|
+
return {"missing": missing}
|