Skip to content

Commit 00da2d0

Browse files
committed
Fix whitenise import
1 parent 4855093 commit 00da2d0

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ build-backend = "poetry.core.masonry.api"
55

66
[tool.poetry]
77
name = "jinjax"
8-
version = "0.47"
8+
version = "0.48"
99
description = "Replace your HTML templates with Python server-Side components"
1010
authors = ["Juan-Pablo Scaletti <[email protected]>"]
1111
license = "MIT"

src/jinjax/middleware.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,23 @@
66
try:
77
from whitenoise import WhiteNoise
88
from whitenoise.responders import Redirect, StaticFile
9-
except ImportError as err :
10-
raise ImportError(
11-
"This feature requires the package `whitenoise` to be installed. \n"
12-
+ "Run `pip install jinjax[whitenoise]` to do it."
13-
) from err
14-
9+
except ImportError:
10+
WhiteNoise = object
1511

1612
RX_FINGERPRINT = re.compile("(.*)-([abcdef0-9]{64})")
1713

1814

19-
class ComponentsMiddleware(WhiteNoise):
15+
class ComponentsMiddleware(WhiteNoise): # type: ignore
2016
"""WSGI middleware for serving components assets"""
2117

2218
allowed_ext: tuple[str, ...]
2319

2420
def __init__(self, **kwargs) -> None:
21+
if WhiteNoise is object:
22+
raise ImportError(
23+
"The ComponentsMiddleware requires the package `whitenoise`"
24+
+ " to be installed. \nRun `pip install jinjax[whitenoise]` to do it."
25+
)
2526
self.allowed_ext = kwargs.pop("allowed_ext", ())
2627
super().__init__(**kwargs)
2728

0 commit comments

Comments
 (0)