Index: Lib/test/script_helper.py |
=================================================================== |
--- Lib/test/script_helper.py (revision 80058) |
+++ Lib/test/script_helper.py (working copy) |
@@ -11,6 +11,9 @@ |
import shutil |
import zipfile |
+from imp import source_from_cache |
+from test.support import make_legacy_pyc |
+ |
# Executing the interpreter in a subprocess |
def python_exit_code(*args): |
cmd_line = [sys.executable, '-E'] |
@@ -62,20 +65,18 @@ |
script_file.close() |
return script_name |
-def compile_script(script_name): |
- py_compile.compile(script_name, doraise=True) |
- if __debug__: |
- compiled_name = script_name + 'c' |
- else: |
- compiled_name = script_name + 'o' |
- return compiled_name |
- |
def make_zip_script(zip_dir, zip_basename, script_name, name_in_zip=None): |
zip_filename = zip_basename+os.extsep+'zip' |
zip_name = os.path.join(zip_dir, zip_filename) |
zip_file = zipfile.ZipFile(zip_name, 'w') |
if name_in_zip is None: |
- name_in_zip = os.path.basename(script_name) |
+ parts = script_name.split(os.sep) |
+ if len(parts) >= 2 and parts[-2] == '__pycache__': |
+ legacy_pyc = make_legacy_pyc(source_from_cache(script_name)) |
+ name_in_zip = os.path.basename(legacy_pyc) |
+ script_name = legacy_pyc |
+ else: |
+ name_in_zip = os.path.basename(script_name) |
zip_file.write(script_name, name_in_zip) |
zip_file.close() |
#if test.test_support.verbose: |
@@ -98,8 +99,8 @@ |
script_name = make_script(zip_dir, script_basename, source) |
unlink.append(script_name) |
if compiled: |
- init_name = compile_script(init_name) |
- script_name = compile_script(script_name) |
+ init_name = py_compile(init_name, doraise=True) |
+ script_name = py_compile(script_name, doraise=True) |
unlink.extend((init_name, script_name)) |
pkg_names = [os.sep.join([pkg_name]*i) for i in range(1, depth+1)] |
script_name_in_zip = os.path.join(pkg_names[-1], os.path.basename(script_name)) |