[Python-Dev] addressing distutils inability to track file dependencies

Martin Sjögren martin@strakt.com
Fri, 14 Jun 2002 15:23:00 +0200


On Fri, Jun 14, 2002 at 04:25:15AM -0400, Jeremy Hylton wrote:
>   MS> Cool. But my module consists of several .c files, how do I
>   MS> specify which .o files depend on which .h files?
> 
> I did something simpler, as Guido mentioned.  I added global
> dependencies for an extension.  This has been fine for all the
> extensions that I commonly build because they have only one or several
> source files.  Recompiling a few .c files costs little.
> 
> I agree that it would be nice to have fine-grained dependency
> tracking, but that costs more in the implementation and to use.
> Thomas Heller has a patch on SF (don't recall the number) that handles
> per-file dependencies.  I didn't care for the way the dependencies are
> spelled in the setup script, but something like the dict that Martin
> (the other Martin, right?) suggested seems workable.

  Extension('foo', ['foo1.c', 'foo2.c'], dependencies={'foo1.c':
    ['bar.h'], 'foo2.c': ['bar.h', 'bar2.h']})

That's what I suggested, is that what you meant?

>   MS> Now, it's a shame I have to maintain compatability with the
>   MS> Python 2.1 and Python 2.2 distributions in my setup.py ;)
>   MS> I suppose I could try/except...
> 
> We should come up with a good hack to use in setup scripts.  This is
> my first try.  It's got too many lines, but it works.
> 
> # A hack to determine if Extension objects support the depends keyword =
arg.
> if not "depends" in Extension.__init__.func_code.co_varnames:
>     # If it doesn't, create a local replacement that removes depends
>     # from the kwargs before calling the regular constructor.
>     _Extension = Extension
>     class Extension(_Extension):
>         def __init__(self, name, sources, **kwargs):
>             if "depends" in kwargs:
>                 del kwargs["depends"]
>             _Extension.__init__(self, name, sources, **kwargs)

Eep :) Looks like it could work, yes, but I think I'll skip that one while
I'm still running Python 2.2. :)


Cheers,
Martin

-- 
Martin Sjögren
  martin@strakt.com              ICQ : 41245059
  Phone: +46 (0)31 7710870       Cell: +46 (0)739 169191
  GPG key: http://www.strakt.com/~martin/gpg.html