Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support generic Traversable in FileSystemLoader #2035

Open
LecrisUT opened this issue Oct 7, 2024 · 0 comments
Open

Support generic Traversable in FileSystemLoader #2035

LecrisUT opened this issue Oct 7, 2024 · 0 comments

Comments

@LecrisUT
Copy link

LecrisUT commented Oct 7, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant