Skip to content

Commit

Permalink
ENH: Use temporary directory for Dataset path by default
Browse files Browse the repository at this point in the history
BREAKING CHANGE: To keep the previous behaviour, pass `path=os.getcwd()` to `Dataset` at instantiation.

skipci
  • Loading branch information
cortadocodes committed Jul 8, 2024
1 parent 2829c63 commit 55a8349
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
3 changes: 2 additions & 1 deletion octue/resources/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import json
import logging
import os
import tempfile
from collections.abc import Iterable

import coolname
Expand Down Expand Up @@ -71,7 +72,7 @@ def __init__(
labels=None,
):
super().__init__(name=name, id=id, tags=tags, labels=labels)
self.path = path or os.getcwd()
self.path = path or tempfile.TemporaryDirectory().name
self.files = FilterSet()
self._recursive = recursive
self._ignore_stored_metadata = ignore_stored_metadata
Expand Down
11 changes: 9 additions & 2 deletions tests/resources/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,15 @@ def test_hashes_for_the_same_dataset_are_the_same(self):

def test_metadata_hash_is_same_for_different_datasets_with_the_same_metadata(self):
"""Test that the metadata hash is the same for datasets with different files but the same metadata."""
first_dataset = Dataset(labels={"a", "b", "c"})
second_dataset = Dataset(files={Datafile(path="blah", ignore_stored_metadata=True)}, labels={"a", "b", "c"})
with tempfile.TemporaryDirectory() as temporary_directory:
first_dataset = Dataset(path=temporary_directory, labels={"a", "b", "c"})

second_dataset = Dataset(
path=temporary_directory,
files={Datafile(path="blah", ignore_stored_metadata=True)},
labels={"a", "b", "c"},
)

self.assertEqual(first_dataset.metadata_hash_value, second_dataset.metadata_hash_value)

def test_metadata_hash_is_different_for_same_dataset_but_different_metadata(self):
Expand Down

0 comments on commit 55a8349

Please sign in to comment.