summaryrefslogtreecommitdiffstats
path: root/Lib/runpy.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/runpy.py')
-rw-r--r--Lib/runpy.py19
1 files changed, 5 insertions, 14 deletions
diff --git a/Lib/runpy.py b/Lib/runpy.py
index 7cb4668..8ca325b 100644
--- a/Lib/runpy.py
+++ b/Lib/runpy.py
@@ -9,6 +9,8 @@ importers when locating support scripts as well as when importing modules.
# Written by Nick Coghlan <ncoghlan at gmail.com>
# to implement PEP 338 (Executing Modules as Scripts)
+
+import os
import sys
import imp
from pkgutil import read_code
@@ -95,7 +97,7 @@ def _get_filename(loader, mod_name):
for attr in ("get_filename", "_get_filename"):
meth = getattr(loader, attr, None)
if meth is not None:
- return meth(mod_name)
+ return os.path.abspath(meth(mod_name))
return None
# Helper to get the loader, code and filename for a module
@@ -199,10 +201,6 @@ def _get_importer(path_name):
try:
importer = cache[path_name]
except KeyError:
- # Not yet cached. Flag as using the
- # standard machinery until we finish
- # checking the hooks
- cache[path_name] = None
for hook in sys.path_hooks:
try:
importer = hook(path_name)
@@ -210,14 +208,7 @@ def _get_importer(path_name):
except ImportError:
pass
else:
- # The following check looks a bit odd. The trick is that
- # NullImporter throws ImportError if the supplied path is a
- # *valid* directory entry (and hence able to be handled
- # by the standard import machinery)
- try:
- importer = imp.NullImporter(path_name)
- except ImportError:
- return None
+ importer = None
cache[path_name] = importer
return importer
@@ -245,7 +236,7 @@ def run_path(path_name, init_globals=None, run_name=None):
run_name = "<run_path>"
pkg_name = run_name.rpartition(".")[0]
importer = _get_importer(path_name)
- if isinstance(importer, imp.NullImporter):
+ if isinstance(importer, (type(None), imp.NullImporter)):
# Not a valid sys.path entry, so run the code directly
# execfile() doesn't help as we want to allow compiled files
code = _get_code_from_file(path_name)