autodetect.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:rcli 作者: contains-io 项目源码 文件源码
def egg_info_writer(cmd, basename, filename):
    # type: (setuptools.command.egg_info.egg_info, str, str) -> None
    """Read rcli configuration and write it out to the egg info.

    Args:
        cmd: An egg info command instance to use for writing.
        basename: The basename of the file to write.
        filename: The full path of the file to write into the egg info.
    """
    setupcfg = next((f for f in setuptools.findall()
                     if os.path.basename(f) == 'setup.cfg'), None)
    if not setupcfg:
        return
    parser = six.moves.configparser.ConfigParser()  # type: ignore
    parser.read(setupcfg)
    if not parser.has_section('rcli') or not parser.items('rcli'):
        return
    config = dict(parser.items('rcli'))
    for k, v in six.iteritems(config):
        if v.lower() in ('y', 'yes', 'true'):
            config[k] = True
        elif v.lower() in ('n', 'no', 'false'):
            config[k] = False
        else:
            try:
                config[k] = json.loads(v)
            except ValueError:
                pass
    cmd.write_file(basename, filename, json.dumps(config))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号