Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/datasets/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,6 @@
LICENSE_FILENAME = "LICENSE"
METRIC_INFO_FILENAME = "metric_info.json"

MODULE_NAME_FOR_DYNAMIC_MODULES = "datasets_modules"

MAX_DATASET_CONFIG_ID_READABLE_LENGTH = 255
12 changes: 4 additions & 8 deletions src/datasets/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@

logger = get_logger(__name__)

MODULE_NAME_FOR_DYNAMIC_MODULES = "datasets_modules"


def init_dynamic_modules(name: str, hf_modules_cache: Optional[Union[Path, str]] = None):
def init_dynamic_modules(
name: str = config.MODULE_NAME_FOR_DYNAMIC_MODULES, hf_modules_cache: Optional[Union[Path, str]] = None
):
"""
Create a module with name `name` in which you can add dynamic modules
such as metrics or datasets. The module can be imported using its name.
Expand Down Expand Up @@ -285,11 +285,7 @@ def prepare_module(
return module_path, hash

# otherwise the module is added to the dynamic modules
dynamic_modules_path = (
dynamic_modules_path
if dynamic_modules_path is not None
else init_dynamic_modules(MODULE_NAME_FOR_DYNAMIC_MODULES, hf_modules_cache=config.HF_MODULES_CACHE)
)
dynamic_modules_path = dynamic_modules_path if dynamic_modules_path else init_dynamic_modules()
module_name_for_dynamic_modules = os.path.basename(dynamic_modules_path)
datasets_modules_path = os.path.join(dynamic_modules_path, "datasets")
datasets_modules_name = module_name_for_dynamic_modules + ".datasets"
Expand Down
4 changes: 3 additions & 1 deletion tests/test_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ def inject_fixtures(self, caplog):

def setUp(self):
self.hf_modules_cache = tempfile.mkdtemp()
self.dynamic_modules_path = datasets.load.init_dynamic_modules("test_datasets_modules", self.hf_modules_cache)
self.dynamic_modules_path = datasets.load.init_dynamic_modules(
name="test_datasets_modules", hf_modules_cache=self.hf_modules_cache
)

def tearDown(self):
shutil.rmtree(self.hf_modules_cache)
Expand Down