aboutsummaryrefslogtreecommitdiff
path: root/modules/import_hook.py
blob: eb10e4fdea8866504e6683ee1e8ea3f1098171e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import builtins
import sys

old_import = builtins.__import__
IMPORT_BLACKLIST = []


if "xformers" not in "".join(sys.argv):
    IMPORT_BLACKLIST.append("xformers")


def import_hook(*args, **kwargs):
    if args[0] in IMPORT_BLACKLIST:
        raise ImportError("Import of %s is blacklisted" % args[0])
    return old_import(*args, **kwargs)


builtins.__import__ = import_hook