@@ -51,14 +51,23 @@ def _check_keywords(keywords: list[ast.keyword]) -> None:
5151 _check_keywords (node .value .keywords )
5252
5353 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+
5464 settings = {}
5565 # TODO: Replace with actual configuration retrieval if it makes sense
5666 # Get Jinja2 search paths from warehouse config
5767 # settings = configure().get_settings()
5868 search_paths = settings .get ("jinja2.searchpath" , [])
5969 # If not set, fallback to default templates path
6070 if not search_paths :
61- repo_root = Path (__file__ ).parent .parent .parent
6271 search_paths = [
6372 str (repo_root / "warehouse" / "templates" ),
6473 str (repo_root / "warehouse" / "admin" / "templates" ),
@@ -146,6 +155,25 @@ def my_view(request):
146155 assert visitor .errors [0 ][2 ] == WH003_msg
147156
148157
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+
149176if __name__ == "__main__" :
150177 test_wh003_renderer_template_not_found ()
178+ test_wh003_renderer_template_in_package_path ()
151179 print ("Test passed!" )
0 commit comments