Show More
@@ -19,6 +19,7 b' import __builtin__ as builtin_mod' | |||
|
19 | 19 | import __future__ |
|
20 | 20 | import bdb |
|
21 | 21 | import inspect |
|
22 | import imp | |
|
22 | 23 | import os |
|
23 | 24 | import sys |
|
24 | 25 | import shutil |
@@ -91,11 +92,24 b' def needs_local_scope(func):' | |||
|
91 | 92 | func.needs_local_scope = True |
|
92 | 93 | return func |
|
93 | 94 | |
|
94 | import imp, os | |
|
95 | ||
|
96 | 95 | def find_module(name, path=None): |
|
97 | 96 | """imp.find_module variant that only return path of module. |
|
98 | Return None if module is missing or does not have .py or .pyw extension | |
|
97 | ||
|
98 | The `imp.find_module` returns a filehandle that we are not interested in. | |
|
99 | Also we ignore any bytecode files that `imp.find_module` finds. | |
|
100 | ||
|
101 | Parameters | |
|
102 | ---------- | |
|
103 | name : str | |
|
104 | name of module to locate | |
|
105 | path : list of str | |
|
106 | list of paths to search for `name`. If path=None then search sys.path | |
|
107 | ||
|
108 | Returns | |
|
109 | ------- | |
|
110 | filename : str | |
|
111 | Return full path of module or None if module is missing or does not have | |
|
112 | .py or .pyw extension | |
|
99 | 113 | """ |
|
100 | 114 | if name is None: |
|
101 | 115 | return None |
@@ -113,7 +127,17 b' def find_module(name, path=None):' | |||
|
113 | 127 | return None |
|
114 | 128 | |
|
115 | 129 | def get_init(dirname): |
|
116 |
"""Get __init__ file path for module |
|
|
130 | """Get __init__ file path for module directory | |
|
131 | ||
|
132 | Parameters | |
|
133 | ---------- | |
|
134 | dirname : str | |
|
135 | Find the __init__ file in directory `dirname` | |
|
136 | ||
|
137 | Returns | |
|
138 | ------- | |
|
139 | init_path : str | |
|
140 | Path to __init__ file | |
|
117 | 141 | """ |
|
118 | 142 | fbase = os.path.join(dirname, "__init__") |
|
119 | 143 | for ext in [".py", ".pyw"]: |
@@ -122,10 +146,24 b' def get_init(dirname):' | |||
|
122 | 146 | return fname |
|
123 | 147 | |
|
124 | 148 | |
|
125 | def find_mod(name): | |
|
126 |
"""Find module |
|
|
149 | def find_mod(module_name): | |
|
150 | """Find module `module_name` on sys.path | |
|
151 | ||
|
152 | Return the path to module `module_name`. If `module_name` refers to | |
|
153 | a module directory then return path to __init__ file. Return full | |
|
154 | path of module or None if module is missing or does not have .py or .pyw | |
|
155 | extension. We are not interested in running bytecode. | |
|
156 | ||
|
157 | Parameters | |
|
158 | ---------- | |
|
159 | module_name : str | |
|
160 | ||
|
161 | Returns | |
|
162 | ------- | |
|
163 | modulepath : str | |
|
164 | Path to module `module_name`. | |
|
127 | 165 | """ |
|
128 | parts = name.split(".") | |
|
166 | parts = module_name.split(".") | |
|
129 | 167 | basepath = find_module(parts[0]) |
|
130 | 168 | for submodname in parts[1:]: |
|
131 | 169 | basepath = find_module(submodname, [basepath]) |
General Comments 0
You need to be logged in to leave comments.
Login now