def run(config=('package.cfg', ), ext=None, script_args=None, manifest_only=0):
    """ Main runner """
    if ext is None:
        ext = []

    cfg = _util.SafeConfigParser()
    cfg.read(config)
    pkg = dict(cfg.items('package'))
    python_min = pkg.get('python.min') or None
    python_max = pkg.get('python.max') or None
    check_python_version('python', python_min, python_max)
    pypy_min = pkg.get('pypy.min') or None
    pypy_max = pkg.get('pypy.max') or None
    check_python_version('pypy', pypy_min, pypy_max)
    jython_min = pkg.get('jython.min') or None
    jython_max = pkg.get('jython.max') or None
    check_python_version('jython', jython_min, jython_max)

    manifest = dict(cfg.items('manifest'))
    try:
        docs = dict(cfg.items('docs'))
    except _config_parser.NoSectionError:
        docs = {}

    summary, description = find_description(docs)
    scripts = manifest.get('scripts', '').strip() or None
    if scripts:
        scripts = scripts.split()
    modules = manifest.get('modules', '').strip() or None
    if modules:
        modules = modules.split()
    keywords = docs.get('meta.keywords', '').strip() or None
    if keywords:
        keywords = keywords.split()
    revision = pkg.get('version.revision', '').strip()
    if revision:
        revision = "-r%s" % (revision, )

    kwargs = {
        'name':
        pkg['name'],
        'version':
        "%s%s" % (
            pkg['version.number'],
            ["", "-dev%s" % (revision, )][_util.humanbool(
                'version.dev', pkg.get('version.dev', 'false'))],
        ),
        'provides':
        find_provides(docs),
        'description':
        summary,
        'long_description':
        description,
        'classifiers':
        find_classifiers(docs),
        'keywords':
        keywords,
        'author':
        pkg['author.name'],
        'author_email':
        pkg['author.email'],
        'maintainer':
        pkg.get('maintainer.name'),
        'maintainer_email':
        pkg.get('maintainer.email'),
        'url':
        pkg.get('url.homepage'),
        'download_url':
        pkg.get('url.download'),
        'license':
        find_license(docs),
        'package_dir': {
            '': manifest.get('packages.lib', '.')
        },
        'packages':
        find_packages(manifest),
        'py_modules':
        modules,
        'ext_modules':
        ext,
        'scripts':
        scripts,
        'script_args':
        script_args,
        'data_files':
        find_data(pkg['name'], docs),
        'cmdclass': {
            'build': _commands.Build,
            'build_ext': _commands.BuildExt,
            'install': _commands.Install,
            'install_data': _commands.InstallData,
            'install_lib': _commands.InstallLib,
        }
    }
    for key in ('provides', ):
        if key not in _core.setup_keywords:
            del kwargs[key]

    if manifest_only:
        return make_manifest(manifest, config, docs, kwargs)

    # monkey-patch crappy manifest writer away.
    from distutils.command import sdist
    sdist.sdist.get_file_list = sdist.sdist.read_manifest

    return _core.setup(**kwargs)
Exemple #2
0
def epydoc(**kwargs):
    """ Run epydoc """
    # pylint: disable = R0912
    prog = kwargs.get('epydoc') or 'epydoc'
    if not _os.path.dirname(_os.path.normpath(prog)):
        prog = _shell.frompath(prog)
    if not prog:
        _term.red("%(epydoc)s not found",
            epydoc=kwargs.get('epydoc') or 'epydoc',
        )
        return False

    version = _VERSION_SEARCH(_shell.spawn(prog, "--version", stdout=True))
    if version is not None:
        try:
            version = tuple(map(int, version.group('major', 'minor')))
        except (TypeError, ValueError):
            version = None
    if version is None:
        _term.red("%(prog)s version not recognized" % locals())
        return False

    if version < (3, 0):
        _term.red("%(prog)s is too old %(version)r < (3, 0)" % locals())
        return False

    env = dict(_os.environ)

    prepend = kwargs.get('prepend')
    if prepend:
        toprepend = _os.pathsep.join(map(str, prepend))
        if 'PYTHONPATH' in env:
            env['PYTHONPATH'] = _os.pathsep.join((
                toprepend, env['PYTHONPATH']
            ))
        else:
            env['PYTHONPATH'] = toprepend

    append = kwargs.get('append')
    if append:
        toappend = _os.pathsep.join(map(str, append))
        if 'PYTHONPATH' in env:
            env['PYTHONPATH'] = _os.pathsep.join((
                env['PYTHONPATH'], toappend
            ))
        else:
            env['PYTHONPATH'] = toappend

    moreenv = kwargs.get('env')
    if moreenv:
        env.update(moreenv)

    config = kwargs.get('config') or _shell.native('docs/epydoc.conf')

    argv = [prog, '--config', config]
    res = not _shell.spawn(*argv, **{'env': env})
    if res:
        cfg = _util.SafeConfigParser()
        cfg.read(config)
        try:
            target = dict(cfg.items('epydoc'))['target']
        except KeyError:
            pass
        else:
            _cleanup_epydoc(target)
    return res