Description
I have been looking at the implementations of FileSystemLoader
and PackageLoader
to see if any of them can support MultiplexedPath
or more general Traversable
.
The idea is that we have a project for which we place them jinja template directory such that it is effectively a namespace package that is shared with external plugin projects using entry-points
. As such the base template directory is no longer a pathlib.Path
type, but instead it is an imporlib.resources.MultiplexedPath
.
There are two possible ways to support this.
Extend PackageLoader
and use importlib.resources.as_file()
This would copy and extract all files that are under foo.bar
package and put them in the native filesystem structure under a temporary directory. The major downside for this is that it can have a heavy overhead of copying and deleting files
Extend FileSystemLoader
to accept arbitrary Traversable
This approach is more involved, but more efficient. Basically if the code relies only on the Traversable
interface (e.g. pathlib.Path("foo") / "subfolder/template.j2") than it would be safe to simply use whatever interface the actual
Traversableimplemented to navigate. If the relevant refactoring for this is contained within the
FileSystemLoader`, than the refactoring is not that bad, and I could write a simple implementation for this, but I'm weary if there is some nuance that I am overlooking.
Activity
resource_files
to generalTraversable
s teemtee/tmt#2946