[Distutils] Question on using distutils.core.run_setup
Phillip J. Eby
pje at telecommunity.com
Wed Mar 19 16:53:12 CET 2008
At 07:00 AM 3/19/2008 +0100, Terry Jones wrote:
> >>>>> "Phillip" == Phillip J Eby <pje at telecommunity.com> writes:
>Phillip> It'd be on the 'install_lib' command instance, not the
>Phillip> distribution. Try
>Phillip> dist.get_finalized_command('install_lib').install_dir instead.
> >>
> >> For the record / archives, I think this should be
> >> dist.get_command_obj('install_lib').install_dir
>
>Phillip> No, it shouldn't. Check again. :)
>
>I get this (using the simplistic direct invocation of run_setup):
>
> $ python
> Python 2.5 (r25:51918, Sep 19 2006, 08:49:13)
> [GCC 4.0.1 (Apple Computer, Inc. build 5341)] on darwin
> Type "help", "copyright", "credits" or "license" for more information.
> >>> from distutils.core import run_setup
> >>> d = run_setup('setup.py', ['-q', 'install'])
> >>> d.get_finalized_command('install_lib').install_dir
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> AttributeError: Distribution instance has no attribute
> 'get_finalized_command'
> >>> d.get_command_obj('install_lib').install_dir
>
>'/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/'
>
>I guess I'm missing something here?
Whoops, my bad. 'get_finalized_command' is a distutils *command
object* method, not a distribution method. I usually work with code
in command objects much more than with distribution objects.
The difference, though, between get_finalized_command() and
get_command_obj() is that the latter is not guaranteed to return a
*finalized* command, i.e., one that has processed its config file and
command-line options. I would personally call .ensure_finalized() on
the command object before checking its install_dir. (This is done
automatically by cmd.get_finalized_command(), which is why I usually
use it, hence the confusion.)
More information about the Distutils-SIG
mailing list