[Distutils] uses for setup.cfg and extracting data from it

P.J. Eby pje at telecommunity.com
Sat Sep 12 02:22:03 CEST 2009


At 08:14 AM 9/12/2009 +1000, Ben Finney wrote:
>Specifically, I want to programmatically access the metadata that is 
>held in the arguments to the ‘distutils.setup()’ call. Without, 
>as you say, executing any Distutils command. I am not aware of any 
>‘distutils’ public functions that can do that, and reading 
><URL:http://docs.python.org/distutils/> again doesn't enlighten me. 
>Would you be more specific about what these functions are?

http://docs.python.org/distutils/apiref.html#module-distutils.core - 
specifically the run_setup() function.  (It appears the docs do not 
have link anchors for individual functions, alas.)

distutils.core.run_setup("setup.py", [], "init") will return you an 
initialized Distribution object from running the setup script, 
without parsing any configuration files or executing any 
commands.  You could use "config" or "commandline" instead of "init" 
if you wanted those pieces of processing to be done as well - i.e. if 
you wanted to be sure any setup.cfg options were processed.

This will work with a sufficiently well-behaved setup.py; setup 
scripts that try to do build or install steps outside of any 
distutils command may produce side-effects when run.  (Which is why 
setuptools always runs setup scripts in a loose sandbox that detects 
when a script tries to modify the filesystem outside the setup directory.)



More information about the Distutils-SIG mailing list