Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions spacy/cli/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def download_cli(
model: str = Arg(..., help="Name of pipeline package to download"),
direct: bool = Opt(False, "--direct", "-d", "-D", help="Force direct download of name + version"),
sdist: bool = Opt(False, "--sdist", "-S", help="Download sdist (.tar.gz) archive instead of pre-built binary wheel"),
url: str = Opt(None, "--url", "-U", help="Download from given url")
# fmt: on
):
"""
Expand All @@ -41,13 +42,14 @@ def download_cli(
DOCS: https://spacy.io/api/cli#download
AVAILABLE PACKAGES: https://spacy.io/models
"""
download(model, direct, sdist, *ctx.args)
download(model, direct, sdist, custom_url=url, *ctx.args)


def download(
model: str,
direct: bool = False,
sdist: bool = False,
custom_url: Optional[str] = None,
*pip_args,
) -> None:
if (
Expand Down Expand Up @@ -87,7 +89,7 @@ def download(

filename = get_model_filename(model_name, version, sdist)

download_model(filename, pip_args)
download_model(filename, pip_args, custom_url)
msg.good(
"Download and installation successful",
f"You can now load the package via spacy.load('{model_name}')",
Expand Down Expand Up @@ -159,12 +161,14 @@ def get_latest_version(model: str) -> str:


def download_model(
filename: str, user_pip_args: Optional[Sequence[str]] = None
filename: str,
user_pip_args: Optional[Sequence[str]] = None,
custom_url: Optional[str] = None,
) -> None:
# Construct the download URL carefully. We need to make sure we don't
# allow relative paths or other shenanigans to trick us into download
# from outside our own repo.
base_url = about.__download_url__
base_url = custom_url if custom_url else about.__download_url__
# urljoin requires that the path ends with /, or the last path part will be dropped
if not base_url.endswith("/"):
base_url = about.__download_url__ + "/"
Expand Down
3 changes: 2 additions & 1 deletion website/docs/api/cli.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pipeline name to be specified with its version (e.g. `en_core_web_sm-3.0.0`).
> project.

```bash
$ python -m spacy download [model] [--direct] [--sdist] [pip_args]
$ python -m spacy download [model] [--direct] [--sdist] [pip_args] [--url url]
```

| Name | Description |
Expand All @@ -58,6 +58,7 @@ $ python -m spacy download [model] [--direct] [--sdist] [pip_args]
| `--help`, `-h` | Show help message and available arguments. ~~bool (flag)~~ |
| pip args | Additional installation options to be passed to `pip install` when installing the pipeline package. For example, `--user` to install to the user home directory or `--no-deps` to not install package dependencies. ~~Any (option/flag)~~ |
| **CREATES** | The installed pipeline package in your `site-packages` directory. |
| `--url`, `-U` | Download from a mirror repository at the given url |

## info {id="info",tag="command"}

Expand Down