litestar-vite 0.13.2__py3-none-any.whl → 0.14.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of litestar-vite might be problematic. Click here for more details.

litestar_vite/commands.py CHANGED
@@ -4,18 +4,22 @@ from collections.abc import MutableMapping
4
4
  from pathlib import Path
5
5
  from typing import TYPE_CHECKING, Any, Optional, Union
6
6
 
7
+ from litestar_vite.config import JINJA_INSTALLED
8
+ from litestar_vite.exceptions import MissingDependencyError
9
+
7
10
  if TYPE_CHECKING:
8
11
  from collections.abc import MutableMapping
9
12
 
10
13
  from jinja2 import Environment, Template
11
14
  from litestar import Litestar
12
15
 
16
+
13
17
  VITE_INIT_TEMPLATES: "set[str]" = {"package.json.j2", "tsconfig.json.j2", "vite.config.ts.j2"}
14
18
  DEFAULT_RESOURCES: "set[str]" = {"styles.css.j2", "main.ts.j2"}
15
19
  DEFAULT_DEV_DEPENDENCIES: "dict[str, str]" = {
16
20
  "typescript": "^5.8.3",
17
21
  "vite": "^6.3.5",
18
- "litestar-vite-plugin": "^0.13.2",
22
+ "litestar-vite-plugin": "^0.14.0",
19
23
  "@types/node": "^22.15.3",
20
24
  }
21
25
  DEFAULT_DEPENDENCIES: "dict[str, str]" = {"axios": "^1.9.0"}
@@ -60,11 +64,17 @@ def init_vite(
60
64
  vite_port: Port for Vite dev server.
61
65
  hot_file: Path to hot reload manifest.
62
66
  litestar_port: Port for Litestar server.
67
+
68
+ Raises:
69
+ MissingDependencyError: If required dependencies are not installed.
63
70
  """
64
- from jinja2 import Environment, FileSystemLoader, select_autoescape
65
71
  from litestar.cli._utils import console # pyright: ignore[reportPrivateImportUsage]
66
72
  from litestar.utils import module_loader
67
73
 
74
+ if not JINJA_INSTALLED:
75
+ raise MissingDependencyError(package="jinja2", install_package="jinja")
76
+ from jinja2 import Environment, FileSystemLoader, select_autoescape
77
+
68
78
  template_path = module_loader.module_to_os_path("litestar_vite.templates")
69
79
  vite_template_env = Environment(
70
80
  loader=FileSystemLoader([template_path]),
@@ -128,6 +138,23 @@ def get_template(
128
138
  parent: "Optional[str]" = None,
129
139
  globals: "Optional[MutableMapping[str, Any]]" = None, # noqa: A002
130
140
  ) -> "Template":
141
+ """Get a template from the Jinja environment.
142
+
143
+ Args:
144
+ environment: The Jinja :class:`jinja2.Environment`.
145
+ name: Template name or :class:`jinja2.Template` object.
146
+ parent: Parent template name.
147
+ globals: Global variables for the template.
148
+
149
+ Returns:
150
+ The :class:`jinja2.Template` object.
151
+
152
+ Raises:
153
+ MissingDependencyError: If Jinja2 is not available.
154
+ """
155
+ if not JINJA_INSTALLED:
156
+ raise MissingDependencyError(package="jinja2", install_package="jinja")
157
+
131
158
  return environment.get_template(name=name, parent=parent, globals=globals)
132
159
 
133
160
 
litestar_vite/config.py CHANGED
@@ -1,10 +1,13 @@
1
1
  import os
2
2
  from dataclasses import dataclass, field
3
+ from importlib.util import find_spec
3
4
  from pathlib import Path
4
5
  from typing import Union
5
6
 
6
- __all__ = ("ViteConfig",)
7
+ __all__ = ("JINJA_INSTALLED", "ViteConfig")
8
+
7
9
  TRUE_VALUES = {"True", "true", "1", "yes", "Y", "T"}
10
+ JINJA_INSTALLED = bool(find_spec("jinja2"))
8
11
 
9
12
 
10
13
  @dataclass
@@ -0,0 +1,26 @@
1
+ """Litestar-Vite exception classes."""
2
+
3
+ from __future__ import annotations
4
+
5
+ __all__ = ["LitestarViteError", "MissingDependencyError"]
6
+
7
+
8
+ class LitestarViteError(Exception):
9
+ """Base exception for Litestar-Vite related errors."""
10
+
11
+
12
+ class MissingDependencyError(LitestarViteError, ImportError):
13
+ """Raised when a package is not installed but required."""
14
+
15
+ def __init__(self, package: str, install_package: str | None = None) -> None:
16
+ """Initialize the exception.
17
+
18
+ Args:
19
+ package: The name of the missing package.
20
+ install_package: Optional alternative package name for installation.
21
+ """
22
+ super().__init__(
23
+ f"Package {package!r} is not installed but required. You can install it by running "
24
+ f"'pip install litestar-vite[{install_package or package}]' to install litestar-vite with the required extra "
25
+ f"or 'pip install {install_package or package}' to install the package separately"
26
+ )
litestar_vite/plugin.py CHANGED
@@ -9,10 +9,11 @@ from pathlib import Path
9
9
  from typing import TYPE_CHECKING, Any, Optional, Union
10
10
 
11
11
  from litestar.cli._utils import console # pyright: ignore[reportPrivateImportUsage]
12
- from litestar.contrib.jinja import JinjaTemplateEngine
13
12
  from litestar.plugins import CLIPlugin, InitPluginProtocol
14
13
  from litestar.static_files import create_static_files_router # pyright: ignore[reportUnknownVariableType]
15
14
 
15
+ from litestar_vite.config import JINJA_INSTALLED
16
+
16
17
  if TYPE_CHECKING:
17
18
  from collections.abc import Iterator, Sequence
18
19
 
@@ -163,15 +164,21 @@ class VitePlugin(InitPluginProtocol, CLIPlugin):
163
164
  """
164
165
  from litestar_vite.loader import render_asset_tag, render_hmr_client
165
166
 
166
- if app_config.template_config and isinstance(app_config.template_config.engine_instance, JinjaTemplateEngine): # pyright: ignore[reportUnknownMemberType]
167
- app_config.template_config.engine_instance.register_template_callable( # pyright: ignore[reportUnknownMemberType]
168
- key="vite_hmr",
169
- template_callable=render_hmr_client,
170
- )
171
- app_config.template_config.engine_instance.register_template_callable( # pyright: ignore[reportUnknownMemberType]
172
- key="vite",
173
- template_callable=render_asset_tag,
174
- )
167
+ if JINJA_INSTALLED:
168
+ from litestar.contrib.jinja import JinjaTemplateEngine
169
+
170
+ if (
171
+ app_config.template_config # pyright: ignore[reportUnknownMemberType]
172
+ and isinstance(app_config.template_config.engine_instance, JinjaTemplateEngine) # pyright: ignore[reportUnknownMemberType]
173
+ ):
174
+ app_config.template_config.engine_instance.register_template_callable( # pyright: ignore[reportUnknownMemberType]
175
+ key="vite_hmr",
176
+ template_callable=render_hmr_client,
177
+ )
178
+ app_config.template_config.engine_instance.register_template_callable( # pyright: ignore[reportUnknownMemberType]
179
+ key="vite",
180
+ template_callable=render_asset_tag,
181
+ )
175
182
  if self._config.set_static_folders:
176
183
  static_dirs = [Path(self._config.bundle_dir), Path(self._config.resource_dir)]
177
184
  if Path(self._config.public_dir).exists() and self._config.public_dir != self._config.bundle_dir:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: litestar-vite
3
- Version: 0.13.2
3
+ Version: 0.14.0
4
4
  Summary: Vite plugin for Litestar
5
5
  Project-URL: Changelog, https://cofin.github.io/litestar-vite/latest/changelog
6
6
  Project-URL: Discord, https://discord.gg/X3FJqy8d2j
@@ -29,7 +29,9 @@ Classifier: Topic :: Database :: Database Engines/Servers
29
29
  Classifier: Topic :: Software Development
30
30
  Classifier: Typing :: Typed
31
31
  Requires-Python: >=3.9
32
- Requires-Dist: litestar[jinja]>=2.7.0
32
+ Requires-Dist: litestar>=2.7.0
33
+ Provides-Extra: jinja
34
+ Requires-Dist: jinja2; extra == 'jinja'
33
35
  Provides-Extra: nodeenv
34
36
  Requires-Dist: nodeenv; extra == 'nodeenv'
35
37
  Description-Content-Type: text/markdown
@@ -73,7 +75,7 @@ app = Litestar(plugins=[vite], template_config=template_config, route_handlers=[
73
75
 
74
76
  ```
75
77
 
76
- Create a template to serve the application in `./templates/index.html.h2`:
78
+ Create a template to serve the application in `./templates/index.html.j2`:
77
79
 
78
80
  ```html
79
81
  <!DOCTYPE html>
@@ -1,10 +1,11 @@
1
1
  litestar_vite/__init__.py,sha256=QykOZjCNHyDZJNIF84fa-6ze-lajDAGcoi18LxeV-0E,241
2
2
  litestar_vite/__metadata__.py,sha256=dMGIPS6M11LcmiEfnMJJrbSPH8Lf00pU8crIIUsIBPw,478
3
3
  litestar_vite/cli.py,sha256=W3bpXZSt_ne0pdDZQCGi_naMEakp7MA-oD_r1BJI0cQ,11058
4
- litestar_vite/commands.py,sha256=XrQ6vIbcJYEANrO1nJwawb3DYOXt-1GGVYfJYWsYc6c,5385
5
- litestar_vite/config.py,sha256=K3C3uhfcllINGAkOUS4tTah-mhhx74GYwNF4ME92eOA,4592
4
+ litestar_vite/commands.py,sha256=aHubdOrSim0RFtJX5zg9UkfXyQN53Q_PB058quGlUfw,6218
5
+ litestar_vite/config.py,sha256=gWnXhWw4XggC82bWQEa2BtqxzR_AdhqZeRuLYvYy3N4,4692
6
+ litestar_vite/exceptions.py,sha256=E37ficSm9V8iMYTPThtLX0Dm0gsK80rV8a0IT8I0MGo,991
6
7
  litestar_vite/loader.py,sha256=opF-YJh0fnu1cpH2uJ4aLmK9PZpsREa4yEEajYV9yVs,11802
7
- litestar_vite/plugin.py,sha256=uyGlJZBl46DpKoHmxkdkNUvZ2SyYI0Q3MXcDwYytweo,9132
8
+ litestar_vite/plugin.py,sha256=4b3I9yc73YAZcnnT_1jvCzN_5s-jFlzS0tHBZwLHyHg,9351
8
9
  litestar_vite/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
10
  litestar_vite/inertia/__init__.py,sha256=KGvxCZhnOw06Pqx5_qjUxj0WWsCR3BR0cVnuNMT7sKQ,1136
10
11
  litestar_vite/inertia/_utils.py,sha256=HZOedWduCu3fCMniuFvstEcXzP2FA1IBwPZ3E2XNBEo,2529
@@ -24,7 +25,7 @@ litestar_vite/templates/package.json.j2,sha256=0JWgdTuaSZ25EmCltF_zbqDdpxfvCLeYu
24
25
  litestar_vite/templates/styles.css.j2,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
25
26
  litestar_vite/templates/tsconfig.json.j2,sha256=q1REIuVyXUHCy4Zi2kgTkmrhdT98vyY89k-WTrImOj8,843
26
27
  litestar_vite/templates/vite.config.ts.j2,sha256=bF5kOPFafYMkhhV0VkIwetN-_zoVMGVM1jEMX_wKoNc,1037
27
- litestar_vite-0.13.2.dist-info/METADATA,sha256=jeyo7erxAdorX651z6CrIaFTF5xwRiCwvVM8Gx5HgjU,6245
28
- litestar_vite-0.13.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
29
- litestar_vite-0.13.2.dist-info/licenses/LICENSE,sha256=HeTiEfEgvroUXZe_xAmYHxtTBgw--mbXyZLsWDYabHc,1069
30
- litestar_vite-0.13.2.dist-info/RECORD,,
28
+ litestar_vite-0.14.0.dist-info/METADATA,sha256=nuE0TkAISpQ4HgWkAR44A--wBbRsNwSO9-7l_DjkxgA,6300
29
+ litestar_vite-0.14.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
30
+ litestar_vite-0.14.0.dist-info/licenses/LICENSE,sha256=HeTiEfEgvroUXZe_xAmYHxtTBgw--mbXyZLsWDYabHc,1069
31
+ litestar_vite-0.14.0.dist-info/RECORD,,