Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Disable py_compile for Python 3 and pypy

  • Loading branch information...
commit dec91944ee5e5e7bc5b02ab9756aaa4a9af08cfb 1 parent 54c9f93
@mitsuhiko authored
View
1  CHANGES
@@ -30,6 +30,7 @@ Version 2.7
filters.
- Added support for `loop.depth` to figure out how deep inside a recursive
loop the code is.
+- Disabled py_compile for pypy and python 3.
Version 2.6
-----------
View
1  jinja2/_compat.py
@@ -13,6 +13,7 @@
import sys
PY2 = sys.version_info[0] == 2
+PYPY = hasattr(sys, 'pypy_translation_info')
_identity = lambda x: x
View
23 jinja2/environment.py
@@ -29,7 +29,7 @@
concat, consume, internalcode
from jinja2._compat import imap, ifilter, string_types, iteritems, \
text_type, reraise, implements_iterator, implements_to_string, \
- get_next, encode_filename
+ get_next, encode_filename, PY2, PYPY
from functools import reduce
@@ -617,7 +617,9 @@ def compile_templates(self, target, extensions=None, filter_func=None,
to `False` and you will get an exception on syntax errors.
If `py_compile` is set to `True` .pyc files will be written to the
- target instead of standard .py files.
+ target instead of standard .py files. This flag does not do anything
+ on pypy and Python 3 where pyc files are not picked up by itself and
+ don't give much benefit.
.. versionadded:: 2.4
"""
@@ -627,13 +629,18 @@ def compile_templates(self, target, extensions=None, filter_func=None,
log_function = lambda x: None
if py_compile:
- import imp, marshal
- py_header = imp.get_magic() + \
- u'\xff\xff\xff\xff'.encode('iso-8859-15')
+ if not PY2 or PYPY:
+ from warnings import warn
+ warn(Warning('py_compile has no effect on pypy or Python 3'))
+ py_compile = False
+ else:
+ import imp, marshal
+ py_header = imp.get_magic() + \
+ u'\xff\xff\xff\xff'.encode('iso-8859-15')
- # Python 3.3 added a source filesize to the header
- if sys.version_info >= (3, 3):
- py_header += u'\x00\x00\x00\x00'.encode('iso-8859-15')
+ # Python 3.3 added a source filesize to the header
+ if sys.version_info >= (3, 3):
+ py_header += u'\x00\x00\x00\x00'.encode('iso-8859-15')
def write_file(filename, data, mode):
if zip:
View
28 jinja2/testsuite/loader.py
@@ -19,6 +19,7 @@
choice_loader, prefix_loader
from jinja2 import Environment, loaders
+from jinja2._compat import PYPY, PY2
from jinja2.loaders import split_template_path
from jinja2.exceptions import TemplateNotFound
@@ -181,17 +182,18 @@ def test_weak_references(self):
assert name not in sys.modules
- def test_byte_compilation(self):
- log = self.compile_down(py_compile=True)
- assert 'Byte-compiled "a/test.html"' in log
- tmpl1 = self.mod_env.get_template('a/test.html')
- mod = self.mod_env.loader.module. \
- tmpl_3c4ddf650c1a73df961a6d3d2ce2752f1b8fd490
- assert mod.__file__.endswith('.pyc')
+ # This test only makes sense on non-pypy python 2
+ if PY2 and not PYPY:
+ def test_byte_compilation(self):
+ log = self.compile_down(py_compile=True)
+ assert 'Byte-compiled "a/test.html"' in log
+ tmpl1 = self.mod_env.get_template('a/test.html')
+ mod = self.mod_env.loader.module. \
+ tmpl_3c4ddf650c1a73df961a6d3d2ce2752f1b8fd490
+ assert mod.__file__.endswith('.pyc')
def test_choice_loader(self):
- log = self.compile_down(py_compile=True)
- assert 'Byte-compiled "a/test.html"' in log
+ log = self.compile_down()
self.mod_env.loader = loaders.ChoiceLoader([
self.mod_env.loader,
@@ -204,8 +206,7 @@ def test_choice_loader(self):
self.assert_equal(tmpl2.render(), 'DICT_TEMPLATE')
def test_prefix_loader(self):
- log = self.compile_down(py_compile=True)
- assert 'Byte-compiled "a/test.html"' in log
+ log = self.compile_down()
self.mod_env.loader = loaders.PrefixLoader({
'MOD': self.mod_env.loader,
@@ -221,8 +222,5 @@ def test_prefix_loader(self):
def suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(LoaderTestCase))
- # pypy currently does not support compiled jinja modules because
- # of changes in the load system.
- if not hasattr(sys, 'pypy_version_info'):
- suite.addTest(unittest.makeSuite(ModuleLoaderTestCase))
+ suite.addTest(unittest.makeSuite(ModuleLoaderTestCase))
return suite
Please sign in to comment.
Something went wrong with that request. Please try again.