18 from typing
import TypeVar, Generic, Type, Generator, Optional, Union, Any
19 from pathlib
import Path
24 from .dataset
import Dataset
25 from ..sample
import LocalSample, AnyLocalSample
28 SampleType = TypeVar(
"SampleType", bound =
"LocalSample")
29 SampleGenerator = Generator[SampleType,
None,
None]
32 def _generateZippedSamples(path: Path, sampleClass: Type[SampleType]) -> Generator[SampleType,
None,
None]:
33 for samplePath
in path.glob(
"*"):
34 if not zipfile.is_zipfile(samplePath):
37 yield sampleClass(samplePath)
43 Represents the generic Local Dataset class for all
44 LocalDataset classes \n
45 Used for working with local datasets
51 sampleClass : Type[SampleType]
53 generator : Optional[SampleGenerator]
57 def __init__(self, path: Path, sampleClass: Type[SampleType], generator: Optional[SampleGenerator] =
None) ->
None:
59 generator = _generateZippedSamples(path, sampleClass)
65 self.
samplessamples = list(generator)
68 def default(path: Path) ->
'LocalDataset':
70 Creates Local Dataset object
79 LocalDataset -> Local Dataset object
85 def custom(path: Path, generator: SampleGenerator) ->
'LocalDataset':
87 Creates Custom Local Dataset object
93 generator : SampleGenerator
98 LocalDataset -> Local Dataset object
108 Path -> Local Dataset path
113 def download(self, decrypt: bool =
True, ignoreCache: bool =
False) ->
None:
114 logging.getLogger(
"coretexpylib").warning(
">> [Coretex] Local dataset cannot be downloaded")
116 def add(self, samplePath: Union[Path, str], sampleName: Optional[str] =
None, **metadata: Any) -> SampleType:
117 if isinstance(samplePath, str):
118 samplePath = Path(samplePath)
121 self.
samplessamples.append(sample)
'LocalDataset' default(Path path)
'LocalDataset' custom(Path path, SampleGenerator generator)