Show More
@@ -26,6 +26,7 b' import sys' | |||||
26 | import unicodedata |
|
26 | import unicodedata | |
27 | import string |
|
27 | import string | |
28 | import warnings |
|
28 | import warnings | |
|
29 | from importlib import import_module | |||
29 |
|
30 | |||
30 | from traitlets.config.configurable import Configurable |
|
31 | from traitlets.config.configurable import Configurable | |
31 | from IPython.core.error import TryNext |
|
32 | from IPython.core.error import TryNext | |
@@ -481,7 +482,7 b' def _safe_isinstance(obj, module, class_name):' | |||||
481 | """Checks if obj is an instance of module.class_name if loaded |
|
482 | """Checks if obj is an instance of module.class_name if loaded | |
482 | """ |
|
483 | """ | |
483 | return (module in sys.modules and |
|
484 | return (module in sys.modules and | |
484 |
isinstance(obj, getattr( |
|
485 | isinstance(obj, getattr(import_module(module), class_name))) | |
485 |
|
486 | |||
486 |
|
487 | |||
487 | def back_unicode_name_matches(text): |
|
488 | def back_unicode_name_matches(text): |
@@ -22,6 +22,7 b' import inspect' | |||||
22 | import os |
|
22 | import os | |
23 | import re |
|
23 | import re | |
24 | import sys |
|
24 | import sys | |
|
25 | from importlib import import_module | |||
25 |
|
26 | |||
26 | try: |
|
27 | try: | |
27 | # Python >= 3.3 |
|
28 | # Python >= 3.3 | |
@@ -155,12 +156,9 b' def is_importable(module, attr, only_modules):' | |||||
155 |
|
156 | |||
156 | def try_import(mod, only_modules=False): |
|
157 | def try_import(mod, only_modules=False): | |
157 | try: |
|
158 | try: | |
158 |
m = |
|
159 | m = import_module(mod) | |
159 | except: |
|
160 | except: | |
160 | return [] |
|
161 | return [] | |
161 | mods = mod.split('.') |
|
|||
162 | for module in mods[1:]: |
|
|||
163 | m = getattr(m, module) |
|
|||
164 |
|
162 | |||
165 | m_is_init = hasattr(m, '__file__') and '__init__' in m.__file__ |
|
163 | m_is_init = hasattr(m, '__file__') and '__init__' in m.__file__ | |
166 |
|
164 |
@@ -7,6 +7,7 b'' | |||||
7 | import os |
|
7 | import os | |
8 | from shutil import copyfile |
|
8 | from shutil import copyfile | |
9 | import sys |
|
9 | import sys | |
|
10 | from importlib import import_module | |||
10 |
|
11 | |||
11 | from traitlets.config.configurable import Configurable |
|
12 | from traitlets.config.configurable import Configurable | |
12 | from IPython.utils.path import ensure_dir_exists |
|
13 | from IPython.utils.path import ensure_dir_exists | |
@@ -80,7 +81,7 b' class ExtensionManager(Configurable):' | |||||
80 | with self.shell.builtin_trap: |
|
81 | with self.shell.builtin_trap: | |
81 | if module_str not in sys.modules: |
|
82 | if module_str not in sys.modules: | |
82 | with prepended_to_syspath(self.ipython_extension_dir): |
|
83 | with prepended_to_syspath(self.ipython_extension_dir): | |
83 |
|
|
84 | import_module(module_str) | |
84 | mod = sys.modules[module_str] |
|
85 | mod = sys.modules[module_str] | |
85 | if self._call_load_ipython_extension(mod): |
|
86 | if self._call_load_ipython_extension(mod): | |
86 | self.loaded.add(module_str) |
|
87 | self.loaded.add(module_str) |
@@ -112,6 +112,7 b' import sys' | |||||
112 | import traceback |
|
112 | import traceback | |
113 | import types |
|
113 | import types | |
114 | import weakref |
|
114 | import weakref | |
|
115 | from importlib import import_module | |||
115 |
|
116 | |||
116 | try: |
|
117 | try: | |
117 | # Reload is not defined by default in Python3. |
|
118 | # Reload is not defined by default in Python3. | |
@@ -177,7 +178,7 b' class ModuleReloader(object):' | |||||
177 | """ |
|
178 | """ | |
178 | self.mark_module_reloadable(module_name) |
|
179 | self.mark_module_reloadable(module_name) | |
179 |
|
180 | |||
180 |
|
|
181 | import_module(module_name) | |
181 | top_name = module_name.split('.')[0] |
|
182 | top_name = module_name.split('.')[0] | |
182 | top_module = sys.modules[top_name] |
|
183 | top_module = sys.modules[top_name] | |
183 | return top_module, top_name |
|
184 | return top_module, top_name |
@@ -11,6 +11,7 b' be accessed directly from the outside' | |||||
11 | import sys |
|
11 | import sys | |
12 | import types |
|
12 | import types | |
13 | from functools import partial |
|
13 | from functools import partial | |
|
14 | from importlib import import_module | |||
14 |
|
15 | |||
15 | from IPython.utils.version import check_version |
|
16 | from IPython.utils.version import check_version | |
16 |
|
17 | |||
@@ -113,7 +114,7 b' def has_binding(api):' | |||||
113 | import imp |
|
114 | import imp | |
114 | try: |
|
115 | try: | |
115 | #importing top level PyQt4/PySide module is ok... |
|
116 | #importing top level PyQt4/PySide module is ok... | |
116 |
mod = |
|
117 | mod = import_module(module_name) | |
117 | #...importing submodules is not |
|
118 | #...importing submodules is not | |
118 | imp.find_module('QtCore', mod.__path__) |
|
119 | imp.find_module('QtCore', mod.__path__) | |
119 | imp.find_module('QtGui', mod.__path__) |
|
120 | imp.find_module('QtGui', mod.__path__) |
@@ -36,6 +36,7 b' import os' | |||||
36 | import tempfile |
|
36 | import tempfile | |
37 | import unittest |
|
37 | import unittest | |
38 | import warnings |
|
38 | import warnings | |
|
39 | from importlib import import_module | |||
39 |
|
40 | |||
40 | from decorator import decorator |
|
41 | from decorator import decorator | |
41 |
|
42 | |||
@@ -268,7 +269,7 b' def module_not_available(module):' | |||||
268 | available, but delay the 'import numpy' to test execution time. |
|
269 | available, but delay the 'import numpy' to test execution time. | |
269 | """ |
|
270 | """ | |
270 | try: |
|
271 | try: | |
271 |
mod = |
|
272 | mod = import_module(module) | |
272 | mod_not_avail = False |
|
273 | mod_not_avail = False | |
273 | except ImportError: |
|
274 | except ImportError: | |
274 | mod_not_avail = True |
|
275 | mod_not_avail = True |
@@ -25,6 +25,7 b' import logging' | |||||
25 | import os |
|
25 | import os | |
26 | import re |
|
26 | import re | |
27 | import sys |
|
27 | import sys | |
|
28 | from importlib import import_module | |||
28 |
|
29 | |||
29 | from testpath import modified_env |
|
30 | from testpath import modified_env | |
30 |
|
31 | |||
@@ -646,7 +647,7 b' class ExtensionDoctest(doctests.Doctest):' | |||||
646 | modname = os.path.splitext(mod)[0] |
|
647 | modname = os.path.splitext(mod)[0] | |
647 | try: |
|
648 | try: | |
648 | sys.path.append(bpath) |
|
649 | sys.path.append(bpath) | |
649 |
module = |
|
650 | module = import_module(modname) | |
650 | tests = list(self.loadTestsFromModule(module)) |
|
651 | tests = list(self.loadTestsFromModule(module)) | |
651 | finally: |
|
652 | finally: | |
652 | sys.path.pop() |
|
653 | sys.path.pop() |
@@ -5,9 +5,11 b'' | |||||
5 |
|
5 | |||
6 | import sys |
|
6 | import sys | |
7 | import types |
|
7 | import types | |
|
8 | from importlib import import_module | |||
8 |
|
9 | |||
9 | from .importstring import import_item |
|
10 | from .importstring import import_item | |
10 |
|
11 | |||
|
12 | ||||
11 | class ShimWarning(Warning): |
|
13 | class ShimWarning(Warning): | |
12 | """A warning to show when a module has moved, and a shim is in its place.""" |
|
14 | """A warning to show when a module has moved, and a shim is in its place.""" | |
13 |
|
15 | |||
@@ -69,15 +71,15 b' class ShimModule(types.ModuleType):' | |||||
69 | @property |
|
71 | @property | |
70 | def __spec__(self): |
|
72 | def __spec__(self): | |
71 | """Don't produce __spec__ until requested""" |
|
73 | """Don't produce __spec__ until requested""" | |
72 |
return |
|
74 | return import_module(self._mirror).__spec__ | |
73 |
|
75 | |||
74 | def __dir__(self): |
|
76 | def __dir__(self): | |
75 |
return dir( |
|
77 | return dir(import_module(self._mirror)) | |
76 |
|
78 | |||
77 | @property |
|
79 | @property | |
78 | def __all__(self): |
|
80 | def __all__(self): | |
79 | """Ensure __all__ is always defined""" |
|
81 | """Ensure __all__ is always defined""" | |
80 |
mod = |
|
82 | mod = import_module(self._mirror) | |
81 | try: |
|
83 | try: | |
82 | return mod.__all__ |
|
84 | return mod.__all__ | |
83 | except AttributeError: |
|
85 | except AttributeError: |
@@ -24,6 +24,8 b' import ast' | |||||
24 | import inspect |
|
24 | import inspect | |
25 | import os |
|
25 | import os | |
26 | import re |
|
26 | import re | |
|
27 | from importlib import import_module | |||
|
28 | ||||
27 |
|
29 | |||
28 | class Obj(object): |
|
30 | class Obj(object): | |
29 | '''Namespace to hold arbitrary information.''' |
|
31 | '''Namespace to hold arbitrary information.''' | |
@@ -147,7 +149,7 b' class ApiDocWriter(object):' | |||||
147 | ''' |
|
149 | ''' | |
148 | # It's also possible to imagine caching the module parsing here |
|
150 | # It's also possible to imagine caching the module parsing here | |
149 | self._package_name = package_name |
|
151 | self._package_name = package_name | |
150 |
self.root_module = |
|
152 | self.root_module = import_module(package_name) | |
151 | self.root_path = self.root_module.__path__[0] |
|
153 | self.root_path = self.root_module.__path__[0] | |
152 | self.written_modules = None |
|
154 | self.written_modules = None | |
153 |
|
155 |
General Comments 0
You need to be logged in to leave comments.
Login now