You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 theFileSystemLoader`, 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.
The text was updated successfully, but these errors were encountered:
I have been looking at the implementations of
FileSystemLoader
andPackageLoader
to see if any of them can supportMultiplexedPath
or more generalTraversable
.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 apathlib.Path
type, but instead it is animporlib.resources.MultiplexedPath
.There are two possible ways to support this.
Extend
PackageLoader
and useimportlib.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 filesExtend
FileSystemLoader
to accept arbitraryTraversable
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.The text was updated successfully, but these errors were encountered: