diff options
author | David Lord <davidism@gmail.com> | 2020-01-10 11:10:19 -0800 |
---|---|---|
committer | David Lord <davidism@gmail.com> | 2020-01-10 12:39:19 -0800 |
commit | 126fce8b049e94ffda5adc3b1c3a301998923c98 (patch) | |
tree | 05d39bd4c19537a96eb34f8c24ee10a0be185061 /scripts | |
parent | 963b5d3c3f426fa36160caef8a1f437e59036bdf (diff) | |
download | jinja2-126fce8b049e94ffda5adc3b1c3a301998923c98.tar.gz |
more relative imports
_identifier exports a compiled regex instead of a string to avoid some
tricky cleanup
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/generate_identifier_pattern.py | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/scripts/generate_identifier_pattern.py b/scripts/generate_identifier_pattern.py index 845a441..5813199 100755 --- a/scripts/generate_identifier_pattern.py +++ b/scripts/generate_identifier_pattern.py @@ -58,17 +58,20 @@ def build_pattern(ranges): def main(): - """Build the regex pattern and write it to the file - :file:`jinja2/_identifier.py`.""" + """Build the regex pattern and write it to + ``jinja2/_identifier.py``. + """ pattern = build_pattern(collapse_ranges(get_characters())) filename = os.path.abspath( os.path.join(os.path.dirname(__file__), "..", "src", "jinja2", "_identifier.py") ) with open(filename, "w", encoding="utf8") as f: - f.write("") + f.write("import re\n\n") f.write("# generated by scripts/generate_identifier_pattern.py\n") - f.write('pattern = "{}" # noqa: B950\n'.format(pattern)) + f.write("pattern = re.compile(\n") + f.write(' r"[\\w{}]+" # noqa: B950\n'.format(pattern)) + f.write(")\n") if __name__ == "__main__": |