@@ -51,14 +51,23 @@ def _check_keywords(keywords: list[ast.keyword]) -> None:
51
51
_check_keywords (node .value .keywords )
52
52
53
53
def template_exists (self , template_name : str ) -> bool :
54
+ repo_root = Path (__file__ ).parent .parent .parent
55
+
56
+ # If the template name is a full package path, check if it exists
57
+ # in the package's templates directory.
58
+ if ":" in template_name :
59
+ pkg , resource = template_name .split (":" , 1 )
60
+ pkg_path = repo_root .joinpath (* pkg .split ("." ))
61
+ resource_path = pkg_path / resource
62
+ return resource_path .is_file ()
63
+
54
64
settings = {}
55
65
# TODO: Replace with actual configuration retrieval if it makes sense
56
66
# Get Jinja2 search paths from warehouse config
57
67
# settings = configure().get_settings()
58
68
search_paths = settings .get ("jinja2.searchpath" , [])
59
69
# If not set, fallback to default templates path
60
70
if not search_paths :
61
- repo_root = Path (__file__ ).parent .parent .parent
62
71
search_paths = [
63
72
str (repo_root / "warehouse" / "templates" ),
64
73
str (repo_root / "warehouse" / "admin" / "templates" ),
@@ -146,6 +155,25 @@ def my_view(request):
146
155
assert visitor .errors [0 ][2 ] == WH003_msg
147
156
148
157
158
+ def test_wh003_renderer_template_in_package_path ():
159
+ code = dedent (
160
+ """
161
+ from pyramid.view import view_config
162
+
163
+ @view_config(renderer="warehouse.admin:templates/admin/dashboard.html")
164
+ def my_view(request):
165
+ pass
166
+ """
167
+ )
168
+ tree = ast .parse (code )
169
+ visitor = WarehouseVisitor (filename = "test_file.py" )
170
+ visitor .visit (tree )
171
+
172
+ # Assert that no WH003 error is raised
173
+ assert len (visitor .errors ) == 0
174
+
175
+
149
176
if __name__ == "__main__" :
150
177
test_wh003_renderer_template_not_found ()
178
+ test_wh003_renderer_template_in_package_path ()
151
179
print ("Test passed!" )
0 commit comments