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