amaurea
amaurea

Reputation: 5067

Numpy setuptools: How to compile fortran file as part of a module

I have a directory structure of the form

setup.py
python/
  __init__.py
  a.py
  b.f

I'd like to install this as a package called foo with the structure

site-packages/
  foo/
    __init__.py
    a.py
    b.so

but I'm at a loss as to how to write setup.py in order to achieve this. So far I have

import numpy.distutils.core
b = numpy.distutils.core.Extension(name = 'b', sources = ['python/b.f'])
numpy.distutils.core.setup(
  name = 'foo',
  version = '0.0',
  packages = ['foo'],
  package_dir = {'foo':'python'},
  ext_modules = [b]
)

But this results in

site-packages/
  foo/
    __init__.py
    a.py
  b.so

So clearly I'm missing something here. How go I get b.so to go in the foo package rather than being installed as a separate pacakge?

Upvotes: 2

Views: 833

Answers (1)

amaurea
amaurea

Reputation: 5067

To tell setuptools that a given extension module should be installed as part of package (e.g. foo) rather than on its own, it's sufficient to prefix foo. to its name. E.g. change

b = numpy.distutils.core.Extension(name = 'b', sources = ['python/b.f'])

into

b = numpy.distutils.core.Extension(name = 'foo.b', sources = ['python/b.f'])

Upvotes: 2

Related Questions