Skip to content
Merged
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
18 changes: 15 additions & 3 deletions labtech/lab.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import concurrent.futures.process
import math
from collections import Counter, defaultdict
from enum import StrEnum
from pathlib import Path
from typing import TYPE_CHECKING

Expand Down Expand Up @@ -290,6 +291,13 @@ def process_completed_tasks():
task_monitor.close()


class DefaultStorage(StrEnum):
singleton = 'labtech_storage'


default_storage = DefaultStorage.singleton


class Lab:
"""Primary interface for configuring, running, and getting results of tasks.

Expand All @@ -304,7 +312,7 @@ class Lab:
"""

def __init__(self, *,
storage: str | Path | None | Storage,
storage: str | Path | None | Storage | DefaultStorage = default_storage,
continue_on_failure: bool = True,
max_workers: int | None = None,
notebook: bool | None = None,
Expand All @@ -316,7 +324,8 @@ def __init__(self, *,
[`Path`](https://docs.python.org/3/library/pathlib.html#pathlib.Path)
will be interpreted as the path to a local directory, `None`
will result in no caching. Any [Storage][labtech.types.Storage]
instance may also be specified.
instance may also be specified. Defaults to a "labtech_storage"
directory inside the current working directory.
continue_on_failure: If `True`, exceptions raised by tasks will be
logged, but execution of other tasks will continue.
max_workers: The maximum number of parallel worker processes for
Expand Down Expand Up @@ -374,7 +383,10 @@ def __init__(self, *,
`multiprocessing` start methods](https://docs.python.org/3/library/multiprocessing.html#contexts-and-start-methods).

"""
if isinstance(storage, str) or isinstance(storage, Path):
if isinstance(storage, DefaultStorage):
logger.warning(f'Caching labtech results in a local "{storage.value}" directory. Construct Lab() with a storage argument to suppress this warning.')
storage = LocalStorage(storage.value)
elif isinstance(storage, str) or isinstance(storage, Path):
storage = LocalStorage(storage)
elif storage is None:
storage = NullStorage()
Expand Down