By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,768 Members | 1,871 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,768 IT Pros & Developers. It's quick & easy.

Advice from distutils experts?

P: n/a
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

Mar 4 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
ol*****@verizon.net wrote:
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
ro*********@gmail.com

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

Mar 4 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.