225 |
225 |
226 if sourceType != UNKNOWN_SOURCE: |
226 if sourceType != UNKNOWN_SOURCE: |
227 for p in path: # search in path |
227 for p in path: # search in path |
228 pathname = os.path.join(p, name) |
228 pathname = os.path.join(p, name) |
229 if os.path.exists(pathname): |
229 if os.path.exists(pathname): |
230 return (open(pathname), pathname, (ext, "r", sourceType)) # noqa: Y115 |
230 return (open(pathname), pathname, (ext, "r", sourceType)) # noqa: Y-115 |
231 raise ImportError |
231 raise ImportError |
232 else: |
232 else: |
233 # standard Python module file |
233 # standard Python module file |
234 if name.lower().endswith(".py"): |
234 if name.lower().endswith(".py"): |
235 name = name[:-3] |
235 name = name[:-3] |
237 spec = importlib.machinery.PathFinder.find_spec(name, path) |
237 spec = importlib.machinery.PathFinder.find_spec(name, path) |
238 if spec is None: |
238 if spec is None: |
239 raise ImportError |
239 raise ImportError |
240 if isinstance(spec.loader, importlib.machinery.SourceFileLoader): |
240 if isinstance(spec.loader, importlib.machinery.SourceFileLoader): |
241 ext = os.path.splitext(spec.origin)[-1] |
241 ext = os.path.splitext(spec.origin)[-1] |
242 return (open(spec.origin), spec.origin, (ext, "r", PY_SOURCE)) # noqa: Y115 |
242 return (open(spec.origin), spec.origin, (ext, "r", PY_SOURCE)) |
|
243 # noqa: Y-115 |
243 |
244 |
244 raise ImportError |
245 raise ImportError |
245 |
246 |
246 |
247 |
247 def determineSourceType(name, isPyFile=False): |
248 def determineSourceType(name, isPyFile=False): |