当前位置: 首页>>代码示例>>Python>>正文


Python _Distribution.parse_config_files方法代码示例

本文整理汇总了Python中setuptools.dist._Distribution.parse_config_files方法的典型用法代码示例。如果您正苦于以下问题:Python _Distribution.parse_config_files方法的具体用法?Python _Distribution.parse_config_files怎么用?Python _Distribution.parse_config_files使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在setuptools.dist._Distribution的用法示例。


在下文中一共展示了_Distribution.parse_config_files方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: read_configuration

# 需要导入模块: from setuptools.dist import _Distribution [as 别名]
# 或者: from setuptools.dist._Distribution import parse_config_files [as 别名]
def read_configuration(
        filepath, find_others=False, ignore_option_errors=False):
    """Read given configuration file and returns options from it as a dict.

    :param str|unicode filepath: Path to configuration file
        to get options from.

    :param bool find_others: Whether to search for other configuration files
        which could be on in various places.

    :param bool ignore_option_errors: Whether to silently ignore
        options, values of which could not be resolved (e.g. due to exceptions
        in directives such as file:, attr:, etc.).
        If False exceptions are propagated as expected.

    :rtype: dict
    """
    from setuptools.dist import Distribution, _Distribution

    filepath = os.path.abspath(filepath)

    if not os.path.isfile(filepath):
        raise DistutilsFileError(
            'Configuration file %s does not exist.' % filepath)

    current_directory = os.getcwd()
    os.chdir(os.path.dirname(filepath))

    try:
        dist = Distribution()

        filenames = dist.find_config_files() if find_others else []
        if filepath not in filenames:
            filenames.append(filepath)

        _Distribution.parse_config_files(dist, filenames=filenames)

        handlers = parse_configuration(
            dist, dist.command_options,
            ignore_option_errors=ignore_option_errors)

    finally:
        os.chdir(current_directory)

    return configuration_to_dict(handlers) 
开发者ID:sofia-netsurv,项目名称:python-netsurv,代码行数:47,代码来源:config.py


注:本文中的setuptools.dist._Distribution.parse_config_files方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。