From 10b84e1e279c3161df9fd06fc82915a41c533709 Mon Sep 17 00:00:00 2001 From: Ines Montani Date: Mon, 27 Jul 2020 16:52:23 +0200 Subject: [PATCH] Add flag to toggle sdist creation on package [ci skip] --- spacy/cli/package.py | 14 ++++++++------ website/docs/api/cli.md | 8 +++++--- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/spacy/cli/package.py b/spacy/cli/package.py index 82b9337a4..a1162f3e1 100644 --- a/spacy/cli/package.py +++ b/spacy/cli/package.py @@ -19,6 +19,7 @@ def package_cli( meta_path: Optional[Path] = Opt(None, "--meta-path", "--meta", "-m", help="Path to meta.json", exists=True, dir_okay=False), create_meta: bool = Opt(False, "--create-meta", "-c", "-C", help="Create meta.json, even if one exists"), version: Optional[str] = Opt(None, "--version", "-v", help="Package version to override meta"), + no_sdist: bool = Opt(False, "--no-sdist", "-NS", help="Don't build .tar.gz sdist, can be set if you want to run this step manually"), force: bool = Opt(False, "--force", "-f", "-F", help="Force overwriting existing model in output directory"), # fmt: on ): @@ -37,6 +38,7 @@ def package_cli( meta_path=meta_path, version=version, create_meta=create_meta, + create_sdist=not no_sdist, force=force, silent=False, ) @@ -48,6 +50,7 @@ def package( meta_path: Optional[Path] = None, version: Optional[str] = None, create_meta: bool = False, + create_sdist: bool = True, force: bool = False, silent: bool = True, ) -> None: @@ -61,7 +64,6 @@ def package( msg.fail("Output directory not found", output_path, exits=1) if meta_path and not meta_path.exists(): msg.fail("Can't find model meta.json", meta_path, exits=1) - meta_path = meta_path or input_dir / "meta.json" if not meta_path.exists() or not meta_path.is_file(): msg.fail("Can't load model meta.json", meta_path, exits=1) @@ -80,7 +82,6 @@ def package( model_name_v = model_name + "-" + meta["version"] main_path = output_dir / model_name_v package_path = main_path / model_name - if package_path.exists(): if force: shutil.rmtree(str(package_path)) @@ -98,10 +99,11 @@ def package( create_file(main_path / "MANIFEST.in", TEMPLATE_MANIFEST) create_file(package_path / "__init__.py", TEMPLATE_INIT) msg.good(f"Successfully created package '{model_name_v}'", main_path) - with util.working_dir(main_path): - util.run_command([sys.executable, "setup.py", "sdist"]) - zip_file = main_path / "dist" / f"{model_name_v}.tar.gz" - msg.good(f"Successfully created zipped Python package", zip_file) + if create_sdist: + with util.working_dir(main_path): + util.run_command([sys.executable, "setup.py", "sdist"]) + zip_file = main_path / "dist" / f"{model_name_v}.tar.gz" + msg.good(f"Successfully created zipped Python package", zip_file) def create_file(file_path: Path, contents: str) -> None: diff --git a/website/docs/api/cli.md b/website/docs/api/cli.md index 5374ff216..4690029aa 100644 --- a/website/docs/api/cli.md +++ b/website/docs/api/cli.md @@ -535,13 +535,14 @@ then create a `.tar.gz` archive file that you can distribute and install with The `spacy package` command now also builds the `.tar.gz` archive automatically, -so you don't have to run `python setup.py sdist` separately anymore. +so you don't have to run `python setup.py sdist` separately anymore. To disable +this, you can set the `--no-sdist` flag. ```bash $ python -m spacy package [input_dir] [output_dir] [--meta-path] [--create-meta] -[--version] [--force] +[--no-sdist] [--version] [--force] ``` > #### Example @@ -557,7 +558,8 @@ $ python -m spacy package [input_dir] [output_dir] [--meta-path] [--create-meta] | `input_dir` | positional | Path to directory containing model data. | | `output_dir` | positional | Directory to create package folder in. | | `--meta-path`, `-m` 2 | option | Path to `meta.json` file (optional). | -| `--create-meta`, `-c` 2 | flag | Create a `meta.json` file on the command line, even if one already exists in the directory. If an existing file is found, its entries will be shown as the defaults in the command line prompt. | +| `--create-meta`, `-C` 2 | flag | Create a `meta.json` file on the command line, even if one already exists in the directory. If an existing file is found, its entries will be shown as the defaults in the command line prompt. | +| `--no-sdist`, `-NS`, | flag | Don't build the `.tar.gz` sdist automatically. Can be set if you want to run this step manually. | | `--version`, `-v` 3 | option | Package version to override in meta. Useful when training new versions, as it doesn't require editing the meta template. | | `--force`, `-f` | flag | Force overwriting of existing folder in output directory. | | `--help`, `-h` | flag | Show help message and available arguments. |