diff --git a/spacy/cli/project/remote_storage.py b/spacy/cli/project/remote_storage.py index 694bc450f..44fb0c189 100644 --- a/spacy/cli/project/remote_storage.py +++ b/spacy/cli/project/remote_storage.py @@ -119,17 +119,19 @@ class RemoteStorage: recent matching file is preferred. """ name = self.encode_name(str(path)) + urls = [] if command_hash is not None and content_hash is not None: - url = self.make_url(path, command_hash, content_hash) + url = self.url / name / command_hash / content_hash urls = [url] if url.exists() else [] elif command_hash is not None: - urls = list((self.url / name / command_hash).iterdir()) + if (self.url / name / command_hash).exists(): + urls = list((self.url / name / command_hash).iterdir()) else: - urls = [] - for sub_dir in (self.url / name).iterdir(): - urls.extend(sub_dir.iterdir()) - if content_hash is not None: - urls = [url for url in urls if url.parts[-1] == content_hash] + if (self.url / name).exists(): + for sub_dir in (self.url / name).iterdir(): + urls.extend(sub_dir.iterdir()) + if content_hash is not None: + urls = [url for url in urls if url.parts[-1] == content_hash] if len(urls) >= 2: try: urls.sort(key=lambda x: x.stat().st_mtime) # type: ignore diff --git a/spacy/tests/test_cli.py b/spacy/tests/test_cli.py index 4a49fa996..23fca59d2 100644 --- a/spacy/tests/test_cli.py +++ b/spacy/tests/test_cli.py @@ -906,6 +906,15 @@ def test_local_remote_storage(): assert file_.read() == content +def test_local_remote_storage_pull_missing(): + # pulling from a non-existent remote pulls nothing gracefully + with make_tempdir() as d: + filename = "a.txt" + remote = RemoteStorage(d / "root", str(d / "remote")) + assert remote.pull(filename, command_hash="aaaa") is None + assert remote.pull(filename) is None + + @pytest.mark.parametrize( "reqs,output", [