From bd21568e61248e51f48a9a146cb837fa0252d162 Mon Sep 17 00:00:00 2001 From: Michael Merickel Date: Wed, 7 Feb 2024 23:20:24 -0700 Subject: [PATCH] issue a warning if a static view is referencing a package that doesn't exist --- src/pyramid/static.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/pyramid/static.py b/src/pyramid/static.py index 100d17676..c3489ae89 100644 --- a/src/pyramid/static.py +++ b/src/pyramid/static.py @@ -4,6 +4,7 @@ import os from os.path import exists, getmtime, getsize, isdir, join, normcase, normpath from pkg_resources import resource_exists, resource_filename, resource_isdir +import warnings from pyramid.asset import abspath_from_asset_spec, resolve_asset_spec from pyramid.httpexceptions import HTTPMovedPermanently, HTTPNotFound @@ -92,6 +93,19 @@ def __init__( if package_name is None: package_name = caller_package().__name__ package_name, docroot = resolve_asset_spec(root_dir, package_name) + if package_name: + try: + __import__(package_name) + except ImportError: + warnings.warn( + f'A "pyramid.static.static_view" is being created with an' + f' asset spec referencing a package "{package_name}" that' + f' does not exist. This will break in the future.' + f' If this is done to override an asset, you must adjust' + f' this to override a location inside a real package.', + DeprecationWarning, + stacklevel=1, + ) self.use_subpath = use_subpath self.package_name = package_name self.docroot = docroot