Author: Philip Jenvey <pjen...@underboss.org> Branch: py3k Changeset: r84283:6c12658dce83 Date: 2016-05-07 17:04 -0700 http://bitbucket.org/pypy/pypy/changeset/6c12658dce83/
Log: o set __main__ loader to SourceFileLoader like cpython o workaround subtle test_cmd_line_script impl details diff --git a/lib-python/3/test/test_cmd_line_script.py b/lib-python/3/test/test_cmd_line_script.py --- a/lib-python/3/test/test_cmd_line_script.py +++ b/lib-python/3/test/test_cmd_line_script.py @@ -41,7 +41,11 @@ _loader = __loader__ if __loader__ is BuiltinImporter else type(__loader__) print('__loader__==%a' % _loader) print('__file__==%a' % __file__) -assertEqual(__cached__, None) +if __cached__ is not None: + # XXX: test_script_compiled on PyPy + assertEqual(__file__, __cached__) + if not __cached__.endswith(('pyc', 'pyo')): + raise AssertionError('has __cached__ but not compiled') print('__package__==%r' % __package__) # Check the sys module import sys @@ -159,8 +163,9 @@ def test_basic_script(self): with temp_dir() as script_dir: script_name = _make_test_script(script_dir, 'script') + package = '' if support.check_impl_detail(pypy=True) else None self._check_script(script_name, script_name, script_name, - script_dir, None, + script_dir, package, importlib.machinery.SourceFileLoader) def test_script_compiled(self): @@ -169,8 +174,9 @@ py_compile.compile(script_name, doraise=True) os.remove(script_name) pyc_file = support.make_legacy_pyc(script_name) + package = '' if support.check_impl_detail(pypy=True) else None self._check_script(pyc_file, pyc_file, - pyc_file, script_dir, None, + pyc_file, script_dir, package, importlib.machinery.SourcelessFileLoader) def test_directory(self): diff --git a/pypy/interpreter/app_main.py b/pypy/interpreter/app_main.py --- a/pypy/interpreter/app_main.py +++ b/pypy/interpreter/app_main.py @@ -677,9 +677,11 @@ # CPython goes to great lengths to detect other cases # of pyc file format, but I think it's ok not to care. try: - from _frozen_importlib import SourcelessFileLoader + from _frozen_importlib import ( + SourceFileLoader, SourcelessFileLoader) except ImportError: - from _frozen_importlib_external import SourcelessFileLoader + from _frozen_importlib_external import ( + SourceFileLoader, SourcelessFileLoader) if IS_WINDOWS: filename = filename.lower() if filename.endswith('.pyc') or filename.endswith('.pyo'): @@ -701,6 +703,10 @@ break else: # That's the normal path, "pypy stuff.py". + # We don't actually load via SourceFileLoader + # because we require PyCF_ACCEPT_NULL_BYTES + loader = SourceFileLoader('__main__', filename) + mainmodule.__loader__ = loader @hidden_applevel def execfile(filename, namespace): with open(filename, 'rb') as f: _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit