From 4b9da436a01fe18a97fa9bfb7f0271ac035a3e62 Mon Sep 17 00:00:00 2001 From: rdb Date: Tue, 17 Dec 2013 22:48:19 +0000 Subject: [PATCH] Automatically invoke 2to3 on built/direct for a Python 3 build --- makepanda/makepanda.py | 10 ++++++---- makepanda/makepandacore.py | 41 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 4 deletions(-) diff --git a/makepanda/makepanda.py b/makepanda/makepanda.py index 223eadc9b0..2cf64380e6 100755 --- a/makepanda/makepanda.py +++ b/makepanda/makepanda.py @@ -1611,12 +1611,14 @@ def RunGenPyCode(target, inputs, opts): if (PkgSkip("PYTHON") != 0): return - cmdstr = sys.executable + " -B " + os.path.join("direct", "src", "ffi", "jGenPyCode.py") + cmdstr = sys.executable + " -B " + os.path.join(GetOutputDir(), "direct", "ffi", "jGenPyCode.py") if (GENMAN): cmdstr += " -d" cmdstr += " -r" for i in inputs: - if (GetOrigExt(i)==".dll"): - cmdstr += " " + os.path.basename(os.path.splitext(i)[0].replace("_d","").replace(GetOutputDir()+"/lib/","")) + if (GetOrigExt(i)==".pyd"): + cmdstr += " panda3d." + os.path.basename(os.path.splitext(i)[0]) + elif (GetOrigExt(i)==".dll"): + cmdstr += " " + os.path.basename(os.path.splitext(i)[0].replace("_d","")) oscmd(cmdstr) @@ -2379,7 +2381,7 @@ CreatePandaVersionFiles() ########################################################################################## if (PkgSkip("DIRECT")==0): - CopyTree(GetOutputDir()+'/direct', 'direct/src') + CopyPythonTree(GetOutputDir() + '/direct', 'direct/src', lib2to3_fixers=['all']) ConditionalWriteFile(GetOutputDir() + '/direct/__init__.py', "") if (GetTarget() == 'windows'): CopyFile(GetOutputDir()+'/bin/panda3d.py', 'direct/src/ffi/panda3d.py') diff --git a/makepanda/makepandacore.py b/makepanda/makepandacore.py index 8acb530039..911e3036d7 100644 --- a/makepanda/makepandacore.py +++ b/makepanda/makepandacore.py @@ -2343,6 +2343,47 @@ def CopyTree(dstdir, srcdir, omitCVS=True): else: cmd = 'cp -R -f ' + srcdir + ' ' + dstdir oscmd(cmd) + if omitCVS: + DeleteCVS(dstdir) + +def CopyPythonTree(dstdir, srcdir, lib2to3_fixers=[]): + if (not os.path.isdir(dstdir)): + os.mkdir(dstdir) + + lib2to3 = None + if len(lib2to3_fixers) > 0 and sys.version_info >= (3, 0): + from lib2to3.main import main as lib2to3 + lib2to3_args = ['-w', '-n', '--no-diffs', '-x', 'buffer', '-x', 'idioms', '-x', 'set_literal', '-x', 'ws_comma'] + if lib2to3_fixers != ['all']: + for fixer in lib2to3_fixers: + lib2to3_args += ['-f', fixer] + + refactor = [] + for entry in os.listdir(srcdir): + srcpth = os.path.join(srcdir, entry) + dstpth = os.path.join(dstdir, entry) + if (os.path.isfile(srcpth)): + base, ext = os.path.splitext(entry) + if (entry != ".cvsignore" and ext not in SUFFIX_INC): + if (NeedsBuild([dstpth], [srcpth])): + WriteBinaryFile(dstpth, ReadBinaryFile(srcpth)) + + if ext == '.py' and not entry.endswith('-extensions.py'): + refactor.append((dstpth, srcpth)) + else: + JustBuilt([dstpth], [srcpth]) + + elif (entry != "CVS"): + CopyPythonTree(dstpth, srcpth, lib2to3_fixers) + + for dstpth, srcpth in refactor: + if lib2to3 is not None: + ret = lib2to3("lib2to3.fixes", lib2to3_args + [dstpth]) + if ret != 0: + os.remove(dstpth) + exit("Error in lib2to3.") + JustBuilt([dstpth], [srcpth]) + ######################################################################## ##