Advice from distutils experts?

O

olsongt

I'm doing something a little wierd in one of my projects. I'm
generating a C source file based on information extracted from python's
header files. Although I can just generate the file and check the
result into source control, I'd rather have the file generated during
the install process instead of doing it manually.

So I'd like to:
+ have the file generated when a unix user runs setup.py install.
+ have the file generated when I create a windows binary
distribution.
+ not have the file generated when I create source distribution
..tgz's and .zip's.

I'd appreciate any pointers on the best way to hook into disutils to do
this. And if the answer is "Your crazy, generate the file outside of
distutils." just let me know.

-Grant
 
R

Robert Kern

I'm doing something a little wierd in one of my projects. I'm
generating a C source file based on information extracted from python's
header files. Although I can just generate the file and check the
result into source control, I'd rather have the file generated during
the install process instead of doing it manually.

So I'd like to:
+ have the file generated when a unix user runs setup.py install.
+ have the file generated when I create a windows binary
distribution.
+ not have the file generated when I create source distribution
.tgz's and .zip's.

I'd appreciate any pointers on the best way to hook into disutils to do
this. And if the answer is "Your crazy, generate the file outside of
distutils." just let me know.

We do things like this in numpy. We've extended distutils to allow functions in
the sources list for Extension.

from numpy.distutils.core import Extension
from distutils.dep_util import newer

def generate_source_c(ext, build_dir):
target = os.path.join(build_dir, 'source.c')
if newer(__file__, target):
# ... parse Python headers
contents = """
#include "Python.h"
/* ... */
""" % (stuff, more_stuff)
f = open(target, 'w')
f.write(contents)
f.close()
return target

ext = Extension('my_extension',
sources=[generate_source_c],
)

setup(#...
ext_modules=[ext]
)

--
Robert Kern
(e-mail address removed)

"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top