diff --git a/spacy/cli/_util.py b/spacy/cli/_util.py index b527ac2a0..77cf36852 100644 --- a/spacy/cli/_util.py +++ b/spacy/cli/_util.py @@ -260,10 +260,22 @@ def upload_file(src: Path, dest: Union[str, "Pathy"]) -> None: src (Path): The source path. url (str): The destination URL to upload to. """ - dest = ensure_pathy(dest) - with dest.open(mode="wb") as output_file: - with src.open(mode="rb") as input_file: - output_file.write(input_file.read()) + import smart_open + # This logic is pretty hacky. We'd like pathy to do this probably? + if ":/" not in str(dest): + # Local path + with Path(dest).open(mode="wb") as output_file: + with src.open(mode="rb") as input_file: + output_file.write(input_file.read()) + elif str(dest).startswith("http") or str(dest).startswith("https"): + with smart_open.open(str(dest), mode="wb") as output_file: + with src.open(mode="rb") as input_file: + output_file.write(input_file.read()) + else: + dest = ensure_pathy(dest) + with dest.open(mode="wb") as output_file: + with src.open(mode="rb") as input_file: + output_file.write(input_file.read()) def download_file(src: Union[str, "Pathy"], dest: Path, *, force: bool = False) -> None: @@ -274,12 +286,23 @@ def download_file(src: Union[str, "Pathy"], dest: Path, *, force: bool = False) force (bool): Whether to force download even if file exists. If False, the download will be skipped. """ + import smart_open + # This logic is pretty hacky. We'd like pathy to do this probably? if dest.exists() and not force: return None - src = ensure_pathy(src) - with src.open(mode="rb") as input_file: - with dest.open(mode="wb") as output_file: - output_file.write(input_file.read()) + if src.startswith("http"): + with smart_open.open(src, mode="rb") as input_file: + with dest.open(mode="wb") as output_file: + output_file.write(input_file.read()) + elif ":/" not in src: + with open(src, mode="rb") as input_file: + with dest.open(mode="wb") as output_file: + output_file.write(input_file.read()) + else: + src = ensure_pathy(src) + with src.open(mode="rb") as input_file: + with dest.open(mode="wb") as output_file: + output_file.write(input_file.read()) def ensure_pathy(path):