From 6eeb4f27e3ab4a96a47ee92fa85bbba3eccad7f3 Mon Sep 17 00:00:00 2001 From: David Rose Date: Thu, 3 Jun 2004 21:11:24 +0000 Subject: [PATCH] more fixes to new genPyCode --- direct/Sources.pp | 5 +- direct/__init__.py | 45 ------- direct/src/cluster/Sources.pp | 0 direct/src/directdevices/Sources.pp | 0 direct/src/directnotify/Sources.pp | 0 direct/src/directtools/Sources.pp | 0 direct/src/directutil/Sources.pp | 0 direct/src/ffi/DoGenPyCode.py | 2 +- direct/src/ffi/genPyCode.pp | 31 ++++- direct/src/fsm/Sources.pp | 0 direct/src/gui/Sources.pp | 0 direct/src/particles/Sources.pp | 0 direct/src/pyinst/Sources.pp | 0 direct/src/showbase/FindCtaPaths.py | 98 +++++++++++++++ direct/src/showbase/sitecustomize.py | 177 ++++----------------------- direct/src/showutil/Sources.pp | 0 direct/src/task/Sources.pp | 0 17 files changed, 156 insertions(+), 202 deletions(-) delete mode 100644 direct/__init__.py create mode 100644 direct/src/cluster/Sources.pp create mode 100644 direct/src/directdevices/Sources.pp create mode 100644 direct/src/directnotify/Sources.pp create mode 100644 direct/src/directtools/Sources.pp create mode 100644 direct/src/directutil/Sources.pp create mode 100644 direct/src/fsm/Sources.pp create mode 100644 direct/src/gui/Sources.pp create mode 100644 direct/src/particles/Sources.pp create mode 100644 direct/src/pyinst/Sources.pp create mode 100755 direct/src/showbase/FindCtaPaths.py create mode 100644 direct/src/showutil/Sources.pp create mode 100644 direct/src/task/Sources.pp diff --git a/direct/Sources.pp b/direct/Sources.pp index 08436ca73d..621e12ba69 100644 --- a/direct/Sources.pp +++ b/direct/Sources.pp @@ -1,5 +1,4 @@ -// This is the toplevel directory. It contains configure.in and other -// stuff. +// This is the toplevel directory for a package. #define DIR_TYPE toplevel @@ -8,3 +7,5 @@ #define EXTRA_DIST \ Sources.pp Config.pp Package.pp + +#define PYTHON_PACKAGE 1 diff --git a/direct/__init__.py b/direct/__init__.py deleted file mode 100644 index 12ae7c6cb0..0000000000 --- a/direct/__init__.py +++ /dev/null @@ -1,45 +0,0 @@ -"""This file defines the path to the Python files within this package. -There are two cases: - -(1) This is a source tree being run interactively by a developer, in - which case the Python files are found in package/src/*/*.py. This - case also breaks down into two sub-cases: (1a) we are using the - ctattach tools, in which case we should look for the files in the - actual source directory according to the ctattach variables, or - (1b) we are not using the ctattach tools, in which case the files - are right where we expect them to be. - -(2) This is an installed tree being run by an end-user, in which case - the Python files are found in package/*/*.py. In this case, this - file doesn't really need to be installed; an empty __init__.py - file to define the package would serve just as well. But the file - is crafted so that it will do no harm if it is installed. -""" - -package = 'DIRECT' - -import os - -if os.getenv('CTPROJS'): - # Ok, this is case (1a): we are using the ctattach tools, are - # therefore will expect to find the source files in - # $(package)/src/*/*.py. Completely replace the search path with - # this path. - tree = os.getenv(package) - - if not tree: - raise StandardError, 'CTPROJS is defined, but $%s is not defined!' % (package) - __path__[0] = os.path.join(tree, 'src') - -else: - # We are not using the ctattach tools. - srcDir = os.path.join(__path__[0], 'src') - if os.path.isdir(srcDir): - # The source directory exists; therefore, we are in case (1b). - __path__[0] = srcDir - - else: - # The source directory does not exist, so we must be in case - # (2). Leave well enough alone. - pass - diff --git a/direct/src/cluster/Sources.pp b/direct/src/cluster/Sources.pp new file mode 100644 index 0000000000..e69de29bb2 diff --git a/direct/src/directdevices/Sources.pp b/direct/src/directdevices/Sources.pp new file mode 100644 index 0000000000..e69de29bb2 diff --git a/direct/src/directnotify/Sources.pp b/direct/src/directnotify/Sources.pp new file mode 100644 index 0000000000..e69de29bb2 diff --git a/direct/src/directtools/Sources.pp b/direct/src/directtools/Sources.pp new file mode 100644 index 0000000000..e69de29bb2 diff --git a/direct/src/directutil/Sources.pp b/direct/src/directutil/Sources.pp new file mode 100644 index 0000000000..e69de29bb2 diff --git a/direct/src/ffi/DoGenPyCode.py b/direct/src/ffi/DoGenPyCode.py index 3f330c9aea..8d18c9ecd1 100644 --- a/direct/src/ffi/DoGenPyCode.py +++ b/direct/src/ffi/DoGenPyCode.py @@ -104,7 +104,7 @@ def doGetopts(): elif (flag == '-n'): doSqueeze = False elif (flag in ['-g', '-t', '-p', '-o']): - FFIConstants.notify.warning("option is deprecated: %s" % (flag)) + FFIConstants.notify.debug("option is deprecated: %s" % (flag)) else: FFIConstants.notify.error('illegal option: ' + flag) diff --git a/direct/src/ffi/genPyCode.pp b/direct/src/ffi/genPyCode.pp index 2fa871279c..3319e9db8b 100644 --- a/direct/src/ffi/genPyCode.pp +++ b/direct/src/ffi/genPyCode.pp @@ -33,7 +33,7 @@ python $[osfilename $[install_bin_dir]/genPyCode.py] %1 %2 %3 %4 %5 %6 %7 %8 %9 #output genPyCode $[hash]! /bin/sh -ppython '$[osfilename $[install_bin_dir]/genPyCode.py]' "$@" +python '$[osfilename $[install_bin_dir]/genPyCode.py]' "$@" #end genPyCode #endif // Win32 @@ -49,6 +49,26 @@ import glob # This script was generated while the user was using the ctattach # tools. That had better still be the case. +def deCygwinify(path): + if os.name in ['nt'] and path[0] == '/': + # On Windows, we may need to convert from a Cygwin-style path + # to a native Windows path. + + # Check for a case like /i/ or /p/: this converts + # to i:/ or p:/. + + dirs = path.split('/') + if len(dirs) > 2 and len(dirs[1]) == 1: + path = '%s:\%s' % (dirs[1], '\\'.join(dirs[2:])) + + else: + # Otherwise, prepend $PANDA_ROOT and flip the slashes. + pandaRoot = os.getenv('PANDA_ROOT') + if pandaRoot: + path = os.path.normpath(pandaRoot + path) + + return path + ctprojs = os.getenv('CTPROJS') if not ctprojs: print "You are no longer attached to any trees!" @@ -59,13 +79,15 @@ if not directDir: print "You are not attached to DIRECT!" sys.exit(1) -# Make sure that direct/src/showbase/sitecustomize.py gets loaded. +directDir = deCygwinify(directDir) + +# Make sure that direct.showbase.FindCtaPaths gets imported. parent, base = os.path.split(directDir) if parent not in sys.path: sys.path.append(parent) -import direct.showbase.sitecustomize +import direct.showbase.FindCtaPaths #endif @@ -105,6 +127,7 @@ packages.reverse() for package in packages: packageDir = os.getenv(package) if packageDir: + packageDir = deCygwinify(packageDir) etcDir = os.path.join(packageDir, 'etc') try: inFiles = glob.glob(os.path.join(etcDir, '*.in')) @@ -113,7 +136,7 @@ for package in packages: if inFiles: DoGenPyCode.etcPath.append(etcDir) - if package not in ['DTOOL', 'DIRECT', 'PANDA']: + if package not in ['WINTOOLS', 'DTOOL', 'DIRECT', 'PANDA']: libDir = os.path.join(packageDir, 'lib') try: files = os.listdir(libDir) diff --git a/direct/src/fsm/Sources.pp b/direct/src/fsm/Sources.pp new file mode 100644 index 0000000000..e69de29bb2 diff --git a/direct/src/gui/Sources.pp b/direct/src/gui/Sources.pp new file mode 100644 index 0000000000..e69de29bb2 diff --git a/direct/src/particles/Sources.pp b/direct/src/particles/Sources.pp new file mode 100644 index 0000000000..e69de29bb2 diff --git a/direct/src/pyinst/Sources.pp b/direct/src/pyinst/Sources.pp new file mode 100644 index 0000000000..e69de29bb2 diff --git a/direct/src/showbase/FindCtaPaths.py b/direct/src/showbase/FindCtaPaths.py new file mode 100755 index 0000000000..0575734066 --- /dev/null +++ b/direct/src/showbase/FindCtaPaths.py @@ -0,0 +1,98 @@ +"""This module is used only by the VR Studio programmers who are using +the ctattach tools. It is imported before any other package, and its +job is to figure out the correct paths to each of the packages. + +This module is not needed if you are not using ctattach; in this case +all of the Panda packages will be collected under a common directory, +which you will presumably have already on your PYTHONPATH. """ + +import os +import sys + +def deCygwinify(path): + if os.name in ['nt'] and path[0] == '/': + # On Windows, we may need to convert from a Cygwin-style path + # to a native Windows path. + + # Check for a case like /i/ or /p/: this converts + # to i:\ or p:\. + + dirs = path.split('/') + if len(dirs) > 2 and len(dirs[1]) == 1: + path = '%s:\%s' % (dirs[1], '\\'.join(dirs[2:])) + + else: + # Otherwise, prepend $PANDA_ROOT and flip the slashes. + pandaRoot = os.getenv('PANDA_ROOT') + if pandaRoot: + path = os.path.normpath(pandaRoot + path) + + return path + +def getPaths(): + """ + Add to sys.path the appropriate director(ies) to search for the + various Panda projects. Typically, these will all be in the same + directory (which is presumably already on sys.path), but if the VR + Studio ctattach tools are in use they could be scattered around in + several places. + """ + + ctprojs = os.getenv("CTPROJS") + if ctprojs: + # The CTPROJS environment variable is defined. We must be + # using the ctattach tools. In this case, we need to figure + # out the location of each of the separate trees, and put the + # parent directory of each one on sys.path. In many cases, + # these will all be siblings, so we filter out duplicate + # parent directories. + + print 'Appending to sys.path based on $CTPROJS:' + + # First, get the list of packages, then reverse the list to + # put it in ctattach order. (The reversal may not matter too + # much these days, but let's be as correct as we can be.) + packages = [] + for proj in ctprojs.split(): + projName = proj.split(':')[0] + packages.append(projName) + packages.reverse() + + # Now walk through the packages and figure out the parent of + # each referenced directory. + + parents = [] + for package in packages: + tree = os.getenv(package) + if not tree: + print " CTPROJS contains %s, but $%s is not defined." % (package, package) + sys.exit(1) + + tree = deCygwinify(tree) + + parent, base = os.path.split(tree) + if base != package.lower(): + print " Warning: $%s refers to a directory named %s (instead of %s)" % (package, base, package.lower()) + + if parent not in parents: + parents.append(parent) + + + # We also put tree/lib on sys.path by hand, because we + # will need to load up the generated C++ modules that got + # put there. Also, we will find the output of genPyCode + # in $DIRECT/lib/pandac. + libdir = os.path.join(tree, 'lib') + if os.path.isdir(libdir): + if libdir not in sys.path: + sys.path.append(libdir) + + + # Now the result goes onto sys.path. + for parent in parents: + print " %s" % (parent) + if parent not in sys.path: + sys.path.append(parent) + + +getPaths() diff --git a/direct/src/showbase/sitecustomize.py b/direct/src/showbase/sitecustomize.py index 83496eaf82..7934424b1e 100644 --- a/direct/src/showbase/sitecustomize.py +++ b/direct/src/showbase/sitecustomize.py @@ -1,160 +1,37 @@ +"""This is a VR Studio custom script to make sure sys.path is set up +properly from the ctattach tools. It's not needed if you aren't using +ctattach, and its use is even somewhat deprecated for the VR Studio.""" + import os import sys -import glob -print 'Site customize for Panda:' +def deCygwinify(path): + if os.name in ['nt'] and path[0] == '/': + # On Windows, we may need to convert from a Cygwin-style path + # to a native Windows path. + # Check for a case like /i/ or /p/: this converts + # to I:/ or P:/. -def readpth(tree, fullname): - #print "readpth(tree=%s, fullname=%s)" % (tree, fullname) - try: - f = open(fullname) - print ' Appending paths in ' + fullname - except IOError: - print ' IOError Appending paths in ' + fullname - return + dirs = path.split('/') + if len(dirs) > 2 and len(dirs[1]) == 1: + path = '%s:\%s' % (dirs[1], '\\'.join(dirs[2:])) - while 1: - dir = f.readline() - if not dir: - break - if dir[0] == '#': - continue - if dir[-1] == '\n': - dir = dir[:-1] - dir = os.path.join(tree, dir) - if dir not in sys.path and os.path.exists(dir): - sys.path = [dir] + sys.path - -def addpackage(package): - """ - Look in this package name for the file $PACKAGE/etc/package.pth - which contains paths that we want prepended to sys.path - There should be one relative pathname per line (relative to $PACKAGE) - comments and empty lines are ok - """ - tree = os.getenv(package) - if tree == None: - print " $%s is not defined." % (package,) - return - - lowerPackage = package.lower() - fullname = os.path.join(tree, 'etc', lowerPackage + '.pth') - - readpth(tree, fullname) - -def getPackages(): - """ - Find all the packages on your ctprojs variable and parse them - to extract the tree name from the long details like this: - TOONTOWN:default DIRECT:default PANDA:personal DTOOL:install - Returns a list of the packages as strings - Note: the ctprojs are reversed to put them in the order of attachment. - """ - ctprojs = os.getenv("CTPROJS") - if ctprojs == None: - # The CTPROJS environment variable isn't defined. Assume - # we're running from the directory above all of the source - # trees; look within these directories for the *.pth files. - - # If PLAYER is defined, use that as the root; otherwise, use - # the current directory. - player = os.getenv("PLAYER") - if player == None: - print ' Appending paths based on current working directory.' - searchstr = os.path.join('*', 'src', 'configfiles', '*.pth') else: - print ' Appending paths based on $PLAYER' - searchstr = os.path.join(player, '*', 'src', 'configfiles', '*.pth') - - filenames = glob.glob(searchstr) - if len(filenames) == 0: - print '' - print ' Warning: no files found matching %s.' % (searchstr) - print ' Check $PLAYER, or your starting directory.' - print '' - - for filename in filenames: - tree = os.path.dirname(os.path.dirname(os.path.dirname(filename))) - readpth(tree, filename) + # Otherwise, prepend $PANDA_ROOT and flip the slashes. + pandaRoot = os.getenv('PANDA_ROOT') + if pandaRoot: + path = os.path.normpath(pandaRoot + path) - else: - # The CTPROJS environment variable *is* defined. We must be - # using the ctattach tools; get the *.pth files from the set - # of attached trees. - print ' Appending paths based on $CTPROJS' - packages = [] + return path - for proj in ctprojs.split(): - projName = proj.split(':')[0] - packages.append(projName) - packages.reverse() - - for package in packages: - addpackage(package) - - -def getPath(): - """ - Add to sys.path the appropriate director(ies) to search for the - various Panda projects. Typically, these will all be in the same - directory (which is presumably already on sys.path), but if the VR - Studio ctattach tools are in use they could be scattered around in - several places. - """ - - ctprojs = os.getenv("CTPROJS") - if ctprojs: - # The CTPROJS environment variable is defined. We must be - # using the ctattach tools. In this case, we need to figure - # out the location of each of the separate trees, and put the - # parent directory of each one on sys.path. In many cases, - # these will all be siblings, so we filter out duplicate - # parent directories. - - print ' Appending to sys.path based on $CTPROJS:' - - # First, get the list of packages, then reverse the list to - # put it in ctattach order. (The reversal may not matter too - # much these days, but let's be as correct as we can be.) - packages = [] - for proj in ctprojs.split(): - projName = proj.split(':')[0] - packages.append(projName) - packages.reverse() - - # Now walk through the packages and figure out the parent of - # each referenced directory. - - parents = [] - for package in packages: - tree = os.getenv(package) - if tree == None: - print " CTPROJS contains %s, but $%s is not defined." % (package, package) - sys.exit(1) - - parent, base = os.path.split(tree) - if base != package.lower(): - print " Warning: $%s refers to a directory named %s (instead of %s)" % (package, base, package.lower()) - - if parent not in parents: - parents.append(parent) - - - # We also put tree/lib on sys.path by hand, because we - # will need to load up the generated C++ modules that got - # put there. Also, we will find the output of genPyCode - # in $DIRECT/lib/pandac. - libdir = os.path.join(tree, 'lib') - if os.path.isdir(libdir): - sys.path.append(libdir) - - - # Now the result goes onto sys.path. - for parent in parents: - print " %s" % (parent) - sys.path.append(parent) +if os.getenv('CTPROJS'): + tree = os.getenv('DIRECT') + if not tree: + raise StandardError,'CTPROJS is defined, but you are not attached to DIRECT!' + tree = deCygwinify(tree) + parent, base = os.path.split(tree) + if parent not in sys.path: + sys.path.append(parent) - -#getPackages() -getPath() + import direct.showbase.FindCtaPaths diff --git a/direct/src/showutil/Sources.pp b/direct/src/showutil/Sources.pp new file mode 100644 index 0000000000..e69de29bb2 diff --git a/direct/src/task/Sources.pp b/direct/src/task/Sources.pp new file mode 100644 index 0000000000..e69de29bb2