summaryrefslogtreecommitdiffstats
path: root/Lib/runpy.py
diff options
context:
space:
mode:
authorBrett Cannon <brett@python.org>2012-04-26 00:54:04 (GMT)
committerBrett Cannon <brett@python.org>2012-04-26 00:54:04 (GMT)
commite0d88a173c5ccc346b8d7c6e805f0e49b4ea92f7 (patch)
tree476528c79622c96645adf554536eeeba0c4ee0d8 /Lib/runpy.py
parent8f79dd5d7cc3eb19d568f8e95f04ee33f1177d92 (diff)
downloadcpython-e0d88a173c5ccc346b8d7c6e805f0e49b4ea92f7.zip
cpython-e0d88a173c5ccc346b8d7c6e805f0e49b4ea92f7.tar.gz
cpython-e0d88a173c5ccc346b8d7c6e805f0e49b4ea92f7.tar.bz2
Issue #14605: Make explicit the entries on sys.path_hooks that used to
be implicit. Added a warning for when sys.path_hooks is found to be empty. Also changed the meaning of None in sys.path_importer_cache to represent trying sys.path_hooks again (an interpretation of previous semantics). Also added a warning for when None was found. The long-term goal is for None in sys.path_importer_cache to represent the same as imp.NullImporter: no finder found for that sys.path entry.
Diffstat (limited to 'Lib/runpy.py')
-rw-r--r--Lib/runpy.py12
1 files changed, 3 insertions, 9 deletions
diff --git a/Lib/runpy.py b/Lib/runpy.py
index 31e5e55..f826e04 100644
--- a/Lib/runpy.py
+++ b/Lib/runpy.py
@@ -9,6 +9,7 @@ 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
@@ -94,7 +95,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
@@ -198,10 +199,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)
@@ -213,10 +210,7 @@ def _get_importer(path_name):
# 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 = imp.NullImporter(path_name)
cache[path_name] = importer
return importer