Author: Manuel Jacob <m...@manueljacob.de> Branch: Changeset: r82506:bc2f7f711496 Date: 2016-02-25 15:44 +0100 http://bitbucket.org/pypy/pypy/changeset/bc2f7f711496/
Log: Remove objspace.usepycfiles option. This option was needed for the sandbox feature, where it might not be allowed to write to the file system. Nowadays Python has a sys.dont_write_bytecode flag, which can be used for that. By default, this flags is `False`, unless when the sandbox feature is enabled; in this case it's set to `True`. diff --git a/pypy/config/pypyoption.py b/pypy/config/pypyoption.py --- a/pypy/config/pypyoption.py +++ b/pypy/config/pypyoption.py @@ -170,12 +170,8 @@ cmdline="--translationmodules", suggests=[("objspace.allworkingmodules", False)]), - BoolOption("usepycfiles", "Write and read pyc files when importing", - default=True), - BoolOption("lonepycfiles", "Import pyc files with no matching py file", - default=False, - requires=[("objspace.usepycfiles", True)]), + default=False), StrOption("soabi", "Tag to differentiate extension modules built for different Python interpreters", diff --git a/pypy/goal/targetpypystandalone.py b/pypy/goal/targetpypystandalone.py --- a/pypy/goal/targetpypystandalone.py +++ b/pypy/goal/targetpypystandalone.py @@ -277,7 +277,6 @@ if config.translation.sandbox: config.objspace.lonepycfiles = False - config.objspace.usepycfiles = False config.translating = True 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 @@ -85,7 +85,7 @@ # The "imp" module does not respect this, and is allowed to find # lone .pyc files. # check the .pyc file - if space.config.objspace.usepycfiles and space.config.objspace.lonepycfiles: + if space.config.objspace.lonepycfiles: pycfile = filepart + ".pyc" if file_exists(pycfile): # existing .pyc file @@ -888,17 +888,11 @@ """ w = space.wrap - if space.config.objspace.usepycfiles: - src_stat = os.fstat(fd) - cpathname = pathname + 'c' - mtime = int(src_stat[stat.ST_MTIME]) - mode = src_stat[stat.ST_MODE] - stream = check_compiled_module(space, cpathname, mtime) - else: - cpathname = None - mtime = 0 - mode = 0 - stream = None + src_stat = os.fstat(fd) + cpathname = pathname + 'c' + mtime = int(src_stat[stat.ST_MTIME]) + mode = src_stat[stat.ST_MODE] + stream = check_compiled_module(space, cpathname, mtime) if stream: # existing and up-to-date .pyc file @@ -913,7 +907,7 @@ else: code_w = parse_source_module(space, pathname, source) - if space.config.objspace.usepycfiles and write_pyc: + if write_pyc: if not space.is_true(space.sys.get('dont_write_bytecode')): write_compiled_module(space, code_w, cpathname, mode, mtime) 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 @@ -123,7 +123,7 @@ stream.try_to_find_file_descriptor()) finally: stream.close() - if space.config.objspace.usepycfiles: + if not space.config.translation.sandbox: # also create a lone .pyc file p.join('lone.pyc').write(p.join('x.pyc').read(mode='rb'), mode='wb') @@ -1349,8 +1349,14 @@ class AppTestWriteBytecode(object): + spaceconfig = { + "translation.sandbox": False + } + def setup_class(cls): cls.saved_modules = _setup(cls.space) + sandbox = cls.spaceconfig['translation.sandbox'] + cls.w_sandbox = cls.space.wrap(sandbox) def teardown_class(cls): _teardown(cls.space, cls.saved_modules) @@ -1364,7 +1370,7 @@ import os.path from test_bytecode import a assert a.__file__.endswith('a.py') - assert os.path.exists(a.__file__ + 'c') + assert os.path.exists(a.__file__ + 'c') == (not self.sandbox) def test_write_bytecode(self): import os.path @@ -1383,15 +1389,15 @@ assert not os.path.exists(c.__file__ + 'c') -class AppTestNoPycFile(object): +class AppTestWriteBytecodeSandbox(AppTestWriteBytecode): spaceconfig = { - "objspace.usepycfiles": False, - "objspace.lonepycfiles": False + "translation.sandbox": True } + + +class _AppTestLonePycFileBase(object): def setup_class(cls): - usepycfiles = cls.spaceconfig['objspace.usepycfiles'] lonepycfiles = cls.spaceconfig['objspace.lonepycfiles'] - cls.w_usepycfiles = cls.space.wrap(usepycfiles) cls.w_lonepycfiles = cls.space.wrap(lonepycfiles) cls.saved_modules = _setup(cls.space) @@ -1400,10 +1406,7 @@ def test_import_possibly_from_pyc(self): from compiled import x - if self.usepycfiles: - assert x.__file__.endswith('x.pyc') - else: - assert x.__file__.endswith('x.py') + assert x.__file__.endswith('x.pyc') try: from compiled import lone except ImportError: @@ -1412,15 +1415,13 @@ assert self.lonepycfiles, "should not have found 'lone.pyc'" assert lone.__file__.endswith('lone.pyc') -class AppTestNoLonePycFile(AppTestNoPycFile): +class AppTestNoLonePycFile(_AppTestLonePycFileBase): spaceconfig = { - "objspace.usepycfiles": True, "objspace.lonepycfiles": False } -class AppTestLonePycFile(AppTestNoPycFile): +class AppTestLonePycFile(_AppTestLonePycFileBase): spaceconfig = { - "objspace.usepycfiles": True, "objspace.lonepycfiles": True } diff --git a/pypy/module/sys/__init__.py b/pypy/module/sys/__init__.py --- a/pypy/module/sys/__init__.py +++ b/pypy/module/sys/__init__.py @@ -77,7 +77,7 @@ 'meta_path' : 'space.wrap([])', 'path_hooks' : 'space.wrap([])', 'path_importer_cache' : 'space.wrap({})', - 'dont_write_bytecode' : 'space.w_False', + 'dont_write_bytecode' : 'space.wrap(space.config.translation.sandbox)', 'getdefaultencoding' : 'interp_encoding.getdefaultencoding', 'setdefaultencoding' : 'interp_encoding.setdefaultencoding', _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit