import os
from distutils.core import setup
from distutils.errors import PackagingFileError
from ConfigParser import RawConfigParser


def cfg_to_args(path='setup.cfg'):
    D1_D2_SETUP_ARGS = {"name": ("metadata",),
                        "version": ("metadata",),
                        "author": ("metadata",),
                        "author_email": ("metadata",),
                        "maintainer": ("metadata",),
                        "maintainer_email": ("metadata",),
                        "url": ("metadata", "home_page"),
                        "description": ("metadata", "summary"),
                        "long_description": ("metadata", "description"),
                        "download-url": ("metadata",),
                        "classifiers": ("metadata", "classifier"),
                        "platforms": ("metadata", "platform"),  # **
                        "license": ("metadata",),
                        "requires": ("metadata", "requires_dist"),
                        "provides": ("metadata", "provides_dist"),  # **
                        "obsoletes": ("metadata", "obsoletes_dist"),  # **
                        "package_dir": ("files", 'packages_root'),
                        "packages": ("files",),
                        "scripts": ("files",),
                        "py_modules": ("files", "modules"),  # **
                        }

    MULTI_FIELDS = ("classifiers",
                    "platforms",
                    "requires",
                    "provides",
                    "obsoletes",
                    "packages",
                    "scripts",
                    "py_modules")

    def has_get_option(config, section, option):
        if config.has_option(section, option):
            return config.get(section, option)
        elif config.has_option(section, option.replace('_', '-')):
            return config.get(section, option.replace('_', '-'))
        else:
            return False

    def split_multiline(value):
        return [element for element in
                (line.strip() for line in value.split('\n'))
                if element]

    # The real code starts here
    config = RawConfigParser()
    if not os.path.exists(path):
        raise PackagingFileError("file '%s' does not exist" %
                                 os.path.abspath(path))
    config.read(path)

    kwargs = {}
    for arg in D1_D2_SETUP_ARGS:
        if len(D1_D2_SETUP_ARGS[arg]) == 2:
            # The distutils field name is different than packaging's
            section, option = D1_D2_SETUP_ARGS[arg]

        else:
            # The distutils field name is the same thant packaging's
            section = D1_D2_SETUP_ARGS[arg][0]
            option = arg

        in_cfg_value = has_get_option(config, section, option)
        if not in_cfg_value:
            # There is no such option in the setup.cfg
            if arg == 'long_description':
                filenames = has_get_option(config, section, 'description-file')
                if filenames:
                    filenames = split_multiline(filenames)
                    in_cfg_value = []
                    for filename in filenames:
                        with open(filename) as fp:
                            in_cfg_value.append(fp.read())
                    in_cfg_value = '\n\n'.join(in_cfg_value)
            else:
                continue

        if arg == 'package_dir' and in_cfg_value:
            in_cfg_value = {'': in_cfg_value}

        if arg in MULTI_FIELDS:
            # support multiline options
            in_cfg_value = split_multiline(in_cfg_value)

        kwargs[arg] = in_cfg_value

    return kwargs


setup(**cfg_to_args())

92e702827e90e47c0087942c1d01e1f1f4973f53
<mask token>

<mask token>


def cfg_to_args(path='setup.cfg'):
    D1_D2_SETUP_ARGS = {'name': ('metadata',), 'version': ('metadata',),
        'author': ('metadata',), 'author_email': ('metadata',),
        'maintainer': ('metadata',), 'maintainer_email': ('metadata',),
        'url': ('metadata', 'home_page'), 'description': ('metadata',
        'summary'), 'long_description': ('metadata', 'description'),
        'download-url': ('metadata',), 'classifiers': ('metadata',
        'classifier'), 'platforms': ('metadata', 'platform'), 'license': (
        'metadata',), 'requires': ('metadata', 'requires_dist'), 'provides':
        ('metadata', 'provides_dist'), 'obsoletes': ('metadata',
        'obsoletes_dist'), 'package_dir': ('files', 'packages_root'),
        'packages': ('files',), 'scripts': ('files',), 'py_modules': (
        'files', 'modules')}
    MULTI_FIELDS = ('classifiers', 'platforms', 'requires', 'provides',
        'obsoletes', 'packages', 'scripts', 'py_modules')

    def has_get_option(config, section, option):
        if config.has_option(section, option):
            return config.get(section, option)
        elif config.has_option(section, option.replace('_', '-')):
            return config.get(section, option.replace('_', '-'))
        else:
            return False

    def split_multiline(value):
        return [element for element in (line.strip() for line in value.
            split('\n')) if element]
    config = RawConfigParser()
    if not os.path.exists(path):
        raise PackagingFileError("file '%s' does not exist" % os.path.
            abspath(path))
    config.read(path)
    kwargs = {}
    for arg in D1_D2_SETUP_ARGS:
        if len(D1_D2_SETUP_ARGS[arg]) == 2:
            section, option = D1_D2_SETUP_ARGS[arg]
        else:
            section = D1_D2_SETUP_ARGS[arg][0]
            option = arg
        in_cfg_value = has_get_option(config, section, option)
        if not in_cfg_value:
            if arg == 'long_description':
                filenames = has_get_option(config, section, 'description-file')
                if filenames:
                    filenames = split_multiline(filenames)
                    in_cfg_value = []
                    for filename in filenames:
                        with open(filename) as fp:
                            in_cfg_value.append(fp.read())
                    in_cfg_value = '\n\n'.join(in_cfg_value)
            else:
                continue
        if arg == 'package_dir' and in_cfg_value:
            in_cfg_value = {'': in_cfg_value}
        if arg in MULTI_FIELDS:
            in_cfg_value = split_multiline(in_cfg_value)
        kwargs[arg] = in_cfg_value
    return kwargs


<mask token>

<mask token>


def cfg_to_args(path='setup.cfg'):
    D1_D2_SETUP_ARGS = {'name': ('metadata',), 'version': ('metadata',),
        'author': ('metadata',), 'author_email': ('metadata',),
        'maintainer': ('metadata',), 'maintainer_email': ('metadata',),
        'url': ('metadata', 'home_page'), 'description': ('metadata',
        'summary'), 'long_description': ('metadata', 'description'),
        'download-url': ('metadata',), 'classifiers': ('metadata',
        'classifier'), 'platforms': ('metadata', 'platform'), 'license': (
        'metadata',), 'requires': ('metadata', 'requires_dist'), 'provides':
        ('metadata', 'provides_dist'), 'obsoletes': ('metadata',
        'obsoletes_dist'), 'package_dir': ('files', 'packages_root'),
        'packages': ('files',), 'scripts': ('files',), 'py_modules': (
        'files', 'modules')}
    MULTI_FIELDS = ('classifiers', 'platforms', 'requires', 'provides',
        'obsoletes', 'packages', 'scripts', 'py_modules')

    def has_get_option(config, section, option):
        if config.has_option(section, option):
            return config.get(section, option)
        elif config.has_option(section, option.replace('_', '-')):
            return config.get(section, option.replace('_', '-'))
        else:
            return False

    def split_multiline(value):
        return [element for element in (line.strip() for line in value.
            split('\n')) if element]
    config = RawConfigParser()
    if not os.path.exists(path):
        raise PackagingFileError("file '%s' does not exist" % os.path.
            abspath(path))
    config.read(path)
    kwargs = {}
    for arg in D1_D2_SETUP_ARGS:
        if len(D1_D2_SETUP_ARGS[arg]) == 2:
            section, option = D1_D2_SETUP_ARGS[arg]
        else:
            section = D1_D2_SETUP_ARGS[arg][0]
            option = arg
        in_cfg_value = has_get_option(config, section, option)
        if not in_cfg_value:
            if arg == 'long_description':
                filenames = has_get_option(config, section, 'description-file')
                if filenames:
                    filenames = split_multiline(filenames)
                    in_cfg_value = []
                    for filename in filenames:
                        with open(filename) as fp:
                            in_cfg_value.append(fp.read())
                    in_cfg_value = '\n\n'.join(in_cfg_value)
            else:
                continue
        if arg == 'package_dir' and in_cfg_value:
            in_cfg_value = {'': in_cfg_value}
        if arg in MULTI_FIELDS:
            in_cfg_value = split_multiline(in_cfg_value)
        kwargs[arg] = in_cfg_value
    return kwargs


setup(**cfg_to_args())

import os
from distutils.core import setup
from distutils.errors import PackagingFileError
from ConfigParser import RawConfigParser


def cfg_to_args(path='setup.cfg'):
    D1_D2_SETUP_ARGS = {'name': ('metadata',), 'version': ('metadata',),
        'author': ('metadata',), 'author_email': ('metadata',),
        'maintainer': ('metadata',), 'maintainer_email': ('metadata',),
        'url': ('metadata', 'home_page'), 'description': ('metadata',
        'summary'), 'long_description': ('metadata', 'description'),
        'download-url': ('metadata',), 'classifiers': ('metadata',
        'classifier'), 'platforms': ('metadata', 'platform'), 'license': (
        'metadata',), 'requires': ('metadata', 'requires_dist'), 'provides':
        ('metadata', 'provides_dist'), 'obsoletes': ('metadata',
        'obsoletes_dist'), 'package_dir': ('files', 'packages_root'),
        'packages': ('files',), 'scripts': ('files',), 'py_modules': (
        'files', 'modules')}
    MULTI_FIELDS = ('classifiers', 'platforms', 'requires', 'provides',
        'obsoletes', 'packages', 'scripts', 'py_modules')

    def has_get_option(config, section, option):
        if config.has_option(section, option):
            return config.get(section, option)
        elif config.has_option(section, option.replace('_', '-')):
            return config.get(section, option.replace('_', '-'))
        else:
            return False

    def split_multiline(value):
        return [element for element in (line.strip() for line in value.
            split('\n')) if element]
    config = RawConfigParser()
    if not os.path.exists(path):
        raise PackagingFileError("file '%s' does not exist" % os.path.
            abspath(path))
    config.read(path)
    kwargs = {}
    for arg in D1_D2_SETUP_ARGS:
        if len(D1_D2_SETUP_ARGS[arg]) == 2:
            section, option = D1_D2_SETUP_ARGS[arg]
        else:
            section = D1_D2_SETUP_ARGS[arg][0]
            option = arg
        in_cfg_value = has_get_option(config, section, option)
        if not in_cfg_value:
            if arg == 'long_description':
                filenames = has_get_option(config, section, 'description-file')
                if filenames:
                    filenames = split_multiline(filenames)
                    in_cfg_value = []
                    for filename in filenames:
                        with open(filename) as fp:
                            in_cfg_value.append(fp.read())
                    in_cfg_value = '\n\n'.join(in_cfg_value)
            else:
                continue
        if arg == 'package_dir' and in_cfg_value:
            in_cfg_value = {'': in_cfg_value}
        if arg in MULTI_FIELDS:
            in_cfg_value = split_multiline(in_cfg_value)
        kwargs[arg] = in_cfg_value
    return kwargs


setup(**cfg_to_args())

import os
from distutils.core import setup
from distutils.errors import PackagingFileError
from ConfigParser import RawConfigParser


def cfg_to_args(path='setup.cfg'):
    D1_D2_SETUP_ARGS = {"name": ("metadata",),
                        "version": ("metadata",),
                        "author": ("metadata",),
                        "author_email": ("metadata",),
                        "maintainer": ("metadata",),
                        "maintainer_email": ("metadata",),
                        "url": ("metadata", "home_page"),
                        "description": ("metadata", "summary"),
                        "long_description": ("metadata", "description"),
                        "download-url": ("metadata",),
                        "classifiers": ("metadata", "classifier"),
                        "platforms": ("metadata", "platform"),  # **
                        "license": ("metadata",),
                        "requires": ("metadata", "requires_dist"),
                        "provides": ("metadata", "provides_dist"),  # **
                        "obsoletes": ("metadata", "obsoletes_dist"),  # **
                        "package_dir": ("files", 'packages_root'),
                        "packages": ("files",),
                        "scripts": ("files",),
                        "py_modules": ("files", "modules"),  # **
                        }

    MULTI_FIELDS = ("classifiers",
                    "platforms",
                    "requires",
                    "provides",
                    "obsoletes",
                    "packages",
                    "scripts",
                    "py_modules")

    def has_get_option(config, section, option):
        if config.has_option(section, option):
            return config.get(section, option)
        elif config.has_option(section, option.replace('_', '-')):
            return config.get(section, option.replace('_', '-'))
        else:
            return False

    def split_multiline(value):
        return [element for element in
                (line.strip() for line in value.split('\n'))
                if element]

    # The real code starts here
    config = RawConfigParser()
    if not os.path.exists(path):
        raise PackagingFileError("file '%s' does not exist" %
                                 os.path.abspath(path))
    config.read(path)

    kwargs = {}
    for arg in D1_D2_SETUP_ARGS:
        if len(D1_D2_SETUP_ARGS[arg]) == 2:
            # The distutils field name is different than packaging's
            section, option = D1_D2_SETUP_ARGS[arg]

        else:
            # The distutils field name is the same thant packaging's
            section = D1_D2_SETUP_ARGS[arg][0]
            option = arg

        in_cfg_value = has_get_option(config, section, option)
        if not in_cfg_value:
            # There is no such option in the setup.cfg
            if arg == 'long_description':
                filenames = has_get_option(config, section, 'description-file')
                if filenames:
                    filenames = split_multiline(filenames)
                    in_cfg_value = []
                    for filename in filenames:
                        with open(filename) as fp:
                            in_cfg_value.append(fp.read())
                    in_cfg_value = '\n\n'.join(in_cfg_value)
            else:
                continue

        if arg == 'package_dir' and in_cfg_value:
            in_cfg_value = {'': in_cfg_value}

        if arg in MULTI_FIELDS:
            # support multiline options
            in_cfg_value = split_multiline(in_cfg_value)

        kwargs[arg] = in_cfg_value

    return kwargs


setup(**cfg_to_args())
