152 pathname = os.path.join(p, name) |
152 pathname = os.path.join(p, name) |
153 if os.path.exists(pathname): |
153 if os.path.exists(pathname): |
154 return (open(pathname), pathname, (ext, 'r', PTL_SOURCE)) |
154 return (open(pathname), pathname, (ext, 'r', PTL_SOURCE)) |
155 raise ImportError |
155 raise ImportError |
156 |
156 |
|
157 elif ( |
|
158 name.lower().endswith( |
|
159 tuple(Preferences.getPython("PythonExtensions") + |
|
160 Preferences.getPython("Python3Extensions"))) or |
|
161 isPyFile |
|
162 ): |
|
163 for p in path: # search in path |
|
164 pathname = os.path.join(p, name) |
|
165 if os.path.exists(pathname): |
|
166 return (open(pathname), pathname, (ext, 'r', PY_SOURCE)) |
|
167 raise ImportError |
|
168 |
|
169 # standard Python module file |
157 if name.lower().endswith('.py'): |
170 if name.lower().endswith('.py'): |
158 name = name[:-3] |
171 name = name[:-3] |
159 |
172 |
160 try: |
173 spec = importlib.machinery.PathFinder.find_spec(name, path) |
161 return imp.find_module(name, path) |
174 if spec is None: |
162 except ImportError: |
|
163 if ( |
|
164 name.lower().endswith( |
|
165 tuple(Preferences.getPython("PythonExtensions") + |
|
166 Preferences.getPython("Python3Extensions"))) or |
|
167 isPyFile |
|
168 ): |
|
169 for p in path: # search in path |
|
170 pathname = os.path.join(p, name) |
|
171 if os.path.exists(pathname): |
|
172 return (open(pathname), pathname, (ext, 'r', PY_SOURCE)) |
|
173 raise ImportError |
175 raise ImportError |
174 except SyntaxError: |
176 if isinstance(spec.loader, importlib.machinery.SourceFileLoader): |
175 # re-raise as an import error |
177 ext = os.path.splitext(spec.origin)[-1] |
176 raise ImportError |
178 return (open(spec.origin), spec.origin, (ext, 'r', PY_SOURCE)) |
|
179 |
|
180 raise ImportError |