18 from typing
import Iterator, Optional, Union
19 from pathlib
import Path
20 from contextlib
import contextmanager
30 Used for handling everything related to local storage
31 when working with Coretex
36 folder where samples are stored
38 folder where models are stored
40 folder where temp files and folders are stored,
41 this is deleted when the run has finished executing
43 folder where datasets are stored (samples are symlinked for datasets)
45 folder where cache module stores items
47 folder where node and run logs are stored
49 folder where node stores python environments
52 def __init__(self, storagePath: Union[Path, str]):
53 if isinstance(storagePath, str):
54 storagePath = Path(storagePath)
56 self.
_root_root = storagePath.expanduser()
73 def _createFolder(self, name: str) -> Path:
74 path = self.
_root_root / name
77 path.mkdir(parents =
True, exist_ok =
True)
83 Creates temp folder which is deleted once
84 the run has finished executing
93 Path -> path to the created folder
97 FileExistsError -> if the temp folder already exists
101 >>> from coretex import folder_manager
103 >>> dummyFolderPath = folder_manager.createTempFolder("dummyTempFolder")
104 >>> print(dummyFolderPath)
105 "/Users/X/.coretex/temp/dummyTempFolder"
108 tempFolderPath = self.
temptemp / name
110 if tempFolderPath.exists():
111 raise FileExistsError
113 tempFolderPath.mkdir()
114 return tempFolderPath
118 Retrieves the path to where the artifacts are stored
119 for the specified TaskRuns
128 Path -> path to the TaskRun artifacts local storage
132 >>> from coretex.folder_management import FolderManager
134 >>> artifactsFolderPath = FolderManager.instance().getArtifactsFolder(1023)
135 >>> print(artifactsFolderPath)
136 Path("/Users/bogdanbm/.coretex/artifacts/1023")
141 def clearDirectory(self, path: Path) ->
None:
147 Deletes all temp files and folders (including artifacts)
153 def getRunLogsDir(self, taskRunId: int) -> Path:
155 taskRunLogsDir.mkdir(parents =
True, exist_ok =
True)
157 return taskRunLogsDir
160 def tempFile(self, name: Optional[str] =
None) -> Iterator[Path]:
162 Returns a path to temporary file and deletes
163 it if it exists once the context is exited.
168 Name of the file. If not specified a random uuid4
169 will be generated and used as the name
173 Iterator[Path] -> path to the file
177 name = str(uuid.uuid4())
179 path = self.
temptemp / name
181 raise FileExistsError(path)
185 path.unlink(missing_ok =
True)
188 folder_manager =
FolderManager(os.environ[
"CTX_STORAGE_PATH"])
Path getArtifactsFolder(self, int taskRunId)
Path _createFolder(self, str name)
None clearDirectory(self, Path path)
Path createTempFolder(self, str name)
Iterator[Path] tempFile(self, Optional[str] name=None)
None clearTempFiles(self)