aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArmin Rigo <arigo@tunes.org>2011-08-16 14:44:12 +0200
committerArmin Rigo <arigo@tunes.org>2011-08-16 14:44:12 +0200
commit812bbe77fdbb2ca18e6f0975105929cda618d514 (patch)
tree559262dd57f2e2f2b4071d1aa61c58610bf6c5fa
parentThe constructor can take a different array; but the precise (diff)
downloadpypy-812bbe77fdbb2ca18e6f0975105929cda618d514.tar.gz
pypy-812bbe77fdbb2ca18e6f0975105929cda618d514.tar.bz2
pypy-812bbe77fdbb2ca18e6f0975105929cda618d514.zip
Support for PYTHONDONTWRITEBYTECODE, setting sys.dont_write_bytecode;
and when it is set, don't write .pyc files. (transplanted from 6dff8ba8be761d1313c1fc8d3d29221d35c55c85)
-rw-r--r--pypy/module/imp/importing.py3
-rw-r--r--pypy/module/imp/test/test_import.py21
-rw-r--r--pypy/translator/goal/app_main.py10
3 files changed, 30 insertions, 4 deletions
diff --git a/pypy/module/imp/importing.py b/pypy/module/imp/importing.py
index f77f4b38a3..9ec6e5742e 100644
--- a/pypy/module/imp/importing.py
+++ b/pypy/module/imp/importing.py
@@ -878,7 +878,8 @@ def load_source_module(space, w_modulename, w_mod, pathname, source,
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
index 6d3d6ca8f0..c136f387a1 100644
--- a/pypy/module/imp/test/test_import.py
+++ b/pypy/module/imp/test/test_import.py
@@ -769,6 +769,27 @@ class TestPycStuff:
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
index 295a8ec5f1..d80992a5ee 100644
--- a/pypy/translator/goal/app_main.py
+++ b/pypy/translator/goal/app_main.py
@@ -424,8 +424,11 @@ def parse_command_line(argv):
# (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 @@ def parse_command_line(argv):
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, (