From 1cf6f28fe8a87415c59e893eeb9913e34d86463e Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 29 Jul 2018 13:16:35 +0530 Subject: [PATCH] When compiling python bytecode for the packages optimize it to level-2 and use relative paths in the pyc files --- setup.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index a28550a7c..5ac5063eb 100755 --- a/setup.py +++ b/setup.py @@ -570,6 +570,20 @@ make && make docs shutil.copytree(src, htmldir) +def compile_python(base_path): + import compileall + try: + from multiprocessing import cpu_count + num_workers = max(1, cpu_count()) + except Exception: + num_workers = 1 + for root, dirs, files in os.walk(base_path): + for f in files: + if f.rpartition('.')[-1] in ('pyc', 'pyo'): + os.remove(os.path.join(root, f)) + compileall.compile_dir(base_path, ddir='', force=True, optimize=1, quiet=1, workers=num_workers) + + def package(args, for_bundle=False, sh_launcher=False): ddir = args.prefix if for_bundle or sh_launcher: @@ -596,8 +610,7 @@ def package(args, for_bundle=False, sh_launcher=False): shutil.copytree('kitty', os.path.join(libdir, 'kitty'), ignore=src_ignore) shutil.copytree('kittens', os.path.join(libdir, 'kittens'), ignore=src_ignore) - import compileall - compileall.compile_dir(libdir, quiet=1, workers=4) + compile_python(libdir) for root, dirs, files in os.walk(libdir): for f in files: path = os.path.join(root, f)