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
Provenance
- Commit
dec9194- Tree
0f64ff4- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
54c9f93
4 files changed+30 added−23 removed
modified:jinja2/testsuite/loader.py+13 added-15 removed
17 unmodified lines18 package_loader, filesystem_loader, function_loader, \19 choice_loader, prefix_loader20 21 from jinja2 import Environment, loaders22+from jinja2._compat import PYPY, PY223 from jinja2.loaders import split_template_path24 from jinja2.exceptions import TemplateNotFound25 26 154 unmodified lines181 pass182 183 assert name not in sys.modules184 185+ # 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')194 195 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()197 198 self.mod_env.loader = loaders.ChoiceLoader([199 self.mod_env.loader,200 loaders.DictLoader({'DICT_SOURCE': 'DICT_TEMPLATE'})4 unmodified lines205 tmpl2 = self.mod_env.get_template('DICT_SOURCE')206 self.assert_equal(tmpl2.render(), 'DICT_TEMPLATE')207 208 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()210 211 self.mod_env.loader = loaders.PrefixLoader({212 'MOD': self.mod_env.loader,213 'DICT': loaders.DictLoader({'test.html': 'DICT_TEMPLATE'})7 unmodified lines221 222 def 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 suitemodified:jinja2/_compat.py+1 added
11 unmodified lines12 """13 import sys14 15 PY2 = sys.version_info[0] == 216+PYPY = hasattr(sys, 'pypy_translation_info')17 _identity = lambda x: x18 19 20 if not PY2:130 unmodified linesmodified:jinja2/environment.py+15 added-8 removed
27 unmodified lines28 from jinja2.utils import import_string, LRUCache, Markup, missing, \29 concat, consume, internalcode30 from 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, PYPY33 from functools import reduce34 35 36 # for direct template usage we have up to ten living environments579 unmodified lines616 syntax errors to abort the compilation you can set `ignore_errors`617 to `False` and you will get an exception on syntax errors.618 619 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.623 624 .. versionadded:: 2.4625 """626 from jinja2.loaders import ModuleLoader1 unmodified line628 if log_function is None:629 log_function = lambda x: None630 631 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')640 634- # 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')644 645 def write_file(filename, data, mode):646 if zip:647 info = ZipInfo(filename)544 unmodified linesmodified:CHANGES+1 added
28 unmodified lines29 - 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.34 35 Version 2.636 -----------37 (codename Convolution, released on July 24th 2011)263 unmodified lines