Coretex
coretex._folder_manager.FolderManager Class Reference

Public Member Functions

Path createTempFolder (self, str name)
 
Path getArtifactsFolder (self, int taskRunId)
 
None clearTempFiles (self)
 
Iterator[Path] tempFile (self, Optional[str] name=None)
 

Detailed Description

    Used for handling everything related to local storage
    when working with Coretex

    Contains
    --------
    samplesFolder : Path
        folder where samples are stored
    modelsFolder : Path
        folder where models are stored
    temp : Path
        folder where temp files and folders are stored,
        this is deleted when the run has finished executing
    datasetsFolder : Path
        folder where datasets are stored (samples are symlinked for datasets)
    cache : Path
        folder where cache module stores items
    logs : Path
        folder where node and run logs are stored
    environments : Path
        folder where node stores python environments

Definition at line 27 of file _folder_manager.py.

Member Function Documentation

◆ clearTempFiles()

None coretex._folder_manager.FolderManager.clearTempFiles (   self)
    Deletes all temp files and folders (including artifacts)

Definition at line 145 of file _folder_manager.py.

145  def clearTempFiles(self) -> None:
146  """
147  Deletes all temp files and folders (including artifacts)
148  """
149 
150  self.clearDirectory(self.temp)
151  self.clearDirectory(self._artifactsFolder)
152 

◆ createTempFolder()

Path coretex._folder_manager.FolderManager.createTempFolder (   self,
str  name 
)
    Creates temp folder which is deleted once
    the run has finished executing

    Parameters
    ----------
    name : str
        name of the folder

    Returns
    -------
    Path -> path to the created folder

    Raises
    ------
    FileExistsError -> if the temp folder already exists

    Example
    -------
    >>> from coretex import folder_manager
    \b
    >>> dummyFolderPath = folder_manager.createTempFolder("dummyTempFolder")
    >>> print(dummyFolderPath)
    "/Users/X/.coretex/temp/dummyTempFolder"

Definition at line 81 of file _folder_manager.py.

81  def createTempFolder(self, name: str) -> Path:
82  """
83  Creates temp folder which is deleted once
84  the run has finished executing
85 
86  Parameters
87  ----------
88  name : str
89  name of the folder
90 
91  Returns
92  -------
93  Path -> path to the created folder
94 
95  Raises
96  ------
97  FileExistsError -> if the temp folder already exists
98 
99  Example
100  -------
101  >>> from coretex import folder_manager
102  \b
103  >>> dummyFolderPath = folder_manager.createTempFolder("dummyTempFolder")
104  >>> print(dummyFolderPath)
105  "/Users/X/.coretex/temp/dummyTempFolder"
106  """
107 
108  tempFolderPath = self.temp / name
109 
110  if tempFolderPath.exists():
111  raise FileExistsError
112 
113  tempFolderPath.mkdir()
114  return tempFolderPath
115 

◆ getArtifactsFolder()

Path coretex._folder_manager.FolderManager.getArtifactsFolder (   self,
int  taskRunId 
)
    Retrieves the path to where the artifacts are stored
    for the specified TaskRuns

    Parameters
    ----------
    taskRunId : int
        id of the TaskRun

    Returns
    -------
    Path -> path to the TaskRun artifacts local storage

    Example
    -------
    >>> from coretex.folder_management import FolderManager
    \b
    >>> artifactsFolderPath = FolderManager.instance().getArtifactsFolder(1023)
    >>> print(artifactsFolderPath)
    Path("/Users/bogdanbm/.coretex/artifacts/1023")

Definition at line 116 of file _folder_manager.py.

116  def getArtifactsFolder(self, taskRunId: int) -> Path:
117  """
118  Retrieves the path to where the artifacts are stored
119  for the specified TaskRuns
120 
121  Parameters
122  ----------
123  taskRunId : int
124  id of the TaskRun
125 
126  Returns
127  -------
128  Path -> path to the TaskRun artifacts local storage
129 
130  Example
131  -------
132  >>> from coretex.folder_management import FolderManager
133  \b
134  >>> artifactsFolderPath = FolderManager.instance().getArtifactsFolder(1023)
135  >>> print(artifactsFolderPath)
136  Path("/Users/bogdanbm/.coretex/artifacts/1023")
137  """
138 
139  return self._artifactsFolder / str(taskRunId)
140 

◆ tempFile()

Iterator[Path] coretex._folder_manager.FolderManager.tempFile (   self,
Optional[str]   name = None 
)
    Returns a path to temporary file and deletes
    it if it exists once the context is exited.

    Parameters
    ----------
    name : Optional[str]
        Name of the file. If not specified a random uuid4
        will be generated and used as the name

    Returns
    -------
    Iterator[Path] -> path to the file

Definition at line 160 of file _folder_manager.py.

160  def tempFile(self, name: Optional[str] = None) -> Iterator[Path]:
161  """
162  Returns a path to temporary file and deletes
163  it if it exists once the context is exited.
164 
165  Parameters
166  ----------
167  name : Optional[str]
168  Name of the file. If not specified a random uuid4
169  will be generated and used as the name
170 
171  Returns
172  -------
173  Iterator[Path] -> path to the file
174  """
175 
176  if name is None:
177  name = str(uuid.uuid4())
178 
179  path = self.temp / name
180  if path.exists():
181  raise FileExistsError(path)
182  try:
183  yield path
184  finally:
185  path.unlink(missing_ok = True)
186 
187 

The documentation for this class was generated from the following file: