pyview-web 0.2.4__py3-none-any.whl → 0.2.5__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.
Potentially problematic release.
This version of pyview-web might be problematic. Click here for more details.
- pyview/cli/__init__.py +0 -0
- pyview/cli/commands/__init__.py +0 -0
- pyview/cli/commands/create_view.py +199 -0
- pyview/cli/main.py +17 -0
- {pyview_web-0.2.4.dist-info → pyview_web-0.2.5.dist-info}/METADATA +3 -3
- {pyview_web-0.2.4.dist-info → pyview_web-0.2.5.dist-info}/RECORD +9 -4
- pyview_web-0.2.5.dist-info/entry_points.txt +3 -0
- {pyview_web-0.2.4.dist-info → pyview_web-0.2.5.dist-info}/LICENSE +0 -0
- {pyview_web-0.2.4.dist-info → pyview_web-0.2.5.dist-info}/WHEEL +0 -0
pyview/cli/__init__.py
ADDED
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import click
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
import tomllib
|
|
4
|
+
from typing import Optional
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def snake_case(name: str) -> str:
|
|
8
|
+
"""Convert PascalCase or camelCase to snake_case."""
|
|
9
|
+
import re
|
|
10
|
+
|
|
11
|
+
s1 = re.sub("(.)([A-Z][a-z]+)", r"\1_\2", name)
|
|
12
|
+
return re.sub("([a-z0-9])([A-Z])", r"\1_\2", s1).lower()
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def pascal_case(name: str) -> str:
|
|
16
|
+
"""Convert snake_case or other formats to PascalCase."""
|
|
17
|
+
# If already in PascalCase or camelCase, convert to snake_case first
|
|
18
|
+
snake_name = snake_case(name)
|
|
19
|
+
return "".join(word.capitalize() for word in snake_name.split("_"))
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def kebab_case(name: str) -> str:
|
|
23
|
+
"""Convert any case to kebab-case."""
|
|
24
|
+
return snake_case(name).replace("_", "-")
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def generate_python_file(name: str) -> str:
|
|
28
|
+
"""Generate the Python LiveView file content."""
|
|
29
|
+
class_name = f"{pascal_case(name)}LiveView"
|
|
30
|
+
context_name = f"{pascal_case(name)}Context"
|
|
31
|
+
|
|
32
|
+
return f"""from pyview import LiveView, LiveViewSocket
|
|
33
|
+
from dataclasses import dataclass
|
|
34
|
+
from pyview.events import event, BaseEventHandler
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
@dataclass
|
|
38
|
+
class {context_name}:
|
|
39
|
+
pass
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class {class_name}(BaseEventHandler, LiveView[{context_name}]):
|
|
43
|
+
async def mount(self, socket: LiveViewSocket[{context_name}], session):
|
|
44
|
+
socket.context = {context_name}()
|
|
45
|
+
"""
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def generate_html_file(name: str) -> str:
|
|
49
|
+
"""Generate the HTML template file content."""
|
|
50
|
+
css_class = kebab_case(name)
|
|
51
|
+
return f'''<div class="{css_class}-container">
|
|
52
|
+
<h1>{pascal_case(name)}</h1>
|
|
53
|
+
|
|
54
|
+
<div class="content">
|
|
55
|
+
<!-- Add your content here -->
|
|
56
|
+
</div>
|
|
57
|
+
</div>
|
|
58
|
+
'''
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def generate_css_file(name: str) -> str:
|
|
62
|
+
"""Generate the CSS file content."""
|
|
63
|
+
css_class = kebab_case(name)
|
|
64
|
+
return f""".{css_class}-container {{
|
|
65
|
+
padding: 1rem;
|
|
66
|
+
}}
|
|
67
|
+
|
|
68
|
+
.{css_class}-container h1 {{
|
|
69
|
+
margin-bottom: 1rem;
|
|
70
|
+
}}
|
|
71
|
+
|
|
72
|
+
.{css_class}-container .content {{
|
|
73
|
+
/* Add your styles here */
|
|
74
|
+
}}
|
|
75
|
+
"""
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def generate_init_file(name: str) -> str:
|
|
79
|
+
"""Generate the __init__.py file content."""
|
|
80
|
+
module_name = snake_case(name)
|
|
81
|
+
class_name = f"{pascal_case(name)}LiveView"
|
|
82
|
+
|
|
83
|
+
return f'''from .{module_name} import {class_name}
|
|
84
|
+
|
|
85
|
+
__all__ = ["{class_name}"]
|
|
86
|
+
'''
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def detect_package_structure(directory: Optional[Path] = None):
|
|
90
|
+
"""Detect the package structure from pyproject.toml.
|
|
91
|
+
|
|
92
|
+
Args:
|
|
93
|
+
directory: Directory to look for pyproject.toml in. Defaults to current directory.
|
|
94
|
+
|
|
95
|
+
Returns:
|
|
96
|
+
tuple: (package_name, views_path)
|
|
97
|
+
"""
|
|
98
|
+
if directory is None:
|
|
99
|
+
directory = Path.cwd()
|
|
100
|
+
|
|
101
|
+
pyproject_path = directory / "pyproject.toml"
|
|
102
|
+
|
|
103
|
+
if not pyproject_path.exists():
|
|
104
|
+
return None, "views"
|
|
105
|
+
|
|
106
|
+
try:
|
|
107
|
+
with open(pyproject_path, "rb") as f:
|
|
108
|
+
config = tomllib.load(f)
|
|
109
|
+
except Exception:
|
|
110
|
+
return None, "views"
|
|
111
|
+
|
|
112
|
+
# Check for packages configuration
|
|
113
|
+
packages = config.get("tool", {}).get("poetry", {}).get("packages", [])
|
|
114
|
+
if not packages:
|
|
115
|
+
# Check for modern pyproject.toml structure
|
|
116
|
+
packages = config.get("project", {}).get("packages", [])
|
|
117
|
+
|
|
118
|
+
if not packages:
|
|
119
|
+
return None, "views"
|
|
120
|
+
|
|
121
|
+
# Find the first package entry
|
|
122
|
+
for package in packages:
|
|
123
|
+
if isinstance(package, dict) and "include" in package:
|
|
124
|
+
package_name = package["include"]
|
|
125
|
+
from_dir = package.get("from", ".")
|
|
126
|
+
|
|
127
|
+
# Construct the path where views should go
|
|
128
|
+
if from_dir == ".":
|
|
129
|
+
package_path = Path(package_name)
|
|
130
|
+
else:
|
|
131
|
+
package_path = Path(from_dir) / package_name
|
|
132
|
+
|
|
133
|
+
views_path = package_path / "views"
|
|
134
|
+
return package_name, str(views_path)
|
|
135
|
+
|
|
136
|
+
return None, "views"
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
@click.command()
|
|
140
|
+
@click.argument("name")
|
|
141
|
+
@click.option(
|
|
142
|
+
"--path",
|
|
143
|
+
"-p",
|
|
144
|
+
default=None,
|
|
145
|
+
help="Directory to create the view in (default: auto-detect from pyproject.toml)",
|
|
146
|
+
)
|
|
147
|
+
@click.option("--no-css", is_flag=True, help="Skip creating CSS file")
|
|
148
|
+
def create_view(name: str, path: Optional[str], no_css: bool):
|
|
149
|
+
"""Create a new LiveView with boilerplate files.
|
|
150
|
+
|
|
151
|
+
Example: pv create-view Counter
|
|
152
|
+
"""
|
|
153
|
+
module_name = snake_case(name)
|
|
154
|
+
|
|
155
|
+
# Always try to detect package structure for import advice
|
|
156
|
+
package_name, detected_path = detect_package_structure()
|
|
157
|
+
|
|
158
|
+
# Use detected path if no path specified, otherwise use provided path
|
|
159
|
+
if path is None:
|
|
160
|
+
path = detected_path
|
|
161
|
+
|
|
162
|
+
view_dir = Path(path) / module_name
|
|
163
|
+
|
|
164
|
+
# Check if directory already exists
|
|
165
|
+
if view_dir.exists():
|
|
166
|
+
click.secho(f"Error: Directory '{view_dir}' already exists", fg="red")
|
|
167
|
+
raise click.Abort()
|
|
168
|
+
|
|
169
|
+
view_dir.mkdir(parents=True, exist_ok=True)
|
|
170
|
+
click.secho(f"Created directory: {view_dir}", fg="green")
|
|
171
|
+
|
|
172
|
+
# Generate files
|
|
173
|
+
files_to_create = [
|
|
174
|
+
("__init__.py", generate_init_file(name)),
|
|
175
|
+
(f"{module_name}.py", generate_python_file(name)),
|
|
176
|
+
(f"{module_name}.html", generate_html_file(name)),
|
|
177
|
+
]
|
|
178
|
+
|
|
179
|
+
if not no_css:
|
|
180
|
+
files_to_create.append((f"{module_name}.css", generate_css_file(name)))
|
|
181
|
+
|
|
182
|
+
# Create files
|
|
183
|
+
for filename, content in files_to_create:
|
|
184
|
+
file_path = view_dir / filename
|
|
185
|
+
file_path.write_text(content)
|
|
186
|
+
click.secho(f"Created: {file_path}", fg="green")
|
|
187
|
+
|
|
188
|
+
class_name = f"{pascal_case(name)}LiveView"
|
|
189
|
+
click.echo("\nLiveView created successfully! 🎉")
|
|
190
|
+
click.echo("\nTo use this view, add it to your app:")
|
|
191
|
+
|
|
192
|
+
# import statement based on detected package structure
|
|
193
|
+
if package_name:
|
|
194
|
+
import_path = f"{package_name}.views.{module_name}"
|
|
195
|
+
else:
|
|
196
|
+
import_path = f"{path.replace('/', '.')}.{module_name}"
|
|
197
|
+
|
|
198
|
+
click.echo(f" from {import_path} import {class_name}")
|
|
199
|
+
click.echo(f" app.add_live_view('/{module_name}', {class_name})")
|
pyview/cli/main.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import click
|
|
2
|
+
|
|
3
|
+
from pyview.cli.commands.create_view import create_view
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
@click.group()
|
|
7
|
+
@click.version_option(package_name="pyview-web")
|
|
8
|
+
def cli():
|
|
9
|
+
"""PyView CLI - Generate boilerplate for LiveView applications."""
|
|
10
|
+
pass
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
cli.add_command(create_view)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
if __name__ == "__main__":
|
|
17
|
+
cli()
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: pyview-web
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.5
|
|
4
4
|
Summary: LiveView in Python
|
|
5
5
|
License: MIT
|
|
6
6
|
Keywords: web,api,LiveView
|
|
7
7
|
Author: Larry Ogrodnek
|
|
8
8
|
Author-email: ogrodnek@gmail.com
|
|
9
|
-
Requires-Python: >=3.
|
|
9
|
+
Requires-Python: >=3.11,<3.13
|
|
10
10
|
Classifier: Development Status :: 4 - Beta
|
|
11
11
|
Classifier: Environment :: Web Environment
|
|
12
12
|
Classifier: Framework :: AsyncIO
|
|
@@ -18,7 +18,6 @@ Classifier: License :: OSI Approved :: MIT License
|
|
|
18
18
|
Classifier: Operating System :: OS Independent
|
|
19
19
|
Classifier: Programming Language :: Python
|
|
20
20
|
Classifier: Programming Language :: Python :: 3
|
|
21
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
22
21
|
Classifier: Programming Language :: Python :: 3.11
|
|
23
22
|
Classifier: Programming Language :: Python :: 3.12
|
|
24
23
|
Classifier: Programming Language :: Python :: 3 :: Only
|
|
@@ -31,6 +30,7 @@ Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
|
|
|
31
30
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
32
31
|
Classifier: Typing :: Typed
|
|
33
32
|
Requires-Dist: APScheduler (==3.9.1.post1)
|
|
33
|
+
Requires-Dist: click (>=8.1.7,<9.0.0)
|
|
34
34
|
Requires-Dist: itsdangerous (>=2.1.2,<3.0.0)
|
|
35
35
|
Requires-Dist: markupsafe (>=2.1.2,<3.0.0)
|
|
36
36
|
Requires-Dist: psutil (>=5.9.4,<6.0.0)
|
|
@@ -8,6 +8,10 @@ pyview/auth/provider.py,sha256=fwriy2JZcOStutVXD-8VlMPAFXjILCM0l08lhTgmuyE,935
|
|
|
8
8
|
pyview/auth/required.py,sha256=ZtNmLFth9nK39RxDiJkSzArXwS5Cvr55MUAzfJ1F2e0,1418
|
|
9
9
|
pyview/changesets/__init__.py,sha256=55CLari2JHZtwy4hapHe7CqUyKjcP4dkM_t5d3CY2gU,46
|
|
10
10
|
pyview/changesets/changesets.py,sha256=hImmvB_jS6RyLr5Mas5L7DO_0d805jR3c41LKJlnNL4,1720
|
|
11
|
+
pyview/cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
12
|
+
pyview/cli/commands/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
13
|
+
pyview/cli/commands/create_view.py,sha256=9hrjc1J1sJHyp3Ihi5ls4Mj19OMNeaj6fpIwDFWrdZ8,5694
|
|
14
|
+
pyview/cli/main.py,sha256=OEHqNwl9fqIPTI6qy5sLYndPHMEJ3fA9qsjSUuKzYSE,296
|
|
11
15
|
pyview/csrf.py,sha256=VIURva9EJqXXYGC7engweh3SwDQCnHlhV2zWdcdnFqc,789
|
|
12
16
|
pyview/events/BaseEventHandler.py,sha256=0xcjFFMLMN8Aj6toI31vzeYhRQqaX9rm-G7XGXMvqsE,1923
|
|
13
17
|
pyview/events/__init__.py,sha256=oP0SG4Af4uf0GEa0Y_zHYhR7TcBOcXQlTAsgOSaIcC4,156
|
|
@@ -45,7 +49,8 @@ pyview/vendor/ibis/template.py,sha256=6XJXnztw87CrOaKeW3e18LL0fNM8AI6AaK_QgMdb7e
|
|
|
45
49
|
pyview/vendor/ibis/tree.py,sha256=hg8f-fKHeo6DE8R-QgAhdvEaZ8rKyz7p0nGwPy0CBTs,2509
|
|
46
50
|
pyview/vendor/ibis/utils.py,sha256=nLSaxPR9vMphzV9qinlz_Iurv9c49Ps6Knv8vyNlewU,2768
|
|
47
51
|
pyview/ws_handler.py,sha256=CY1iDx5GETjIkqhgFbo2fkE3FhrqucSdg4AjuJ2P0Qg,9041
|
|
48
|
-
pyview_web-0.2.
|
|
49
|
-
pyview_web-0.2.
|
|
50
|
-
pyview_web-0.2.
|
|
51
|
-
pyview_web-0.2.
|
|
52
|
+
pyview_web-0.2.5.dist-info/LICENSE,sha256=M_bADaBm9_MV9llX3lCicksLhwk3eZUjA2srE0uUWr0,1071
|
|
53
|
+
pyview_web-0.2.5.dist-info/METADATA,sha256=3g39-VhWx0gWkq1B46NAkTTTDSqnOr692TkFZtgOrNo,5243
|
|
54
|
+
pyview_web-0.2.5.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
|
|
55
|
+
pyview_web-0.2.5.dist-info/entry_points.txt,sha256=GAT-ic-VYmmSMUSUVKdV1bp4w-vgEeVP-XzElvarQ9U,42
|
|
56
|
+
pyview_web-0.2.5.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|