Skip to content

Commit

Permalink
fix: adapt to changes in interface
Browse files Browse the repository at this point in the history
  • Loading branch information
johanneskoester committed Nov 15, 2023
1 parent 3a06bb0 commit 2ab1c31
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ homepage = "https://github.com/snakemake/snakemake-storage-plugin-s3"
[tool.poetry.dependencies]
python = "^3.11"
snakemake-interface-common = "^1.12.0"
snakemake-interface-storage-plugins = "^1.3.1"
snakemake-interface-storage-plugins = "^2.0.0"
boto3 = "^1.28.55"
botocore = "^1.31.55"

Expand Down
10 changes: 7 additions & 3 deletions snakemake_storage_plugin_s3/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,15 @@ async def inventory(self, cache: IOCacheStorageInterface):
# If this is implemented in a storage object, results have to be stored in
# the given IOCache object.

if self.get_inventory_parent() in cache.exists_in_storage:
# bucket has been inventorized before, stop here
return

# check if bucket exists
if not self.bucket_exists():
cache.exists_in_storage[self.cache_key()] = False
else:
cache.exists_in_storage[self.get_inventory_parent()] = True
for obj in self.s3bucket().objects.all():
key = self.cache_key(self._local_suffix_from_key(obj.key))
cache.mtime[key] = obj.last_modified.timestamp()
Expand All @@ -247,12 +252,11 @@ async def inventory(self, cache: IOCacheStorageInterface):

def get_inventory_parent(self) -> Optional[str]:
"""Return the parent directory of this object."""
# TODO potentially implement later for speeding up existence calculation
return None
return self.cache_key(self.bucket)

def local_suffix(self) -> str:
return self._local_suffix

def _local_suffix_from_key(self, key: str) -> str:
return f"{self.bucket}/{key}"

Expand Down
4 changes: 2 additions & 2 deletions tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ class TestStorageNoSettings(TestStorageBase):
__test__ = True
retrieve_only = False

def get_query(self) -> str:
def get_query(self, tmp_path) -> str:
return "s3://snakemake-test-bucket/test-file.txt"

def get_query_not_existing(self) -> str:
def get_query_not_existing(self, tmp_path) -> str:
bucket = uuid.uuid4().hex
key = uuid.uuid4().hex
return f"s3://{bucket}/{key}"
Expand Down

0 comments on commit 2ab1c31

Please sign in to comment.