I have a namespace package, and in one of the packages in that namespace I have a Jinja2
template. I am using jinja2.PackageLoader
to load it.
However, if I create a jinja2.PackageLoader('namespacepackage')
and then try to list_templates()
, it fails to find the templates/
folder, and I can see why:
It creates a pkg_resources.DefaultProvider('namespacepackage')
and then uses its resource_listdir()
method, giving it 'templates'
as argument.
But resource_listdir()
joins this path with self.module_path
internally, and self.module_path
is set from the module's __path__
attribute:
self.module_path = os.path.dirname(getattr(module, '__file__', ''))
Since namespacepackage
has no __file__
, DefaultProvider.module_path
is set to ''
, and the template lookup in Jinja fails.
How is this supposed to work?
Aren't I supposed to provide the package name to PackageLoader
?
If I refer to a specific namespacepackage.module
, everything works, because the module has a __file__
, so DefaultProvider.module_path
is set correctly.