File size: 308 Bytes
f520676
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import sys
from pathlib import Path


class RelativeImport:
    def __init__(self, path):
        self.import_path = Path(path)

    def __enter__(self):
        sys.path.insert(0, str(self.import_path))

    def __exit__(self, exc_type, exc_value, traceback):
        sys.path.remove(str(self.import_path))