[Distutils] converting a distutil command to setuptools

Jorge Vargas jorge.vargas at gmail.com
Sat Jun 30 10:47:45 CEST 2007


I'm porting a distutils package to setuptools they have a Command that
takes the po files and compiles them and then they are feeding a cmd
Class to distutils, I read in the docs that the way of doing this in
setuptools is with an entry point and that the entry point should be
provided by a preinstalled package, the problem I see with that is
that we'll need 2 packages to install one so is there a better way to
do the following?

from distutils.command.build import build as _build
import msgfmt #this is the compiler

class build_trans(cmd.Command):
    description = 'Compile .po files into .mo files'

    def initialize_options(self):

    def finalize_options(self):

    def run(self):
        po_dir = os.path.join(os.path.dirname(__file__), 'po')
        for path, names, filenames in os.walk(po_dir):
            for f in filenames:
                if f.endswith('.po'):
                    lang = f[:len(f) - 3]
                    src = os.path.join(path, f)
                    dest_path = os.path.join('build', 'locale', lang,
                    dest = os.path.join(dest_path, 'deluge.mo')
                    if not os.path.exists(dest_path):
                    if not os.path.exists(dest):
                        print 'Compiling %s' % src
                        msgfmt.make(src, dest)
                        src_mtime = os.stat(src)[8]
                        dest_mtime = os.stat(dest)[8]
                        if src_mtime > dest_mtime:
                            print 'Compiling %s' % src
                            msgfmt.make(src, dest)

class build(_build):
    sub_commands = _build.sub_commands + [('build_trans', None)]
    def run(self):

Also is there any setuptools enhancement to Extension, to handle C++
compilation and dependencies check?

More information about the Distutils-SIG mailing list