yamlfile.py 文件源码

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

项目:pypyr-cli 作者: pypyr 项目源码 文件源码
def get_parsed_context(context_arg):
    """Parse input context string and returns context as dictionary."""
    assert context_arg, ("pipeline must be invoked with --context set. For "
                         "this yaml parser you're looking for something "
                         "like --context './myyamlfile.yaml'")
    logger.debug("starting")
    logger.debug(f"attempting to open file: {context_arg}")
    with open(context_arg) as yaml_file:
        payload = yaml.safe_load(yaml_file)

    logger.debug(f"yaml file parsed. Count: {len(payload)}")

    if not isinstance(payload, MutableMapping):
        raise TypeError("yaml input should describe a dictionary at the top "
                        "level. You should have something like "
                        "\n'key1: value1'\n key2: value2'\n"
                        "in the yaml top-level, not \n'- value1\n - value2'")

    logger.debug("done")
    return payload
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号