-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathautoinstaller.py
36 lines (30 loc) · 1023 Bytes
/
autoinstaller.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# Created by Massimo Di Pierro (http://experts4solutions.com) @2016 BSDv3 License
import sys, imp
from ez_setup import use_setuptools
use_setuptools()
from setuptools.command.easy_install import main
class SmartImporter(object):
tried_modules=set()
domain_modules = set()
def find_module(self, fullname, path=None):
if fullname in self.domain_modules:
return self
if fullname in self.tried_modules:
return None
else:
self.tried_modules.add(fullname)
try:
main([fullname])
return self
except:
return None
def load_module(self, fullname):
if fullname in sys.modules:
return sys.modules[fullname]
mod = imp.new_module(fullname)
mod.__loader__ = self
sys.modules[fullname] = mod
if fullname not in self.domain_modules:
self.domain_modules.add(fullname)
return mod
sys.meta_path = [SmartImporter()]