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)
评论列表
文章目录