Skip to content
Myr

Disable py_compile for Python 3 and pypy

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Armin Ronacher · committed by Armin Ronacher · parent 54c9f93 · Browse files · 4 files+30 added−23 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

4 files+30 added−23 removed

  • other:+30 added−23 removed

4 files+30 added−23 removed

modified:jinja2/testsuite/loader.py+13 added-15 removed
17 unmodified lines
18 package_loader, filesystem_loader, function_loader, \19 choice_loader, prefix_loader2021from jinja2 import Environment, loaders22from jinja2._compat import PYPY, PY223from jinja2.loaders import split_template_path24from jinja2.exceptions import TemplateNotFound2526
154 unmodified lines
181 pass182183 assert name not in sys.modules184185 # This test only makes sense on non-pypy python 2186 if PY2 and not PYPY:184 def test_byte_compilation(self):185 log = self.compile_down(py_compile=True)186 assert 'Byte-compiled "a/test.html"' in log187 tmpl1 = self.mod_env.get_template('a/test.html')188 mod = self.mod_env.loader.module. \189 tmpl_3c4ddf650c1a73df961a6d3d2ce2752f1b8fd490190 assert mod.__file__.endswith('.pyc')187 def test_byte_compilation(self):188 log = self.compile_down(py_compile=True)189 assert 'Byte-compiled "a/test.html"' in log190 tmpl1 = self.mod_env.get_template('a/test.html')191 mod = self.mod_env.loader.module. \192 tmpl_3c4ddf650c1a73df961a6d3d2ce2752f1b8fd490193 assert mod.__file__.endswith('.pyc')194195 def test_choice_loader(self):193 log = self.compile_down(py_compile=True)194 assert 'Byte-compiled "a/test.html"' in log196 log = self.compile_down()197198 self.mod_env.loader = loaders.ChoiceLoader([199 self.mod_env.loader,200 loaders.DictLoader({'DICT_SOURCE': 'DICT_TEMPLATE'})
4 unmodified lines
205 tmpl2 = self.mod_env.get_template('DICT_SOURCE')206 self.assert_equal(tmpl2.render(), 'DICT_TEMPLATE')207208 def test_prefix_loader(self):207 log = self.compile_down(py_compile=True)208 assert 'Byte-compiled "a/test.html"' in log209 log = self.compile_down()210211 self.mod_env.loader = loaders.PrefixLoader({212 'MOD': self.mod_env.loader,213 'DICT': loaders.DictLoader({'test.html': 'DICT_TEMPLATE'})
7 unmodified lines
221222def suite():223 suite = unittest.TestSuite()224 suite.addTest(unittest.makeSuite(LoaderTestCase))224 # pypy currently does not support compiled jinja modules because225 # of changes in the load system.226 if not hasattr(sys, 'pypy_version_info'):227 suite.addTest(unittest.makeSuite(ModuleLoaderTestCase))225 suite.addTest(unittest.makeSuite(ModuleLoaderTestCase))226 return suite
modified:jinja2/_compat.py+1 added
11 unmodified lines
12"""13import sys1415PY2 = sys.version_info[0] == 216PYPY = hasattr(sys, 'pypy_translation_info')17_identity = lambda x: x181920if not PY2:
130 unmodified lines
modified:jinja2/environment.py+15 added-8 removed
27 unmodified lines
28from jinja2.utils import import_string, LRUCache, Markup, missing, \29 concat, consume, internalcode30from jinja2._compat import imap, ifilter, string_types, iteritems, \31 text_type, reraise, implements_iterator, implements_to_string, \32 get_next, encode_filename32 get_next, encode_filename, PY2, PYPY33from functools import reduce343536# for direct template usage we have up to ten living environments
579 unmodified lines
616 syntax errors to abort the compilation you can set `ignore_errors`617 to `False` and you will get an exception on syntax errors.618619 If `py_compile` is set to `True` .pyc files will be written to the620 target instead of standard .py files.620 target instead of standard .py files. This flag does not do anything621 on pypy and Python 3 where pyc files are not picked up by itself and622 don't give much benefit.623624 .. versionadded:: 2.4625 """626 from jinja2.loaders import ModuleLoader
1 unmodified line
628 if log_function is None:629 log_function = lambda x: None630631 if py_compile:632 if not PY2 or PYPY:633 from warnings import warn634 warn(Warning('py_compile has no effect on pypy or Python 3'))635 py_compile = False636 else:630 import imp, marshal631 py_header = imp.get_magic() + \632 u'\xff\xff\xff\xff'.encode('iso-8859-15')637 import imp, marshal638 py_header = imp.get_magic() + \639 u'\xff\xff\xff\xff'.encode('iso-8859-15')640634 # Python 3.3 added a source filesize to the header635 if sys.version_info >= (3, 3):636 py_header += u'\x00\x00\x00\x00'.encode('iso-8859-15')641 # Python 3.3 added a source filesize to the header642 if sys.version_info >= (3, 3):643 py_header += u'\x00\x00\x00\x00'.encode('iso-8859-15')644645 def write_file(filename, data, mode):646 if zip:647 info = ZipInfo(filename)
544 unmodified lines
modified:CHANGES+1 added
28 unmodified lines
29- Added `map`, `select`, `reject`, `selectattr` and `rejectattr`30 filters.31- Added support for `loop.depth` to figure out how deep inside a recursive32 loop the code is.33- Disabled py_compile for pypy and python 3.3435Version 2.636-----------37(codename Convolution, released on July 24th 2011)
263 unmodified lines