util.py 文件源码

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

项目:q2cli 作者: qiime2 项目源码 文件源码
def convert_primitive(ast):
    import click

    mapping = {
        'Int': int,
        'Str': str,
        'Float': float,
        'Color': str,
        'Bool': bool
    }
    # TODO: it would be a good idea to refactor this someday, but until then
    # just handle the few predicates we know about.
    predicate = ast['predicate']
    if predicate:
        if predicate['name'] == 'Choices' and ast['name'] == 'Str':
            return click.Choice(predicate['choices'])
        elif predicate['name'] == 'Range' and ast['name'] == 'Int':
            start = predicate['start']
            end = predicate['end']
            # click.IntRange is always inclusive
            if start is not None and not predicate['inclusive-start']:
                start += 1
            if end is not None and not predicate['inclusive-end']:
                end -= 1
            return click.IntRange(start, end)
        elif predicate['name'] == 'Range' and ast['name'] == 'Float':
            # click.FloatRange will be in click 7.0, so for now the
            # range handling will just fallback to qiime2.
            return mapping['Float']
        else:
            raise NotImplementedError()
    else:
        return mapping[ast['name']]
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号