cli.py 文件源码

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

项目:reqwire 作者: darvid 项目源码 文件源码
def main_build(ctx,                  # type: click.Context
               options,              # type: Dict[str, Any]
               all,                  # type: bool
               tag,                  # type: Iterable[str]
               pip_compile_options,  # type: Iterable[str]
               ):
    # type: (...) -> None
    """Build requirements with pip-compile."""
    if not options['directory'].exists():
        console.error('run `{} init\' first', ctx.find_root().info_name)
        ctx.abort()
    if not all and not tag:
        console.error('either --all or --tag must be provided.')
        ctx.abort()
    src_dir = options['directory'] / options['source_dir']
    dest_dir = options['directory'] / options['build_dir']
    if not dest_dir.exists():
        dest_dir.mkdir()
    default_args = ['-r']
    if not tag:
        pattern = '*{}'.format(options['extension'])
        tag = (path.stem for path in src_dir.glob(pattern))
    for tag_name in tag:
        src = src_dir / ''.join((tag_name, options['extension']))
        dest = dest_dir / '{}.txt'.format(tag_name)
        console.info('building {}', click.format_filename(str(dest)))
        args = default_args[:]
        args += [str(src)]
        args += list(pip_compile_options)
        with atomicwrites.AtomicWriter(str(dest), 'w', True).open() as f:
            f.write(reqwire.scaffold.MODELINES_HEADER)
            with tempfile.NamedTemporaryFile() as temp_file:
                args += ['-o', temp_file.name]
                sh.pip_compile(*args, _out=f, _tty_out=False)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号