[Distutils] distutils post processing

Eric S. Johansson esj at harvee.org
Tue Nov 7 21:43:30 CET 2006

Phillip J. Eby wrote:
> At 10:42 AM 11/7/2006 -0500, Eric S. Johansson wrote:
>> I'm trying to extend distutiles to do things like fix permissions etc.
>>   have a draft that works but I'm  not sure how to invoke it.  I'm
>> running it after setup() but as you would expect it always run on any
>> setup operation.  How can I limit when my code run only when it's a
>> build command?
>> I tried following the distutiles extension instructions but it is a bit
>> thin.  some pointers would be appreciated.  Thanks for your time.
> Subclass the appropriate command class, e.g. 
> distuils.command.build_ext.build_ext or whatever, extending the run() 
> method to do what you want.  Add it to the 'cmdclass' dictionary in your 
> setup() call.

  thank you.  Your advice helped by can't quite say why.  Somehow it 
closed a missing gap.  I would suggest something more like this inside 
the documentation for integrating new commands

distutils lets the developer modify different phases of the build, 
installation, and distribution processes.  By overriding one of the 
distutils/command modules, one can modify the build process for your 

It's often hard to know where to start with regards to modifying setup 
processes.  Frequently it is simpler than it first appears.  For 
example, modifying the mainline build process for pre processing and 
post processing of data requires a subclass to build and overload the 
run method.  this new run method would do the pre-and or postprocessing 
necessary.  At the right time it would also call the original run 
method.  See the example below.

class mybuild(_build):
     """Specialized Python source builder."""
     def run(self):
         # pre processing

         # normal processing

         # post processing

setup would be told about this new class using its cmdclass argument. 
This argument is a dictionary of  class name to look for (i.e. one of 
the five above) and the class associated with that name.

setup(cmdclass={'build': mybuild},


  anyway, that's some of the kind of information that would have been 
useful when I was reading the documentation.

More information about the Distutils-SIG mailing list