jinja icon indicating copy to clipboard operation
jinja copied to clipboard

Add Environment.extract_parsed_names to support tracking dynamic inheritance or inclusion

Open infinity0 opened this issue 1 year ago • 1 comments

Add Environment.extract_parsed_names to support tracking dynamic inheritance or inclusion.

Compared to jinja2.meta.find_referenced_templates(), it:

a. works on dynamic inheritance and includes b. does not work unless and until you actually render the template

Many buildsystems are unable to support (b), but some do e.g. [1], the point being that if the target file does not exist, dependency information is not needed since the target file must be built anyway. In such cases, you may prefer this function due to (a).

[1] https://make.mad-scientist.net/papers/advanced-auto-dependency-generation/

  • fixes #1775

Checklist:

  • [X] Add tests that demonstrate the correct behavior of the change. Tests should fail without the change.
  • [X] Add or update relevant docs, in the docs folder and in code.
  • [x] Add an entry in CHANGES.rst summarizing the change and linking to the issue.
  • [X] Add .. versionchanged:: entries in any relevant code docs.
  • [x] Run pre-commit hooks and fix any issues.
  • [x] Run pytest and tox, no tests failed.

infinity0 avatar Dec 15 '22 12:12 infinity0

pre-commit.ci is complaining about these two files even though I didn't touch them in this PR:

src/jinja2/nodes.py:138:30: B905 `zip()` without an explicit `strict=` parameter.
src/jinja2/compiler.py:1350:29: B905 `zip()` without an explicit `strict=` parameter.

infinity0 avatar Dec 15 '22 12:12 infinity0