| 154 | return [path for path in glob.iglob(os.path.join(self.path, "*")) if "__pycache__" not in path] |
| 155 | |
| 156 | def _remove_artifacts(self, must_exist=True): |
| 157 | for artifact in self.artifacts: |
| 158 | if must_exist: |
| 159 | print(f"Checking for the existence of artifact: {artifact}") |
| 160 | assert os.path.exists(artifact), f"{artifact} does not exist!" |
| 161 | elif not os.path.exists(artifact): |
| 162 | continue |
| 163 | |
| 164 | if os.path.isdir(artifact): |
| 165 | shutil.rmtree(artifact) |
| 166 | else: |
| 167 | os.remove(artifact) |
| 168 | |
| 169 | def __enter__(self): |
| 170 | self._remove_artifacts(must_exist=False) |