f90wrap
f90wrap copied to clipboard
Using f90wrap with distutils
It would be handy to use f90wrap from distutils directly, as is now possible with f2py.
Any plan in this direction?
Never checked the internals, it must not be too complicated...
It is about subclassing the distutils.extension.Extension class, or/and provide a new setup script, or, like cython does, defining a build_ext function to pass to setup's cmd_class.
An example here: https://github.com/perrette/python-fortran-cpp-template/blob/master/setup.py.
I will take a look at some point in 2016...
I agree with this in principle, but find distutils so horrible to work with in practice that I've stuck with plain Makefiles to date. I've been meaning to look into (mini)conda for packaging (see issue #27), but I think this still requires a distutils wrapper.
I implemented distuils support in quippy, which is essentially a special-purpose predecessor to f90wrap. Here's a link to the code, I'm sure this could be adapted relatively easily...
https://github.com/libAtoms/QUIP/blob/public/quippy/setup.py#L56
Sounds good, probably a good starting point.
I have not looked into the Extension class yet, but here is a handy workaround to copy a manually-compiled file under python site-packages, inspired by http://stackoverflow.com/a/18159969/2192272:
from distutils.core import setup
from distutils.command.install import install as _install
from distutils.command.build import build as _build
# install shared library under python site-packages
# http://stackoverflow.com/a/18159969/2192272
def _post_install(dir):
from subprocess import call
cmd = ['cp', '_MODULE.so', dir]
print(*cmd)
call(cmd)
class install(_install):
def run(self):
_install.run(self)
self.execute(_post_install, (self.install_lib,),
msg="Post-install : manually copying :_MODULE.so under site-packages")
class build(_build):
def run(self):
_build.run(self)
self.execute(_post_install, (self.build_lib,),
msg="Post-build : manually copying _MODULE.so under site-packages")
setup(name='MODULE',
cmdclass={'install': install, 'build':build},
packages = ['MODULE'],
)