Author: Armin Rigo <[email protected]>
Branch: release-1.6.x
Changeset: r46542:d1d23f5a0e72
Date: 2011-08-16 14:44 +0200
http://bitbucket.org/pypy/pypy/changeset/d1d23f5a0e72/
Log: Support for PYTHONDONTWRITEBYTECODE, setting
sys.dont_write_bytecode; and when it is set, don't write .pyc files.
(transplanted from 6dff8ba8be761d1313c1fc8d3d29221d35c55c85)
diff --git a/pypy/module/imp/importing.py b/pypy/module/imp/importing.py
--- a/pypy/module/imp/importing.py
+++ b/pypy/module/imp/importing.py
@@ -878,7 +878,8 @@
code_w = parse_source_module(space, pathname, source)
if space.config.objspace.usepycfiles and write_pyc:
- write_compiled_module(space, code_w, cpathname, mode, mtime)
+ if not space.is_true(space.sys.get('dont_write_bytecode')):
+ write_compiled_module(space, code_w, cpathname, mode, mtime)
update_code_filenames(space, code_w, pathname)
exec_code_module(space, w_mod, code_w)
diff --git a/pypy/module/imp/test/test_import.py
b/pypy/module/imp/test/test_import.py
--- a/pypy/module/imp/test/test_import.py
+++ b/pypy/module/imp/test/test_import.py
@@ -769,6 +769,27 @@
cpathname = udir.join('test.pyc')
assert not cpathname.check()
+ def test_load_source_module_dont_write_bytecode(self):
+ space = self.space
+ w_modulename = space.wrap('somemodule')
+ w_mod = space.wrap(Module(space, w_modulename))
+ pathname = _testfilesource()
+ stream = streamio.open_file_as_stream(pathname, "r")
+ try:
+ space.setattr(space.sys, space.wrap('dont_write_bytecode'),
+ space.w_True)
+ w_ret = importing.load_source_module(space,
+ w_modulename,
+ w_mod,
+ pathname,
+ stream.readall())
+ finally:
+ space.setattr(space.sys, space.wrap('dont_write_bytecode'),
+ space.w_False)
+ stream.close()
+ cpathname = udir.join('test.pyc')
+ assert not cpathname.check()
+
def test_load_source_module_syntaxerror(self):
# No .pyc file on SyntaxError
space = self.space
diff --git a/pypy/translator/goal/app_main.py b/pypy/translator/goal/app_main.py
--- a/pypy/translator/goal/app_main.py
+++ b/pypy/translator/goal/app_main.py
@@ -424,8 +424,11 @@
# (relevant in case of "reload(sys)")
sys.argv[:] = argv
- if (PYTHON26 and not options["ignore_environment"] and
os.getenv('PYTHONNOUSERSITE')):
- options["no_user_site"] = True
+ if PYTHON26 and not options["ignore_environment"]:
+ if os.getenv('PYTHONNOUSERSITE'):
+ options["no_user_site"] = True
+ if os.getenv('PYTHONDONTWRITEBYTECODE'):
+ options["dont_write_bytecode"] = True
if (options["interactive"] or
(not options["ignore_environment"] and os.getenv('PYTHONINSPECT'))):
@@ -434,7 +437,8 @@
if PYTHON26 and we_are_translated():
flags = [options[flag] for flag in sys_flags]
sys.flags = type(sys.flags)(flags)
- sys.py3kwarning = sys.flags.py3k_warning
+ sys.py3kwarning = bool(sys.flags.py3k_warning)
+ sys.dont_write_bytecode = bool(sys.flags.dont_write_bytecode)
if sys.py3kwarning:
print >> sys.stderr, (
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit