Skip to content

Commit

Permalink
implement support for local extensions via AltTemporaryDirectory
Browse files Browse the repository at this point in the history
as implemented in MichalKubek@5e3ca75
  • Loading branch information
Chilipp committed Mar 24, 2023
1 parent 1fd1548 commit 7c63ae4
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions cruft/_commands/utils/iohelper.py
@@ -1,15 +1,23 @@
from tempfile import TemporaryDirectory
from time import sleep
import sys


class AltTemporaryDirectory:
def __init__(self):
self.tmpdir = TemporaryDirectory()
self._extended_path = False
name = self.tmpdir.name
if name not in sys.path:
self._extended_path = True
sys.path.append(name)

def __enter__(self):
return self.tmpdir.name

def cleanup(self, cnt=0):
if self._extended_path:
sys.path.remove(self.tmpdir.name)
if cnt >= 5: # pragma: no cover
raise RuntimeError("Could not delete TemporaryDirectory!")
try:
Expand Down

0 comments on commit 7c63ae4

Please sign in to comment.