[Distutils] using sub_commands in distutils

P.J. Eby pje at telecommunity.com
Fri May 14 18:55:42 CEST 2010

At 06:10 PM 5/14/2010 +0200, Manlio Perillo wrote:
>P.J. Eby ha scritto:
> > At 05:53 PM 5/14/2010 +0200, Manlio Perillo wrote:
> >> By the way: in order to get messages compiled, should I just subclass
> >> build and develop commands?
> >
> > I don't understand your question.
> >
>I want messages to be compiled (using compile_catalog distutils command
>from babel) in all these cases:
>1) create a binary distribution
>2) create an egg
>3) running the setup using develop command
> > [...]
> >
> > Personally, however, if I had to do what you're doing, I'd package a
> > build_mo command as a setuptools plugin, and add it to my build_requires
> > dependencies.  That way, I could use it with multiple projects.
>This is indeed what I'm doing, using babel.
>However I noted that running
>   python setup.py develop
>does not execute the compile_catalog command.

Ah.  Okay, so yes, you'd need to subclass develop as well as 
bdist_egg.  An easier way, however, might be to define aliases in setup.cfg:

develop = build_mo develop
bdist_egg = build_mo bdist_egg
... etc.

Another alternative would be to use an egg_info.writers entry point 
-- the egg_info command gets called for install, develop, bdist_egg, 
and all other bdist_* installation scenarios.  The doc is here:


It's a bit of a hack, in that you wouldn't actually be generating an 
egg-info file.  You'd do something like:

   def my_writer(cmd, basename, filename):

as your writer function.  Sadly, this is perhaps the easiest way to 
extend the build process in the current distribution tools 
environment.  (Hopefully, the build_mo command will not do too much 
unnecessary processing.)

Still another way to accomplish this, would be to add your built 
files to your source distribution(s), so that recipients don't need 
to do it themselves.  (Of course, that won't work if the files are 

More information about the Distutils-SIG mailing list