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

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

infinity0
Copy link

@infinity0 infinity0 commented Dec 15, 2022

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/

Checklist:

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

@infinity0 infinity0 force-pushed the main branch 4 times, most recently from 173c4e1 to 034c91c Compare December 15, 2022 12:35
@infinity0 infinity0 changed the title add an alternative method for getting a template's dependencies Add Environment.extract_parsed_names to support tracking dynamic inheritance or inclusion Dec 15, 2022
@infinity0
Copy link
Author

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.

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

Successfully merging this pull request may close these issues.

Support accurate dependency tracking including dynamic inheritance or inclusion
2 participants