From da6d5f442cee7395a17fac8e49347126065b2003 Mon Sep 17 00:00:00 2001 From: rdb Date: Fri, 20 Nov 2015 00:56:31 +0100 Subject: [PATCH] Don't require setting system PATH to import panda3d.* (backport from master) --- makepanda/makepanda.py | 35 ++++++++++++++++++++++++++++++++++- makepanda/makepandacore.py | 3 +-- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/makepanda/makepanda.py b/makepanda/makepanda.py index 0bf937f683..020dafab45 100755 --- a/makepanda/makepanda.py +++ b/makepanda/makepanda.py @@ -1790,7 +1790,7 @@ def RunGenPyCode(target, inputs, opts): if (PkgSkip("PYTHON") != 0): return - cmdstr = BracketNameWithQuotes(SDK["PYTHONEXEC"]) + " " + cmdstr = BracketNameWithQuotes(SDK["PYTHONEXEC"].replace('\\', '/')) + " " if sys.version_info >= (2, 6): cmdstr += "-B " @@ -2591,6 +2591,39 @@ if (PkgSkip("DIRECT")==0): if os.path.isfile(GetOutputDir() + '/direct/ffi/panda3d.pyc'): os.remove(GetOutputDir() + '/direct/ffi/panda3d.pyc') +# These files used to exist; remove them to avoid conflicts. +del_files = ['core.py', 'core.pyc', 'core.pyo', + '_core.pyd', '_core.so', + 'direct.py', 'direct.pyc', 'direct.pyo', + '_direct.pyd', '_direct.so'] + +for basename in del_files: + path = os.path.join(GetOutputDir(), 'panda3d', basename) + if os.path.isfile(path): + print("Removing %s" % (path)) + os.remove(path) + +# Write an appropriate panda3d/__init__.py +p3d_init = """"Python bindings for the Panda3D libraries" +""" + +if GetTarget() == 'windows': + p3d_init += """ +import os + +bindir = os.path.join(os.path.dirname(__file__), '..', 'bin') +if os.path.isfile(os.path.join(bindir, 'libpanda.dll')): + if not os.environ.get('PATH'): + os.environ['PATH'] = bindir + else: + os.environ['PATH'] = bindir + os.pathsep + os.environ['PATH'] + +del os, bindir +""" + +if not PkgSkip("PYTHON"): + ConditionalWriteFile(GetOutputDir() + '/panda3d/__init__.py', p3d_init) + ########################################################################################## # # Generate the PRC files into the ETC directory. diff --git a/makepanda/makepandacore.py b/makepanda/makepandacore.py index f14179fb84..41c0c941eb 100644 --- a/makepanda/makepandacore.py +++ b/makepanda/makepandacore.py @@ -1061,7 +1061,6 @@ def MakeBuildTree(): MakeDirectory(OUTPUTDIR + "/pandac") MakeDirectory(OUTPUTDIR + "/pandac/input") MakeDirectory(OUTPUTDIR + "/panda3d") - CreateFile(OUTPUTDIR + "/panda3d/__init__.py") if GetTarget() == 'darwin': MakeDirectory(OUTPUTDIR + "/Frameworks") @@ -2423,7 +2422,7 @@ def SetupBuildEnvironment(compiler): return # Add our output directories to the environment. - builtdir = os.path.join(os.path.abspath(GetOutputDir())) + builtdir = GetOutputDir() AddToPathEnv("PYTHONPATH", builtdir) AddToPathEnv("PANDA_PRC_DIR", os.path.join(builtdir, "etc")) AddToPathEnv("PATH", os.path.join(builtdir, "bin"))