1import config.package 2import os 3 4class Configure(config.package.Package): 5 def __init__(self, framework): 6 config.package.Package.__init__(self, framework) 7 self.pyver = None 8 self.cyver = None 9 self.setuptools = 0 10 self.cython = 0 11 self.numpy = 0 12 self.path = set() 13 self.lookforbydefault = 1 14 self.skipMPIDependency = 1 15 return 16 17 def setupHelp(self,help): 18 import nargs 19 help.addArgument('PETSc', '-with-python-exec=<executable>', nargs.Arg(None, None, 'Python executable to use for mpi4py/petsc4py. The full path is used')) 20 help.addArgument('PETSc', '-with-python-exec-from-env=<executable>', nargs.Arg(None, None, 'Python executable to use for mpi4py/petsc4py. The full path is resolved at runtime using the environment; it will be determined by PATH when mpi4py/petsc4py is used')) 21 help.addArgument('PETSc', '-have-numpy=<bool>', nargs.ArgBool(None, None, 'Whether numpy python module is installed (default: autodetect)')) 22 return 23 24 def configure(self): 25 '''determine python binary to use''' 26 if 'with-python-exec-from-env' in self.argDB: 27 self.getExecutable(os.path.basename(self.argDB['with-python-exec-from-env']), getFullPath=0, resultName='pyexe', setMakeMacro = 0) 28 if 'with-python-exec' in self.argDB: 29 raise RuntimeError("You cannot provide both -with-python-exec and -with-python-exec-from-path") 30 elif 'with-python-exec' in self.argDB: 31 self.getExecutable(self.argDB['with-python-exec'], getFullPath=1, resultName='pyexe', setMakeMacro = 0) 32 else: 33 import sys 34 self.pyexe = sys.executable 35 self.addDefine('PYTHON_EXE','"'+self.pyexe+'"') 36 self.addMakeMacro('PYTHON_EXE','"'+self.pyexe+'"') 37 self.executablename = 'pyexe' 38 self.found = 1 39 40 try: 41 self.pyver,err1,ret1 = config.package.Package.executeShellCommand([self.pyexe,'-c','import sysconfig;print(sysconfig.get_python_version())'],timeout=60, log = self.log) 42 except: 43 self.logPrint('Unable to determine version of',self.pyexe) 44 45 try: 46 output,err1,ret1 = config.package.Package.executeShellCommand([self.pyexe,'-c','import setuptools;print(setuptools.__version__)'],timeout=60, log = self.log) 47 self.setuptools = 1 48 except: 49 self.logPrint('Python being used '+self.pyexe+' does not have the setuptools package') 50 51 try: 52 self.cyver,err1,ret1 = config.package.Package.executeShellCommand([self.pyexe,'-c','import cython;print(cython.__version__)'],timeout=60, log = self.log) 53 self.cython = 1 54 except: 55 self.logPrint('Python being used '+self.pyexe+' does not have the Cython package') 56 57 have_numpy = self.argDB.get('have-numpy', None) 58 if have_numpy is not None: 59 self.numpy = int(have_numpy) 60 else: 61 try: 62 output1,err1,ret1 = config.package.Package.executeShellCommand(self.pyexe + ' -c "import numpy"',timeout=60, log = self.log) 63 self.numpy = 1 64 except: 65 self.logPrint('Python being used '+self.pyexe+' does not have the numpy package') 66