-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
__init__.py
45 lines (29 loc) · 1014 Bytes
/
__init__.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
36
37
38
39
40
41
42
43
44
45
import sys
import os
def enabled():
"""
Allow selection of distutils by environment variable.
"""
which = os.environ.get('SETUPTOOLS_USE_DISTUTILS', 'stdlib')
return which == 'local'
class DistutilsMetaFinder:
def find_spec(self, fullname, path, target=None):
if path is not None or fullname != "distutils":
return None
return self.get_distutils_spec()
def get_distutils_spec(self):
import importlib.util
class DistutilsLoader(importlib.util.abc.Loader):
def create_module(self, spec):
return importlib.import_module('._distutils', 'setuptools')
def exec_module(self, module):
pass
return importlib.util.spec_from_loader('distutils', DistutilsLoader())
DISTUTILS_FINDER = DistutilsMetaFinder()
def add_shim():
sys.meta_path.insert(0, DISTUTILS_FINDER)
def remove_shim():
try:
sys.path.remove(DISTUTILS_FINDER)
except ValueError:
pass