Support downloading .whl files

This commit is contained in:
Ines Montani 2021-01-30 14:16:12 +11:00
parent 2332c4280b
commit 1841bcbb4f
3 changed files with 14 additions and 9 deletions

View File

@ -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"

View File

@ -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}')",

View File

@ -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)