def build_dist(srcdir, destdir='.', build_type='bdist_egg'):
    """
    Builds a distribution using the specified source directory and places
    it in the specified destination directory.
    
    srcdir: str
        Source directory for the distribution to be built.
        
    destdir: str
        Directory where the built distribution file will be placed.

    build_type: str
        The type of distribution to be built.  Default is 'bdist_egg'.
    """
    startdir = os.getcwd()
    destdir = os.path.abspath(os.path.expanduser(destdir)).replace('\\','/')
    srcdir = os.path.abspath(os.path.expanduser(srcdir)).replace('\\','/')
    
    setupname = os.path.join(srcdir, 'setup.py')
    if not has_setuptools():
        setupname = make_new_setupfile(setupname)

    dirfiles = set(os.listdir(destdir))
    
    print "building distribution in %s" % srcdir
    
    cmd = [sys.executable.replace('\\','/'),
           os.path.basename(setupname),
        ]
    cmd.extend(build_type.split(' '))
    cmd.extend(['-d', destdir])

    os.chdir(srcdir)
    
    # FIXME: fabric barfs when running this remotely due to some unicode
    # output that it can't handle, so we first save the output to 
    # a file with unicode stripped out 
    out = codecs.open('_build_.out', 'wb', 
                      encoding='ascii', errors='replace')
    
    print 'running command: %s' % ' '.join(cmd)
    try:
        p = subprocess.Popen(' '.join(cmd), 
                             stdout=out, stderr=subprocess.STDOUT,
                             shell=True)
        p.wait()
    finally:
        out.close()
        with open('_build_.out', 'r') as f:
            print f.read()
        os.chdir(startdir)
        
    newfiles = set(os.listdir(destdir)) - dirfiles
    if len(newfiles) != 1:
        raise RuntimeError("expected one new file in in destination directory but found %s" % 
                           list(newfiles))
    if p.returncode != 0:
        raise RuntimeError("problem building distribution in %s. (return code = %s)" %
                           (srcdir, p.returncode))
    
    distfile = os.path.join(destdir, newfiles.pop())
    print distfile % 'new distribution file is %s'
    return distfile
dataset/ETHPy150Open OpenMDAO/OpenMDAO-Framework/openmdao.devtools/src/openmdao/devtools/locdistbld.py/build_dist/swapped operands of `%`