Advice from distutils experts?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • olsongt@verizon.net

    #1

    Advice from distutils experts?

    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

  • Robert Kern

    #2
    Re: Advice from distutils experts?

    olsongt@verizon .net wrote:[color=blue]
    > 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.[/color]

    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_u til import newer

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

    ext = Extension('my_e xtension',
    sources=[generate_source _c],
    )

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

    --
    Robert Kern
    robert.kern@gma il.com

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

    Comment

    Working...