From 5f4b80e5a1508116271ae8a6087834fff8ee3825 Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Mon, 29 Jun 2009 10:18:10 +0000 Subject: - Use ``caller_package`` function instead of ``caller_module`` function within ``templating`` to avoid needing to name the caller module in resource overrides (actually match docs). - Make it possible to override templates stored directly in a module with templates in a subdirectory of the same module, stored directly within another module, or stored in a subdirectory of another module (actually match docs). --- repoze/bfg/path.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'repoze/bfg/path.py') diff --git a/repoze/bfg/path.py b/repoze/bfg/path.py index 5b827f04b..b79ff3816 100644 --- a/repoze/bfg/path.py +++ b/repoze/bfg/path.py @@ -16,6 +16,16 @@ def caller_module(level=2): module = sys.modules[module_name] return module +def caller_package(level=2, caller_module=caller_module): + # caller_module in arglist for tests + module = caller_module(level+1) + if '__init__.py' in module.__file__: + # Module is a package + return module + # Go up one level to get package + package_name = module.__name__.rsplit('.', 1)[0] + return sys.modules[package_name] + def package_path(package): # computing the abspath is actually kinda expensive so we memoize # the result -- cgit v1.2.3