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
jinja2 no longer supports the pytest loader #1168
Comments
This seems related to #1148. We dropped Here's where we detect the package, there are also some workarounds in the surrounding code to support zip and namespace imports: Lines 262 to 267 in 45a76a3
|
Pytest's loader does not provides get_filename as I pointed out in the first post. Are you sure that it must though for any loader? |
jinja2 is making assumptions about loaders that aren't part of PEP 451 -- it should probably be using the |
We need a way to get the path to files within a package in order to load them. This appeared to be the way to do that with the APIs provided by Python, but admittedly the documentation about how to do anything with those APIs was pretty much impenetrable for me. If anyone has a better suggestion that plays nicer with different loaders while still supporting directories, zips, and namespaces, I would appreciate the help. |
cc @jaraco |
If you want to load some resource shouldn't you be using https://docs.python.org/3/library/importlib.html#module-importlib.resources; there's no need for you to know the source of the file, just what it contains, not? |
|
this might be a helpful starting point, I'll see if I can shimmy some code into jinja2: https://github.com/asottile/aspy.refactor_imports/blob/519ee18ea75e0045b9b53644c627c6817b2a0748/aspy/refactor_imports/classify.py#L76-L91 |
Seems this might be an occlusion of the initial design for |
It looks like maybe |
#1169 is an attempt at a fix, I probably still need changelog etc. but you can probably try it out and see if it fixes your issue @gaborbernat |
Never mind, the issue is still valid. |
Can we have a release with this please? |
Waiting on one other PR. |
Can you link it? 😄 |
I suspect it's #1183 given the milestone |
Just released 2.11.2 that reverts the change. 3.0 will have the new behavior with the fix. |
we can probably upgrade once Jinja2 3.0.0 is out (see pallets/jinja#1168) or try subsequent releases of pytest we cannot simply switch to filesystem loader (like we did in the test fixtures) since the ability to override templates by installing additional python packages is a core feature of the briefkasten.
Currently, jinja2 expects either _path defined or get_filenames: https://github.com/pallets/jinja/blob/master/src/jinja2/loaders.py#L262-L281
The pytest assertion rewriter defines neither (see https://github.com/pytest-dev/pytest/blob/master/src/_pytest/assertion/rewrite.py#L48), and as such running a test suite on a source code that has the following global:
will fail with:
Not sure if here jinja2 needs to support more ways to get the template rooot, or pytest loader is missing some methods.
The text was updated successfully, but these errors were encountered: