Show More
@@ -10,6 +10,7 b' from __future__ import absolute_import' | |||||
10 | import imp |
|
10 | import imp | |
11 | import os |
|
11 | import os | |
12 | import sys |
|
12 | import sys | |
|
13 | import zipimport | |||
13 |
|
14 | |||
14 | __all__ = [] |
|
15 | __all__ = [] | |
15 |
|
16 | |||
@@ -60,6 +61,36 b' class hgimporter(object):' | |||||
60 |
|
61 | |||
61 | mercurial = sys.modules['mercurial'] |
|
62 | mercurial = sys.modules['mercurial'] | |
62 |
|
63 | |||
|
64 | # The zip importer behaves sufficiently differently from the default | |||
|
65 | # importer to warrant its own code path. | |||
|
66 | loader = getattr(mercurial, '__loader__', None) | |||
|
67 | if isinstance(loader, zipimport.zipimporter): | |||
|
68 | def ziploader(*paths): | |||
|
69 | """Obtain a zipimporter for a directory under the main zip.""" | |||
|
70 | path = os.path.join(loader.archive, *paths) | |||
|
71 | zl = sys.path_importer_cache.get(path) | |||
|
72 | if not zl: | |||
|
73 | zl = zipimport.zipimporter(path) | |||
|
74 | return zl | |||
|
75 | ||||
|
76 | try: | |||
|
77 | if modulepolicy == 'py': | |||
|
78 | raise ImportError() | |||
|
79 | ||||
|
80 | zl = ziploader('mercurial') | |||
|
81 | mod = zl.load_module(name) | |||
|
82 | # Unlike imp, ziploader doesn't expose module metadata that | |||
|
83 | # indicates the type of module. So just assume what we found | |||
|
84 | # is OK (even though it could be a pure Python module). | |||
|
85 | except ImportError: | |||
|
86 | if modulepolicy == 'c': | |||
|
87 | raise | |||
|
88 | zl = ziploader('mercurial', 'pure') | |||
|
89 | mod = zl.load_module(name) | |||
|
90 | ||||
|
91 | sys.modules[name] = mod | |||
|
92 | return mod | |||
|
93 | ||||
63 | # Unlike the default importer which searches special locations and |
|
94 | # Unlike the default importer which searches special locations and | |
64 | # sys.path, we only look in the directory where "mercurial" was |
|
95 | # sys.path, we only look in the directory where "mercurial" was | |
65 | # imported from. |
|
96 | # imported from. |
General Comments 0
You need to be logged in to leave comments.
Login now