diff options
author | Barry Warsaw <barry@python.org> | 2010-04-17 00:19:56 (GMT) |
---|---|---|
committer | Barry Warsaw <barry@python.org> | 2010-04-17 00:19:56 (GMT) |
commit | 28a691b7fdde1b8abafa4c4a5025e6bfa44f48b9 (patch) | |
tree | ca0098063694e0f91d1bcd785d0044e96e1bf389 /Lib/test/script_helper.py | |
parent | 0e59cc3fc347582d8625050de258a2dd6b87f978 (diff) | |
download | cpython-28a691b7fdde1b8abafa4c4a5025e6bfa44f48b9.zip cpython-28a691b7fdde1b8abafa4c4a5025e6bfa44f48b9.tar.gz cpython-28a691b7fdde1b8abafa4c4a5025e6bfa44f48b9.tar.bz2 |
PEP 3147
Diffstat (limited to 'Lib/test/script_helper.py')
-rw-r--r-- | Lib/test/script_helper.py | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/Lib/test/script_helper.py b/Lib/test/script_helper.py index 144cf66..39874d9 100644 --- a/Lib/test/script_helper.py +++ b/Lib/test/script_helper.py @@ -11,6 +11,9 @@ import contextlib 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 @@ def make_script(script_dir, script_basename, source): 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 @@ def make_zip_pkg(zip_dir, zip_basename, pkg_name, script_basename, 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)) |