##// END OF EJS Templates
Add proper warnings on use of the backwards compatibility shim.
Fernando Perez -
Show More
@@ -1,11 +1,51 b''
1 """
2 Shim to maintain backwards compatibility with old frontend imports.
3
4 We have moved all contents of the old `frontend` subpackage into top-level
5 subpackages (`html`, `qt` and `terminal`). This will let code that was making
6 `from IPython.frontend...` calls continue working, though a warning will be
7 printed.
8 """
9
10 #-----------------------------------------------------------------------------
11 # Copyright (c) 2013, IPython Development Team.
12 #
13 # Distributed under the terms of the Modified BSD License.
14 #
15 # The full license is in the file COPYING.txt, distributed with this software.
16 #-----------------------------------------------------------------------------
17
18 #-----------------------------------------------------------------------------
19 # Imports
20 #-----------------------------------------------------------------------------
21 from __future__ import print_function
1 import sys
22 import sys
2 import types
23 import types
3
24
25 #-----------------------------------------------------------------------------
26 # Class declarations
27 #-----------------------------------------------------------------------------
4
28
5 class ShimModule(types.ModuleType):
29 class ShimModule(types.ModuleType):
6
30
7 def __getattribute__(self, key):
31 def __getattribute__(self, key):
32 m = ("*** WARNING*** : The top-level `frontend` module has been deprecated.\n"
33 "Please import %s directly from the `IPython` level." % key)
34
35 # FIXME: I don't understand why, but if the print statement below is
36 # redirected to stderr, this shim module stops working. It seems the
37 # Python import machinery has problem with redirected prints happening
38 # during the import process. If we can't figure out a solution, we may
39 # need to leave it to print to default stdout.
40 print(m)
41
42 # FIXME: this seems to work fine, but we should replace it with an
43 # __import__ call instead of using exec/eval.
8 exec 'from IPython import %s' % key
44 exec 'from IPython import %s' % key
9 return eval(key)
45 return eval(key)
10
46
47
48 # Unconditionally insert the shim into sys.modules so that further import calls
49 # trigger the custom attribute access above
50
11 sys.modules['IPython.frontend'] = ShimModule('frontend')
51 sys.modules['IPython.frontend'] = ShimModule('frontend')
General Comments 0
You need to be logged in to leave comments. Login now