/config/PETSc/packages/petsc4py.py

https://bitbucket.org/bourdin/petsc · Python · 67 lines · 58 code · 7 blank · 2 comment · 12 complexity · 900d29277712af410f221be9b11382a1 MD5 · raw file

  1. import PETSc.package
  2. class Configure(PETSc.package.NewPackage):
  3. def __init__(self, framework):
  4. PETSc.package.NewPackage.__init__(self, framework)
  5. self.download = ['http://petsc4py.googlecode.com/files/petsc4py-1.1.1.tar.gz']
  6. self.functions = []
  7. self.includes = []
  8. self.liblist = []
  9. self.complex = 1
  10. return
  11. def setupDependencies(self, framework):
  12. PETSc.package.NewPackage.setupDependencies(self, framework)
  13. self.petscconfigure = framework.require('PETSc.Configure',self)
  14. self.numpy = framework.require('PETSc.packages.Numpy',self)
  15. self.setCompilers = framework.require('config.setCompilers',self)
  16. self.sharedLibraries = framework.require('PETSc.utilities.sharedLibraries', self)
  17. return
  18. def Install(self):
  19. import os
  20. pp = os.path.join(self.installDir,'lib','python*','site-packages')
  21. if self.setCompilers.isDarwin():
  22. apple = 'You may need to\n (csh/tcsh) setenv MACOSX_DEPLOYMENT_TARGET 10.X\n (sh/bash) MACOSX_DEPLOYMENT_TARGET=10.X; export MACOSX_DEPLOYMENT_TARGET\nbefore running make on PETSc'
  23. else:
  24. apple = ''
  25. self.logClearRemoveDirectory()
  26. self.logResetRemoveDirectory()
  27. archflags = ""
  28. if self.setCompilers.isDarwin():
  29. if self.types.sizes['known-sizeof-void-p'] == 32:
  30. archflags = "ARCHFLAGS=\'-arch i386\'"
  31. else:
  32. archflags = "ARCHFLAGS=\'-arch x86_64\'"
  33. self.addMakeRule('petsc4py','', \
  34. ['@cd '+self.packageDir+';python setup.py clean --all; '+archflags+' python setup.py install --install-lib='+os.path.join(self.installDir,'lib'),\
  35. '@echo "====================================="',\
  36. '@echo "To use petsc4py, add '+os.path.join(self.petscconfigure.installdir,'lib')+' to PYTHONPATH"',\
  37. '@echo "====================================="'])
  38. return self.installDir
  39. def configureLibrary(self):
  40. if not self.sharedLibraries.useShared:
  41. raise RuntimeError('petsc4py requires PETSc be built with shared libraries; rerun with --with-shared-libraries')
  42. self.checkDownload(1)
  43. if self.setCompilers.isDarwin():
  44. # The name of the Python library on Apple is Python which does not end in the expected .dylib
  45. # Thus see if the python library in the standard locations points to the Python version
  46. import sys
  47. import os
  48. prefix = sys.exec_prefix
  49. if os.path.isfile(os.path.join(prefix,'Python')):
  50. for i in ['/usr/lib/libpython.dylib','/opt/local/lib/libpython2.5.dylib','/opt/local/lib/libpython2.6.dylib']:
  51. if os.path.realpath(i) == os.path.join(prefix,'Python'):
  52. self.addDefine('PYTHON_LIB','"'+os.path.join(i)+'"')
  53. return
  54. raise RuntimeError('realpath of /usr/lib/libpython.dylib ('+os.path.realpath('/usr/lib/libpython.dylib')+') does not point to the expected Python library path ('+os.path.join(prefix,'Python')+') for current Python;\n')
  55. elif os.path.isfile(os.path.join(prefix,'lib','libpython.dylib')):
  56. self.addDefine('PYTHON_LIB','"'+os.path.join(prefix,'lib','libpython.dylib')+'"')
  57. else:
  58. raise RuntimeError('Unable to find Python dynamic library at prefix '+prefix)
  59. def alternateConfigureLibrary(self):
  60. self.addMakeRule('petsc4py','')