Add more options to read in meta data in package command

Add meta option to supply path to meta.json. If no meta path is set,
check if meta.json exists in input directory and use it. Otherwise,
prompt for details on the command line.
This commit is contained in:
ines 2017-04-16 13:06:02 +02:00
parent 13c8a42d2b
commit a7574b7572
2 changed files with 16 additions and 6 deletions

View File

@ -63,15 +63,16 @@ class CLI(object):
@plac.annotations(
input_dir=("directory with model data", "positional", None, str),
output_dir=("output parent directory", "positional", None, str),
meta=("path to meta.json", "option", "m", str),
force=("force overwriting of existing folder in output directory", "flag", "f", bool)
)
def package(self, input_dir, output_dir, force=False):
def package(self, input_dir, output_dir, meta=None, force=False):
"""
Generate Python package for model data, including meta and required
installation files. A new directory will be created in the specified
output directory, and model data will be copied over.
"""
cli_package(input_dir, output_dir, force)
cli_package(input_dir, output_dir, meta, force)
@plac.annotations(

View File

@ -9,15 +9,22 @@ from ..compat import unicode_, json_dumps
from .. import util
def package(input_dir, output_dir, force):
def package(input_dir, output_dir, meta_path, force):
input_path = Path(input_dir)
output_path = Path(output_dir)
check_dirs(input_path, output_path)
meta_path = util.ensure_path(meta_path)
check_dirs(input_path, output_path, meta_path)
template_setup = get_template('setup.py')
template_manifest = get_template('MANIFEST.in')
template_init = get_template('en_model_name/__init__.py')
meta = generate_meta()
meta_path = meta_path or input_path / 'meta.json'
if meta_path.is_file():
util.print_msg(unicode_(meta_path), title="Reading meta.json from file")
meta = util.read_json(meta_path)
else:
meta = generate_meta()
model_name = meta['lang'] + '_' + meta['name']
model_name_v = model_name + '-' + meta['version']
@ -37,11 +44,13 @@ def package(input_dir, output_dir, force):
title="Successfully created package {p}".format(p=model_name_v))
def check_dirs(input_path, output_path):
def check_dirs(input_path, output_path, meta_path):
if not input_path.exists():
util.sys_exit(unicode_(input_path.as_poisx), title="Model directory not found")
if not output_path.exists():
util.sys_exit(unicode_(output_path), title="Output directory not found")
if meta_path and not meta_path.exists():
util.sys_exit(unicode_(meta_path), title="meta.json not found")
def create_dirs(package_path, force):