cli.py 文件源码

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

项目:MonkeyType 作者: Instagram 项目源码 文件源码
def apply_stub_handler(args: argparse.Namespace, stdout: IO, stderr: IO) -> None:
    stub = get_stub(args, stdout, stderr)
    if stub is None:
        print(f'No traces found', file=stderr)
        return
    module = args.module_path[0]
    mod = importlib.import_module(module)
    src_path = inspect.getfile(mod)
    src_dir = os.path.dirname(src_path)
    pyi_name = module.split('.')[-1] + '.pyi'
    with tempfile.TemporaryDirectory(prefix='monkeytype') as pyi_dir:
        pyi_path = os.path.join(pyi_dir, pyi_name)
        with open(pyi_path, 'w+') as f:
            f.write(stub.render())
        cmd = ' '.join([
            'retype',
            '--pyi-dir ' + pyi_dir,
            '--target-dir ' + src_dir,
            src_path
        ])
        subprocess.run(cmd, shell=True, check=True, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号