From 5230ed5b98e3f1e9c83b1205c87db962c5844804 Mon Sep 17 00:00:00 2001 From: ines Date: Tue, 21 Mar 2017 02:06:53 +0100 Subject: [PATCH] Move directory check and overwriting/creating dirs to own function --- spacy/cli/package.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/spacy/cli/package.py b/spacy/cli/package.py index bf424e075..59b45ab5f 100644 --- a/spacy/cli/package.py +++ b/spacy/cli/package.py @@ -20,7 +20,7 @@ def package(input_dir, output_dir, force): main_path = output_path / model_name_v package_path = main_path / model_name - Path.mkdir(package_path, parents=True) + create_dirs(package_path, force) shutil.copytree(input_path, package_path / model_name_v) create_file(main_path / 'meta.json', json.dumps(meta, indent=2)) create_file(main_path / 'setup.py', TEMPLATE_SETUP.strip()) @@ -40,6 +40,17 @@ def check_dirs(input_path, output_path): util.sys_exit(output_path.as_posix(), title="Output directory not found") +def create_dirs(package_path, force): + if package_path.exists(): + if force: + shutil.rmtree(package_path) + else: + util.sys_exit(package_path.as_posix(), + "Please delete the directory and try again.", + title="Package directory already exists") + Path.mkdir(package_path, parents=True) + + def create_file(file_path, contents): file_path.touch() file_path.write_text(contents, encoding='utf-8')