Skip to content

Commit e1fd75e

Browse files
feat: raise FileOrDirectoryNotFoundError if mtime or size queries fail and object does not exist remotely (#80)
* feat: raise ObjectNotFoundError if mtime or size queries fail and object does not exist remotely * latest pixi * fix * missing file * rename * fix * add method for checking with given path * resolve
1 parent 2c089af commit e1fd75e

File tree

4 files changed

+27
-6
lines changed

4 files changed

+27
-6
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@ jobs:
2121
uses: actions/checkout@v4
2222

2323
- name: Install Pixi
24-
uses: prefix-dev/setup-pixi@v0.8.3
24+
uses: prefix-dev/setup-pixi@v0
2525
with:
2626
environments: dev
27-
pixi-version: v0.42.1
2827

2928
- name: Ruff Format
3029
if: always()
@@ -49,10 +48,9 @@ jobs:
4948
- uses: actions/checkout@v4
5049

5150
- name: Install Pixi
52-
uses: prefix-dev/setup-pixi@v0.8.3
51+
uses: prefix-dev/setup-pixi@v0
5352
with:
5453
environments: dev
55-
pixi-version: v0.42.1
5654

5755
- name: Run tests
5856
run: pixi run --environment dev test --show-capture=all -s -vv

pyproject.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,10 @@ homepage = "https://github.com/snakemake/snakemake-interface-storage-plugins"
2222
requires = ["poetry-core"]
2323
build-backend = "poetry.core.masonry.api"
2424

25-
[tool.pixi.project]
25+
[tool.pixi.workspace]
2626
channels = ["conda-forge"]
2727
platforms = ["osx-arm64", "linux-64"]
2828

29-
3029
[tool.pixi.tasks]
3130

3231
[tool.pixi.dependencies]
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from pathlib import Path
2+
from typing import Optional
3+
4+
5+
class FileOrDirectoryNotFoundError(Exception):
6+
def __init__(self, local_path: Path, query: Optional[str]):
7+
self.query: Optional[str] = query
8+
self.local_path: Path = local_path
9+
msg = (
10+
f"Storage object {query} not found in storage (local path: {local_path!s})."
11+
if query
12+
else f"File or directory not found: {local_path!s}"
13+
)
14+
super().__init__(msg)
15+
16+
def is_for_path(self, path: Path) -> bool:
17+
return self.local_path.resolve() == path.resolve()

snakemake_interface_storage_plugins/storage_object.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from snakemake_interface_common.logging import get_logger
2020
from snakemake_interface_storage_plugins.common import Operation, get_disk_free
2121

22+
from snakemake_interface_storage_plugins.exceptions import FileOrDirectoryNotFoundError
2223
from snakemake_interface_storage_plugins.io import IOCacheStorageInterface
2324
from snakemake_interface_storage_plugins.storage_provider import StorageProviderBase
2425

@@ -173,18 +174,24 @@ def retrieve_object(self):
173174
"""
174175
...
175176

177+
def _raise_object_not_found_if_not_exists(self):
178+
if not self.exists():
179+
raise FileOrDirectoryNotFoundError(self.print_query, self.local_path())
180+
176181
async def managed_size(self) -> int:
177182
try:
178183
async with self._rate_limiter(Operation.SIZE):
179184
return self.size()
180185
except Exception as e:
186+
self._raise_object_not_found_if_not_exists()
181187
raise WorkflowError(f"Failed to get size of {self.print_query}", e)
182188

183189
async def managed_mtime(self) -> float:
184190
try:
185191
async with self._rate_limiter(Operation.MTIME):
186192
return self.mtime()
187193
except Exception as e:
194+
self._raise_object_not_found_if_not_exists()
188195
raise WorkflowError(f"Failed to get mtime of {self.print_query}", e)
189196

190197
async def managed_exists(self) -> bool:

0 commit comments

Comments
 (0)