#!/usr/bin/python # Copyright (c) 2005 by Mark T. Holder, Florida State University. (see end of file) import sys, os _PACKAGENAME = 'PIPRes' _VERSION = '0.01' _AUTHOR = 'Mark Holder' # should change this to cipres-dev if others contribute to the python code _AUTHOR_EMAIL = 'mholder@csit.fsu.edu' # should change _PACKAGE_URL = 'http://www.csit.fsu.edu/~mholder/PIPRes/' _IDLCOMPILER = 'omniidl' _CORBA_IDL_MODULE_NAME = 'CipresIDL' _PIPRES_CORBA_DIR = 'corba' def getPutativeCipresCvsRoot(): cipresTop = os.environ.get('CIPRES_TOP') if cipresTop is None: # cipresTop is our grandparent cipresTop = os.path.split(os.path.abspath(os.curdir))[0] cipresTop = os.path.split(cipresTop)[0] return cipresTop cipresIDLRoot = os.environ.get('CIPRES_IDL_DIR') if cipresIDLRoot is None: cipresTop = getPutativeCipresCvsRoot() cipresIDLRoot = os.path.join(cipresTop, 'framework','IDL') if not os.path.exists(cipresIDLRoot): cipresIDLRoot = None else: print "Using ", os.path.abspath(cipresIDLRoot), "as the CIPRES_IDL_ROOT" os.environ['CIPRES_IDL_DIR'] = cipresIDLRoot def partition(pred, iterable): '''returns a pair of lists: ([iterable items for which pred is True], [iterable items for which pred is False])''' tList = [] fList = [] for i in iterable: if pred(i): tList.append(i) else: fList.append(i) return tList, fList if 0: # the following darwin-specific code snippet came from PyXML's setup.py # LDFLAGS is later used in compiling extensions. I've included this # as a reminder of the issues I've had with mac library loading. # When building extensions, I'll need to delve into this. from distutils.sysconfig import get_config_var LDFLAGS = [] if sys.platform.startswith("darwin"): # Fixup various Mac OS X issues if get_config_var("LDSHARED").find("-flat_namespace") == -1: LDFLAGS.append('-flat_namespace') if get_config_var("LDFLAGS").find("-arch i386") != -1: # Remove the erroneous duplicate -arch flag globally new_flags = get_config_var('LDFLAGS').replace('-arch i386', '') get_config_vars()['LDFLAGS'] = new_flags ################################################################################ # Start processing command line arguments (that we want to deal with instead # of passing on to distutils) # define PIPRes-specific setup options ################################################################################ def moveOptionsToObject(option_dict, obj): for k, v in option_dict.iteritems(): obj.__dict__[k.lstrip('-')] = v[0] def printVersionInfo(outStream): print >>outStream, sys.argv[0], 'version', _VERSION def printHelpMessage(outStream, buildTool = None, phycRoot = None): global optDict printVersionInfo(outStream) print >>outStream, 'In addition to distutils options (the', _PACKAGENAME, 'setup script) recognizes the following options relevant to ', if len(installOptions) > 0: print >>outStream, 'users installing the software:' for k, v in optDict.iteritems(): opt = (k[-1] == ':' or k[-1] == '=') and k[:-1] or k print >>outStream, '%-15s%s' % (opt, v[1]) print >>outStream, '=============================================================' print >>outStream, 'developers creating a distribution may also use the follwing options: ' else: print >>outStream, 'developers creating a distribution:' for k, v in developerOptions.iteritems(): opt = (k[-1] == ':' or k[-1] == '=') and k[:-1] or k print >>outStream, '%-15s%s' % (opt, v[1]) print >>outStream, _IDLCOMPILER, 'will be used to compile idl files to python (when needed).' if cipresIDLRoot is not None: print >>outStream, 'The IDL files used reside in', cipresIDLRoot print >>outStream, '=============================================================' print >>outStream, 'What follows are options from the distutils package' print >>outStream, '=============================================================' developerOptions = { '--idlcompile': [ False, '''Perform omniidl compilation for all changed IDL files (supported by PIPRes) before making the distribution''' ], '--fidlcompile': [ False, '''Force omniidl compilation for ALL IDL files (supported by PIPRes) before making the distribution''' ], '--help': [ False, 'Display this help message.'], '--idlroot:': [ False, '''Specify path to CIPRES IDL directory (overrides the CIPRES_IDL_ROOT environmental setting)'''], '-h': [ False, 'Display this help message.'], } installOptions = {} optDict = developerOptions optDict.update(installOptions) class Options: pass options = Options() moveOptionsToObject(optDict, options) for k in filter(lambda x : str(x)[1] != '-', optDict.iterkeys()): # delete all of the single - options del options.__dict__[k.lstrip('-')] def compileIDLFiles(idlDir, destDir, cosIDLPath, recursive=True, **kwargs): "kwargs['parents'] can be a list of parent directories" import stat pathsep = '/' parents = kwargs.get('parents',[]) curDir = pathsep.join([idlDir] + list(parents)) if not (curDir and os.path.exists(curDir)): sys.exit('The path %s (the specified CIPRES_IDL_DIR) does not exist' % curDir) if not os.path.exists(destDir): os.mkdir(destDir) idlFiles = filter(lambda x : str(x).endswith('.idl'), os.listdir(curDir)) package = '.'.join([_PACKAGENAME, _PIPRES_CORBA_DIR] + parents) print curDir for i in idlFiles: fp = [curDir] + [i] iPath = pathsep.join(fp) idlName = os.path.splitext(i)[0] pyMapped = os.path.join(destDir, idlName + '_idl.py') if options.fidlcompile or not os.path.exists(pyMapped) or os.stat(pyMapped)[stat.ST_MTIME] < os.stat(iPath)[stat.ST_MTIME]: if _IDLCOMPILER == 'omniidl': cmd = 'omniidl -I%s -I%s -DRENDEZ_VOUS -bpython -Wbpackage=%s %s' % (idlDir, cosIdlPath, package, iPath) else: sys.exit('The idl compiler %s is not currently support in %s' %(_IDLCOMPILER, sys.argv[0])) print cmd if os.system(cmd): print cmd, 'failed.\nBailing out.' else: print i, 'is up to date.' #this is a real hack, but we need CosEvent to be in the same package write now (this will generate the python code in every directory!) cmd = 'omniidl -I%s -bpython -Wbpackage=%s %s' % (cosIdlPath, package, os.path.join(cosIdlPath, 'CosEventChannelAdmin.idl')) if os.system(cmd): sys.exit('%s failed.\nBailing out.' % cmd) cmd = 'omniidl -I%s -bpython -Wbpackage=%s %s' % (cosIdlPath, package, os.path.join(cosIdlPath, 'CosEventComm.idl')) if os.system(cmd): sys.exit('%s failed.\nBailing out.' % cmd) if not recursive: return True for i in os.listdir(curDir): fp = os.path.join(curDir, i) if os.path.isdir(fp) and not i == '.svn': childParent = parents + [i] compileIDLFiles(idlDir, os.path.join(destDir, i), cosIDLPath, recursive=True, parents=childParent) iterArgs = iter(sys.argv) unparsed = [] # bug I need to change to removing args from sys.argv rebinding sys.argv (below) is not # affecting the invoking args so that when dist utils uses sys.argv it gets my options too. if len(sys.argv) == 1: print 'At least one argument is required.' sys.argv.append('--help') unparsed.append('--help') for a in iterArgs: if a == '--help' or a == '-h': options.help = True elif a == '--idlroot' or a == '--idlroot=': cipresIDLRoot = iterArgs.next() elif a == '--idlcompile': options.idlcompile = True elif a == '--fidlcompile': options.idlcompile = True options.fidlcompile = True else: unparsed.append(a) sys.argv = unparsed ################################################################################ # end option parsing at this point all user specified flags should be # data members in the "options" object ################################################################################ if options.help: printHelpMessage(sys.stdout, sys.argv[0]) sys.argv.append('--help') #replace the help flag that we removed else: if options.idlcompile: relPathToCorbaDir = os.path.join(_PACKAGENAME, _PIPRES_CORBA_DIR) if not 'OMNIORB_SHARE_DIR' in os.environ: cipresTop = getPutativeCipresCvsRoot() putativeShare = os.path.abspath(os.path.join(cipresTop, 'cipres_dist', 'share')) if os.path.exists(putativeShare): print 'Using', putativeShare, 'as the OMNIORB_SHARE_DIR' os.environ['OMNIORB_SHARE_DIR'] = putativeShare else: sys.exit('OMNIORB_SHARE_DIR must be defined') cosIdlPath = os.path.expandvars(os.path.join('$OMNIORB_SHARE_DIR', 'idl', 'omniORB', 'COS')) compileIDLFiles(cipresIDLRoot, relPathToCorbaDir, cosIdlPath) from distutils.core import setup fullCorbaModule = _PACKAGENAME + '.' + _PIPRES_CORBA_DIR fullCorbaIDLModule = fullCorbaModule + '.' + _CORBA_IDL_MODULE_NAME fullCorbaIDLPOAModule = fullCorbaIDLModule + '__POA' allPackages = [ _PACKAGENAME, fullCorbaModule, fullCorbaIDLModule, fullCorbaIDLPOAModule, _PACKAGENAME + '.service_impl', _PACKAGENAME + '.nexus', ] if len(unparsed) < 2 and not options.help: # don't go to distutils.setup with out a command. sys.exit(0) setup( name = _PACKAGENAME, version = _VERSION, description = "Python infrastructure for phylogenetic research", author = _AUTHOR, author_email = _AUTHOR_EMAIL, url = _PACKAGE_URL, packages = allPackages, classifiers = [ 'Development Status :: 3 - Alpha', 'Environment :: Console', 'Intended Audience :: Science/Research', 'License :: OSI Approved :: GNU Library or Lesser General Public License (LGPL)', 'Natural Language :: English', 'Operating System :: OS Independent', 'Programming Language :: Python', 'Topic :: Scientific/Engineering :: Bio-Informatics' ], license = 'GNU Lesser General Public License (see LICENCE.txt and LGPL.txt)' ) try: __import__('omniORB') except ImportError: print >>sys.stderr, 'Use of any corba-related portion of PIPRes requires the omniORBPy package, available from\n\thttp://omniorb.sourceforge.net/index.html' # The PIPRes library is free software; you can redistribute it # and/or modify it under the terms of the GNU Lesser General # Public License as published by the Free Software Foundation; # either version 2.1 of the License, or (at your option) any later # version. # # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free # Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, # MA 02111-1307, USA