Document the (very small) public API for importlib. As time goes on and some
key refactorings occur more of the API will be exposed and documented.
diff --git a/Lib/importlib/NOTES b/Lib/importlib/NOTES
index 95d002b..e0ca28c 100644
--- a/Lib/importlib/NOTES
+++ b/Lib/importlib/NOTES
@@ -1,12 +1,11 @@
to do
/////
-* Write importlib.__import__
+* Expose resolve_name().
-* Document
- + Package.
+* Backport to Python 2.7.
+ import_module
- + __import__
+ + resolve_name
* Create reasonable base tests that all finders and loaders must pass so
that various implementations can just subclass as needed.
@@ -42,7 +41,7 @@
- Absolute name from sys.path.
- Relative name from sys.path.
-* Public API (w/ docs!)
+* Public API to expose (w/ docs!)
+ abc
- Finder
* find_module
@@ -72,9 +71,5 @@
- Source/bytecode importers
* SourceFinder
* (?) Loader
- + __init__
- - __import__
- - import_module (backport to 2.7)
- - resolve_name (backport to 2.7)
* Bootstrap importlib as implementation of builtins.__import__
diff --git a/Lib/importlib/__init__.py b/Lib/importlib/__init__.py
index b59c9c4..8d11502d 100644
--- a/Lib/importlib/__init__.py
+++ b/Lib/importlib/__init__.py
@@ -79,27 +79,6 @@
return x
-def import_module(name, package=None):
- """Import a module.
-
- The 'package' argument is used to resolve relative import names. Typically
- this is the __package__ attribute of the module making the function call.
-
- """
- if name.startswith('.'):
- if not package:
- raise TypeError("relative imports require the 'package' argument")
- level = 0
- for character in name:
- if character != '.':
- break
- level += 1
- name = Import._resolve_name(name[level:], package, level)
- __import__(name)
- return sys.modules[name]
-
-
-
# Required built-in modules.
try:
import posix as _os
@@ -130,4 +109,30 @@
marshal._w_long = _w_long
marshal._r_long = _r_long
+
+__import__ = _bootstrap.Import().__call__
+
+
+def import_module(name, package=None):
+ """Import a module.
+
+ The 'package' argument is required when performing a relative import. It
+ specifies the package to use as the anchor point from which to resolve the
+ relative import to an absolute import.
+
+ """
+ if name.startswith('.'):
+ if not package:
+ raise TypeError("relative imports require the 'package' argument")
+ level = 0
+ for character in name:
+ if character != '.':
+ break
+ level += 1
+ name = Import._resolve_name(name[level:], package, level)
+ __import__(name)
+ return sys.modules[name]
+
+
+
from ._bootstrap import *