Skip to content

Commit 68679d6

Browse files
etiennebonnafouxebonnafoux
andauthored
Add custom download URL (#13848)
* add download url * Update .pre-commit-config.yaml * Update cli.mdx --------- Co-authored-by: ebonnafoux <[email protected]>
1 parent 94d6be8 commit 68679d6

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

spacy/cli/download.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def download_cli(
2929
model: str = Arg(..., help="Name of pipeline package to download"),
3030
direct: bool = Opt(False, "--direct", "-d", "-D", help="Force direct download of name + version"),
3131
sdist: bool = Opt(False, "--sdist", "-S", help="Download sdist (.tar.gz) archive instead of pre-built binary wheel"),
32+
url: str = Opt(None, "--url", "-U", help="Download from given url")
3233
# fmt: on
3334
):
3435
"""
@@ -41,13 +42,14 @@ def download_cli(
4142
DOCS: https://spacy.io/api/cli#download
4243
AVAILABLE PACKAGES: https://spacy.io/models
4344
"""
44-
download(model, direct, sdist, *ctx.args)
45+
download(model, direct, sdist, custom_url=url, *ctx.args)
4546

4647

4748
def download(
4849
model: str,
4950
direct: bool = False,
5051
sdist: bool = False,
52+
custom_url: Optional[str] = None,
5153
*pip_args,
5254
) -> None:
5355
if (
@@ -87,7 +89,7 @@ def download(
8789

8890
filename = get_model_filename(model_name, version, sdist)
8991

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

160162

161163
def download_model(
162-
filename: str, user_pip_args: Optional[Sequence[str]] = None
164+
filename: str,
165+
user_pip_args: Optional[Sequence[str]] = None,
166+
custom_url: Optional[str] = None,
163167
) -> None:
164168
# Construct the download URL carefully. We need to make sure we don't
165169
# allow relative paths or other shenanigans to trick us into download
166170
# from outside our own repo.
167-
base_url = about.__download_url__
171+
base_url = custom_url if custom_url else about.__download_url__
168172
# urljoin requires that the path ends with /, or the last path part will be dropped
169173
if not base_url.endswith("/"):
170174
base_url = about.__download_url__ + "/"

website/docs/api/cli.mdx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pipeline name to be specified with its version (e.g. `en_core_web_sm-3.0.0`).
4747
> project.
4848
4949
```bash
50-
$ python -m spacy download [model] [--direct] [--sdist] [pip_args]
50+
$ python -m spacy download [model] [--direct] [--sdist] [pip_args] [--url url]
5151
```
5252

5353
| Name | Description |
@@ -58,6 +58,7 @@ $ python -m spacy download [model] [--direct] [--sdist] [pip_args]
5858
| `--help`, `-h` | Show help message and available arguments. ~~bool (flag)~~ |
5959
| 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)~~ |
6060
| **CREATES** | The installed pipeline package in your `site-packages` directory. |
61+
| `--url`, `-U` | Download from a mirror repository at the given url |
6162

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

0 commit comments

Comments
 (0)