-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathsitecustomize.py
More file actions
31 lines (27 loc) · 878 Bytes
/
sitecustomize.py
File metadata and controls
31 lines (27 loc) · 878 Bytes
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
import imp
import os
import sys
from pkgutil import ImpLoader
class MappingImporter(object):
def __init__(self, mapping):
self.mapping = mapping
def find_module(self, fullname, path=None):
try:
real_path = self.mapping[fullname]
return ImpLoader(fullname, None, real_path, ('', '', imp.PKG_DIRECTORY))
except KeyError:
return None
# Walk up the path until we find a '.git' subdirectory. Add an importer which
# maps the 'viewfinder' module name to that subdirectory. This allows the
# 'viewfinder' module to be found in a directory that is not named
# 'viewfinder'.
path = os.getcwd()
while path != '/':
try:
if os.path.isdir(os.path.join(path, '.hg')):
sys.meta_path.append(MappingImporter({ 'viewfinder': path }))
break
except OSError:
# path is not a dir or does not exist
pass
path = os.path.dirname(path)