summaryrefslogtreecommitdiffstats
path: root/Lib/importlib
diff options
context:
space:
mode:
authorBrett Cannon <bcannon@gmail.com>2009-01-20 02:21:27 (GMT)
committerBrett Cannon <bcannon@gmail.com>2009-01-20 02:21:27 (GMT)
commitafccd63ac9541630953cd4e59a421696d3869311 (patch)
tree35229a6a1a7b3836c50f660fed3df2a8f40e14e5 /Lib/importlib
parentdf50106408d525a8e7022b6545ecbd0c13ce8740 (diff)
downloadcpython-afccd63ac9541630953cd4e59a421696d3869311.zip
cpython-afccd63ac9541630953cd4e59a421696d3869311.tar.gz
cpython-afccd63ac9541630953cd4e59a421696d3869311.tar.bz2
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.
Diffstat (limited to 'Lib/importlib')
-rw-r--r--Lib/importlib/NOTES13
-rw-r--r--Lib/importlib/__init__.py47
2 files changed, 30 insertions, 30 deletions
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 @@ to do
- 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 @@ to do
- 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 @@ def _r_long(int_bytes):
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 @@ _bootstrap._case_ok = _case_ok
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 *