From 1841bcbb4f9303d06e93e97cf2d476778cc94642 Mon Sep 17 00:00:00 2001 From: Ines Montani Date: Sat, 30 Jan 2021 14:16:12 +1100 Subject: [PATCH] Support downloading .whl files --- spacy/cli/_util.py | 3 +++ spacy/cli/download.py | 14 ++++++++------ spacy/cli/package.py | 6 +++--- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/spacy/cli/_util.py b/spacy/cli/_util.py index 4012737cf..963394128 100644 --- a/spacy/cli/_util.py +++ b/spacy/cli/_util.py @@ -23,6 +23,9 @@ if TYPE_CHECKING: from pathy import Pathy # noqa: F401 +SDIST_SUFFIX = ".tar.gz" +WHEEL_SUFFIX = "-py3-none-any.whl" + PROJECT_FILE = "project.yml" PROJECT_LOCK = "project.lock" COMMAND = "python -m spacy" diff --git a/spacy/cli/download.py b/spacy/cli/download.py index 5fcac63c0..a7ebbfd77 100644 --- a/spacy/cli/download.py +++ b/spacy/cli/download.py @@ -4,7 +4,7 @@ import sys from wasabi import msg import typer -from ._util import app, Arg, Opt +from ._util import app, Arg, Opt, WHEEL_SUFFIX, SDIST_SUFFIX from .. import about from ..util import is_package, get_base_version, run_command from ..errors import OLD_MODEL_SHORTCUTS @@ -19,6 +19,7 @@ def download_cli( ctx: typer.Context, model: str = Arg(..., help="Name of pipeline package to download"), direct: bool = Opt(False, "--direct", "-d", "-D", help="Force direct download of name + version"), + wheel: bool = Opt(False, "--wheel", "-W", help="Download binary wheel") # fmt: on ): """ @@ -31,10 +32,10 @@ def download_cli( DOCS: https://nightly.spacy.io/api/cli#download AVAILABLE PACKAGES: https://spacy.io/models """ - download(model, direct, *ctx.args) + download(model, direct, wheel, *ctx.args) -def download(model: str, direct: bool = False, *pip_args) -> None: +def download(model: str, direct: bool = False, wheel: bool = False, *pip_args) -> None: if ( not (is_package("spacy") or is_package("spacy-nightly")) and "--no-deps" not in pip_args @@ -48,12 +49,13 @@ def download(model: str, direct: bool = False, *pip_args) -> None: "dependencies, you'll have to install them manually." ) pip_args = pip_args + ("--no-deps",) - dl_tpl = "{m}-{v}/{m}-{v}.tar.gz#egg={m}=={v}" + suffix = WHEEL_SUFFIX if wheel else SDIST_SUFFIX + dl_tpl = "{m}-{v}/{m}-{v}{s}#egg={m}=={v}" if direct: components = model.split("-") model_name = "".join(components[:-1]) version = components[-1] - download_model(dl_tpl.format(m=model_name, v=version), pip_args) + download_model(dl_tpl.format(m=model_name, v=version, s=suffix), pip_args) else: model_name = model if model in OLD_MODEL_SHORTCUTS: @@ -64,7 +66,7 @@ def download(model: str, direct: bool = False, *pip_args) -> None: model_name = OLD_MODEL_SHORTCUTS[model] compatibility = get_compatibility() version = get_version(model_name, compatibility) - download_model(dl_tpl.format(m=model_name, v=version), pip_args) + download_model(dl_tpl.format(m=model_name, v=version, s=suffix), pip_args) msg.good( "Download and installation successful", f"You can now load the package via spacy.load('{model_name}')", diff --git a/spacy/cli/package.py b/spacy/cli/package.py index a2b8e69ae..dff9328c8 100644 --- a/spacy/cli/package.py +++ b/spacy/cli/package.py @@ -5,7 +5,7 @@ from wasabi import Printer, get_raw_input import srsly import sys -from ._util import app, Arg, Opt, string_to_list +from ._util import app, Arg, Opt, string_to_list, WHEEL_SUFFIX, SDIST_SUFFIX from ..schemas import validate, ModelMetaSchema from .. import util from .. import about @@ -146,12 +146,12 @@ def package( if create_sdist: with util.working_dir(main_path): util.run_command([sys.executable, "setup.py", "sdist"], capture=False) - zip_file = main_path / "dist" / f"{model_name_v}.tar.gz" + zip_file = main_path / "dist" / f"{model_name_v}{SDIST_SUFFIX}" msg.good(f"Successfully created zipped Python package", zip_file) if create_wheel: with util.working_dir(main_path): util.run_command([sys.executable, "setup.py", "bdist_wheel"], capture=False) - wheel = main_path / "dist" / f"{model_name_v}-py3-none-any.whl" + wheel = main_path / "dist" / f"{model_name_v}{WHEEL_SUFFIX}" msg.good(f"Successfully created binary wheel", wheel)