From 69a851f991eacea644b57baa2610ff75673b8e2f Mon Sep 17 00:00:00 2001 From: ebonnafoux Date: Fri, 11 Jul 2025 10:10:48 +0200 Subject: [PATCH 1/2] add download url --- .pre-commit-config.yaml | 2 +- spacy/cli/download.py | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e2c5e98fd..a13e801d4 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,7 +3,7 @@ repos: rev: 22.3.0 hooks: - id: black - language_version: python3.7 + language_version: python3.10 additional_dependencies: ['click==8.0.4'] - repo: https://github.com/pycqa/flake8 rev: 5.0.4 diff --git a/spacy/cli/download.py b/spacy/cli/download.py index 4261fb830..8ab6a2997 100644 --- a/spacy/cli/download.py +++ b/spacy/cli/download.py @@ -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 ): """ @@ -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 ( @@ -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}')", @@ -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__ + "/" From d54b23e50d0cc80a85cb91d67112b27236ac2224 Mon Sep 17 00:00:00 2001 From: "Etienne.bfx" Date: Fri, 11 Jul 2025 10:13:38 +0200 Subject: [PATCH 2/2] Update .pre-commit-config.yaml --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a13e801d4..e2c5e98fd 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,7 +3,7 @@ repos: rev: 22.3.0 hooks: - id: black - language_version: python3.10 + language_version: python3.7 additional_dependencies: ['click==8.0.4'] - repo: https://github.com/pycqa/flake8 rev: 5.0.4