Hi,<div><br></div><div>This may be of interest to people developing in Python and C/C++. I worked out a simple hack to use the petsc4py configuration to build Python extension modules with the correct petsc compilers and options. We had been doing this using some makefile tricks, but our approach wasn't as reliable as Lisandro's configuration of petsc4py. I had to hack two of the build_ext functions. You still have to give setup.py the --petsc-dir/--petsc-arch arguments. It might be a nice feature to install something similar in petsc4py so one could just do 'from petsc4py import PetscExtension'.</div>
<div><br></div><div>Chris </div><div><br></div><div>setup.py</div><div>-------------------</div><div><div>from distutils.core import setup</div></div><div><div>sys.path.append('/path_to_petsc4py')</div><div>from conf.petscconf import Extension as PetscExtension</div>
<div>from conf.petscconf import build_ext as petsc_build_ext</div><div>from conf.petscconf import config, build, build_src</div><div>from conf.petscconf import test, sdist</div><div><br></div><div>class my_build_ext(petsc_build_ext):</div>
<div> def build_configuration(self, arch_list):</div><div> from distutils.util import split_quoted, execute</div><div> #</div><div> template, variables = self.get_config_data(arch_list)</div><div> config_data = template % variables</div>
<div> #</div><div> build_lib = self.build_lib</div><div> dist_name = self.distribution.get_name()</div><div> config_file = os.path.join(build_lib, dist_name,'petsc.cfg')#cek hack</div>
<div> #</div><div> def write_file(filename, data):</div><div> fh = open(filename, 'w')</div><div> try: fh.write(config_data)</div><div> finally: fh.close()</div><div>
execute(write_file, (config_file, config_data),</div><div> msg='writing %s' % config_file, </div><div> verbose=self.verbose, dry_run=self.dry_run)</div><div> def _copy_ext(self, ext):</div>
<div> from copy import deepcopy</div><div> extclass = ext.__class__</div><div> fullname = self.get_ext_fullname(<a href="http://ext.name">ext.name</a>)</div><div> modpath = str.split(fullname, '.')</div>
<div> pkgpath = os.path.join('', *modpath[0:-1])</div><div> name = modpath[-1]</div><div> sources = list(ext.sources)</div><div> newext = extclass(name, sources)</div><div> newext.__dict__.update(deepcopy(ext.__dict__))</div>
<div> <a href="http://newext.name">newext.name</a> = name</div><div> pkgpath=''#cek hack</div><div> return pkgpath, newext</div><div><br></div><div>setup(name='proteus',</div><div> ext_package='proteus',</div>
<div> package_data = {'proteus' : ['petsc.cfg'],},</div><div> cmdclass = {'config' : config,</div><div> 'build' : build,</div><div> 'build_src' : build_src,</div>
<div> 'build_ext' : my_build_ext,</div><div> 'test' : test,</div><div> 'sdist' : sdist,</div><div> },</div>
<div> ext_modules=[PetscExtension('flcbdfWrappers',</div><div> ['proteus/flcbdfWrappersModule.cpp','proteus/mesh.cpp','proteus/meshio.cpp'],</div><div> define_macros=[('PROTEUS_TRIANGLE_H',PROTEUS_TRIANGLE_H),</div>
<div> ('PROTEUS_SUPERLU_H',PROTEUS_SUPERLU_H),</div><div> ('CMRVEC_BOUNDS_CHECK',1),</div><div> ('MV_VECTOR_BOUNDS_CHECK',1),</div>
<div> ('PETSCVEC_BOUNDS_CHECK',1),</div><div> ('F77_POST_UNDERSCORE',1),</div><div> ('USE_BLAS',1)],</div>
<div> include_dirs=['include',numpy.get_include(),PROTEUS_SUPERLU_INCLUDE_DIR,PROTEUS_TRIANGLE_INCLUDE_DIR]+PROTEUS_DAETK_INCLUDE_DIR+PROTEUS_PETSC_INCLUDE_DIRS+</div><div> [PROTEUS_MPI_INCLUDE_DIR],</div>
<div> library_dirs=[PROTEUS_DAETK_LIB_DIR]+PROTEUS_PETSC_LIB_DIRS+[PROTEUS_MPI_LIB_DIR],</div><div> libraries=['m',PROTEUS_DAETK_LIB]+PROTEUS_PETSC_LIBS+PROTEUS_MPI_LIBS,</div>
<div> extra_link_args=PROTEUS_EXTRA_LINK_ARGS,</div><div> extra_compile_args=PROTEUS_EXTRA_COMPILE_ARGS)])</div></div><div><br></div>