[Distutils] CWD when running compilers

Stefan Seefeld seefeld at sympatico.ca
Mon Oct 27 09:45:42 EST 2003

amk at amk.ca wrote:
> I've come across a situation that may be a Distutils bug, but I'm unsure
> if it's a bug or not.
> When Distutils runs a compiler subprocess, the current working directory is
> left alone so, in the absence of os.chdir() calls in the setup.py, it's the
> same directory as the setup.py script.  If the source file is in a
> subdirectory (e.g. src/constants.c), the CWD is therefore different from the
> directory containing the source file.
> In C you can use relative #include paths, e.g.  #include
> <../../hydra/mbv_sched/common.h>.  If the source file contains such a
> relative #include, it's natural to start from the directory containing the
> header or the source file; this is wrong, however.  
> Question: is this a bug in Distutils?  Should distutils.spawn change the CWD
> to the same directory as the source?  

In my own projects I'v always treated the source tree as read-only, i.e.
I generally build in a 'build tree' that lives outside the source tree.
Therefor, I never use relative include statements (for this and other

As this is an issue only the authors of extension modules can address, I 
think it would be best if distutils could adapt to the different models.
I believe the current way is fine, but I don't think distutils should 
impose any particular build system design.

In a nutshell: it's not a bug, just a restriction (which distutils is
already full of anyways).


More information about the Distutils-SIG mailing list