Deferred accessing the module-global variable __file__ because the
Python import API does not guarantee it always exists—in particular, it
does not exist in certain "frozen" environments. The following changes
advanced this goal.
Thanks to Carlton Gibson, Tom Forbes, Mariusz Felisiak, and Shreyas
Ravi for review and feedback.
Benchmarking shows that about 22% of the startup time for a simple
django project was spent importing jinja2, which the project doesn't
use.
It's reasonable to make this import lazy. This will only affect
projects where jinja2 is installed but not used, but given the
prevalence of jinja2 that's likely to be many environments (e.g. if
Ansible is installed, or the global Python install is used).