##// END OF EJS Templates
Merging Jorgen's py2exe fix branch.
Jorgen Stenarson -
r1871:a1a785b2 merge
parent child Browse files
Show More
@@ -928,12 +928,15 def get_home_dir():
928 # first, check py2exe distribution root directory for _ipython.
928 # first, check py2exe distribution root directory for _ipython.
929 # This overrides all. Normally does not exist.
929 # This overrides all. Normally does not exist.
930
930
931 if '\\library.zip\\' in IPython.__file__.lower():
931 if hasattr(sys, "frozen"): #Is frozen by py2exe
932 root, rest = IPython.__file__.lower().split('library.zip')
932 if '\\library.zip\\' in IPython.__file__.lower():#libraries compressed to zip-file
933 if isdir(root + '_ipython'):
933 root, rest = IPython.__file__.lower().split('library.zip')
934 os.environ["IPYKITROOT"] = root.rstrip('\\')
934 else:
935 return root
935 root=os.path.join(os.path.split(IPython.__file__)[0],"../../")
936
936 root=os.path.abspath(root).rstrip('\\')
937 if isdir(os.path.join(root, '_ipython')):
938 os.environ["IPYKITROOT"] = root
939 return root
937 try:
940 try:
938 homedir = env['HOME']
941 homedir = env['HOME']
939 if not isdir(homedir):
942 if not isdir(homedir):
@@ -953,7 +956,7 def get_home_dir():
953 if not isdir(homedir):
956 if not isdir(homedir):
954 raise HomeDirError
957 raise HomeDirError
955 return homedir
958 return homedir
956 except:
959 except KeyError:
957 try:
960 try:
958 # Use the registry to get the 'My Documents' folder.
961 # Use the registry to get the 'My Documents' folder.
959 import _winreg as wreg
962 import _winreg as wreg
@@ -992,8 +995,8 def get_ipython_dir():
992 ipdir_def = '_ipython'
995 ipdir_def = '_ipython'
993 home_dir = get_home_dir()
996 home_dir = get_home_dir()
994 ipdir = os.path.abspath(os.environ.get('IPYTHONDIR',
997 ipdir = os.path.abspath(os.environ.get('IPYTHONDIR',
995 os.path.join(home_dir,ipdir_def)))
998 os.path.join(home_dir, ipdir_def)))
996 return ipdir
999 return ipdir.decode(sys.getfilesystemencoding())
997
1000
998 def get_security_dir():
1001 def get_security_dir():
999 """Get the IPython security directory.
1002 """Get the IPython security directory.
@@ -1371,6 +1371,7 want to merge them back into the new files.""" % locals()
1371 # not run as the syntax for libedit is different.
1371 # not run as the syntax for libedit is different.
1372 if not readline.uses_libedit:
1372 if not readline.uses_libedit:
1373 for rlcommand in self.rc.readline_parse_and_bind:
1373 for rlcommand in self.rc.readline_parse_and_bind:
1374 #print "loading rl:",rlcommand # dbg
1374 readline.parse_and_bind(rlcommand)
1375 readline.parse_and_bind(rlcommand)
1375
1376
1376 # remove some chars from the delimiters list
1377 # remove some chars from the delimiters list
@@ -131,20 +131,15 object? -> Details about 'object'. ?object also works, ?? prints more.
131
131
132 IP.usage = interactive_usage
132 IP.usage = interactive_usage
133
133
134 # Platform-dependent suffix and directory names. We use _ipython instead
134 # Platform-dependent suffix.
135 # of .ipython under win32 b/c there's software that breaks with .named
136 # directories on that platform.
137 if os.name == 'posix':
135 if os.name == 'posix':
138 rc_suffix = ''
136 rc_suffix = ''
139 ipdir_def = '.ipython'
140 else:
137 else:
141 rc_suffix = '.ini'
138 rc_suffix = '.ini'
142 ipdir_def = '_ipython'
143
139
144 # default directory for configuration
140 # default directory for configuration
145 ipythondir_def = os.path.abspath(os.environ.get('IPYTHONDIR',
141 ipythondir_def = get_ipython_dir()
146 os.path.join(IP.home_dir,ipdir_def)))
142
147
148 sys.path.insert(0, '') # add . to sys.path. Fix from Prabhu Ramachandran
143 sys.path.insert(0, '') # add . to sys.path. Fix from Prabhu Ramachandran
149
144
150 # we need the directory where IPython itself is installed
145 # we need the directory where IPython itself is installed
@@ -155,6 +155,11 def skip(msg=''):
155 return inner
155 return inner
156
156
157 # Decorators to skip certain tests on specific platforms.
157 # Decorators to skip certain tests on specific platforms.
158 skip_win32 = skipif(sys.platform=='win32',"This test does not run under Windows")
158 skip_win32 = skipif(sys.platform == 'win32',"This test does not run under Windows")
159 skip_linux = skipif(sys.platform=='linux2',"This test does not run under Linux")
159 skip_linux = skipif(sys.platform == 'linux2',"This test does not run under Linux")
160 skip_osx = skipif(sys.platform=='darwin',"This test does not run under OSX")
160 skip_osx = skipif(sys.platform == 'darwin',"This test does not run under OSX")
161
162 # Decorators to skip tests if not on specific platforms.
163 skip_if_not_win32 = skipif(sys.platform != 'win32', "This test only runs under Windows")
164 skip_if_not_linux = skipif(sys.platform != 'linux2', "This test only runs under Linux")
165 skip_if_not_osx = skipif(sys.platform != 'darwin', "This test only runs under OSX")
@@ -15,18 +15,277 __docformat__ = "restructuredtext en"
15 # Imports
15 # Imports
16 #-----------------------------------------------------------------------------
16 #-----------------------------------------------------------------------------
17
17
18 # stdlib
19 import os
20 import shutil
21 import sys
22 import tempfile
23
24 from os.path import join, abspath, split
25
26 # third-party
27 import nose.tools as nt
28
29 from nose import with_setup
30 from nose.tools import raises
31
32 # Our own
33 import IPython
18 from IPython import genutils
34 from IPython import genutils
35 from IPython.testing.decorators import skipif, skip_if_not_win32
36
37 # Platform-dependent imports
38 try:
39 import _winreg as wreg
40 except ImportError:
41 #Fake _winreg module on none windows platforms
42 import new
43 sys.modules["_winreg"] = new.module("_winreg")
44 import _winreg as wreg
45 #Add entries that needs to be stubbed by the testing code
46 (wreg.OpenKey, wreg.QueryValueEx,) = (None, None)
47
48 #-----------------------------------------------------------------------------
49 # Globals
50 #-----------------------------------------------------------------------------
51 env = os.environ
52 TEST_FILE_PATH = split(abspath(__file__))[0]
53 TMP_TEST_DIR = tempfile.mkdtemp()
54 HOME_TEST_DIR = join(TMP_TEST_DIR, "home_test_dir")
55 IP_TEST_DIR = join(HOME_TEST_DIR,'_ipython')
56 #
57 # Setup/teardown functions/decorators
58 #
59
60 def setup():
61 """Setup testenvironment for the module:
62
63 - Adds dummy home dir tree
64 """
65 # Do not mask exceptions here. In particular, catching WindowsError is a
66 # problem because that exception is only defined on Windows...
67 os.makedirs(IP_TEST_DIR)
68
69 def teardown():
70 """Teardown testenvironment for the module:
71
72 - Remove dummy home dir tree
73 """
74 # Note: we remove the parent test dir, which is the root of all test
75 # subdirs we may have created. Use shutil instead of os.removedirs, so
76 # that non-empty directories are all recursively removed.
77 shutil.rmtree(TMP_TEST_DIR)
78
79
80 def setup_environment():
81 """Setup testenvironment for some functions that are tested
82 in this module. In particular this functions stores attributes
83 and other things that we need to stub in some test functions.
84 This needs to be done on a function level and not module level because
85 each testfunction needs a pristine environment.
86 """
87 global oldstuff, platformstuff
88 oldstuff = (env.copy(), os.name, genutils.get_home_dir, IPython.__file__,)
89
90 if os.name == 'nt':
91 platformstuff = (wreg.OpenKey, wreg.QueryValueEx,)
92
93 if 'IPYTHONDIR' in env:
94 del env['IPYTHONDIR']
95
96 def teardown_environment():
97 """Restore things that were remebered by the setup_environment function
98 """
99 (oldenv, os.name, genutils.get_home_dir, IPython.__file__,) = oldstuff
100 for key in env.keys():
101 if key not in oldenv:
102 del env[key]
103 env.update(oldenv)
104 if hasattr(sys, 'frozen'):
105 del sys.frozen
106 if os.name == 'nt':
107 (wreg.OpenKey, wreg.QueryValueEx,) = platformstuff
108
109 # Build decorator that uses the setup_environment/setup_environment
110 with_enivronment = with_setup(setup_environment, teardown_environment)
111
112
113 #
114 # Tests for get_home_dir
115 #
116
117 @skip_if_not_win32
118 @with_enivronment
119 def test_get_home_dir_1():
120 """Testcase for py2exe logic, un-compressed lib
121 """
122 sys.frozen = True
123
124 #fake filename for IPython.__init__
125 IPython.__file__ = abspath(join(HOME_TEST_DIR, "Lib/IPython/__init__.py"))
126
127 home_dir = genutils.get_home_dir()
128 nt.assert_equal(home_dir, abspath(HOME_TEST_DIR))
129
130 @skip_if_not_win32
131 @with_enivronment
132 def test_get_home_dir_2():
133 """Testcase for py2exe logic, compressed lib
134 """
135 sys.frozen = True
136 #fake filename for IPython.__init__
137 IPython.__file__ = abspath(join(HOME_TEST_DIR, "Library.zip/IPython/__init__.py")).lower()
138
139 home_dir = genutils.get_home_dir()
140 nt.assert_equal(home_dir, abspath(HOME_TEST_DIR).lower())
141
142 @with_enivronment
143 def test_get_home_dir_3():
144 """Testcase $HOME is set, then use its value as home directory."""
145 env["HOME"] = HOME_TEST_DIR
146 home_dir = genutils.get_home_dir()
147 nt.assert_equal(home_dir, env["HOME"])
148
149 @with_enivronment
150 def test_get_home_dir_4():
151 """Testcase $HOME is not set, os=='poix'.
152 This should fail with HomeDirError"""
153
154 os.name = 'posix'
155 if 'HOME' in env: del env['HOME']
156 nt.assert_raises(genutils.HomeDirError, genutils.get_home_dir)
157
158 @skip_if_not_win32
159 @with_enivronment
160 def test_get_home_dir_5():
161 """Testcase $HOME is not set, os=='nt'
162 env['HOMEDRIVE'],env['HOMEPATH'] points to path."""
163
164 os.name = 'nt'
165 if 'HOME' in env: del env['HOME']
166 env['HOMEDRIVE'], env['HOMEPATH'] = os.path.splitdrive(HOME_TEST_DIR)
19
167
168 home_dir = genutils.get_home_dir()
169 nt.assert_equal(home_dir, abspath(HOME_TEST_DIR))
170
171 @skip_if_not_win32
172 @with_enivronment
173 def test_get_home_dir_6():
174 """Testcase $HOME is not set, os=='nt'
175 env['HOMEDRIVE'],env['HOMEPATH'] do not point to path.
176 env['USERPROFILE'] points to path
177 """
178
179 os.name = 'nt'
180 if 'HOME' in env: del env['HOME']
181 env['HOMEDRIVE'], env['HOMEPATH'] = os.path.abspath(TEST_FILE_PATH), "DOES NOT EXIST"
182 env["USERPROFILE"] = abspath(HOME_TEST_DIR)
183
184 home_dir = genutils.get_home_dir()
185 nt.assert_equal(home_dir, abspath(HOME_TEST_DIR))
186
187 # Should we stub wreg fully so we can run the test on all platforms?
188 @skip_if_not_win32
189 @with_enivronment
190 def test_get_home_dir_7():
191 """Testcase $HOME is not set, os=='nt'
192 env['HOMEDRIVE'],env['HOMEPATH'], env['USERPROFILE'] missing
193 """
194 os.name = 'nt'
195 if 'HOME' in env: del env['HOME']
196 if 'HOMEDRIVE' in env: del env['HOMEDRIVE']
197
198 #Stub windows registry functions
199 def OpenKey(x, y):
200 class key:
201 def Close(self):
202 pass
203 return key()
204 def QueryValueEx(x, y):
205 return [abspath(HOME_TEST_DIR)]
206
207 wreg.OpenKey = OpenKey
208 wreg.QueryValueEx = QueryValueEx
20
209
21 def test_get_home_dir():
22 """Make sure we can get the home directory."""
23 home_dir = genutils.get_home_dir()
210 home_dir = genutils.get_home_dir()
211 nt.assert_equal(home_dir, abspath(HOME_TEST_DIR))
212
213
214 #
215 # Tests for get_ipython_dir
216 #
217
218 @with_enivronment
219 def test_get_ipython_dir_1():
220 """test_get_ipython_dir_1, Testcase to see if we can call get_ipython_dir without Exceptions."""
221 env['IPYTHONDIR'] = "someplace/.ipython"
222 ipdir = genutils.get_ipython_dir()
223 nt.assert_equal(ipdir, os.path.abspath("someplace/.ipython"))
24
224
25 def test_get_ipython_dir():
225
26 """Make sure we can get the ipython directory."""
226 @with_enivronment
227 def test_get_ipython_dir_2():
228 """test_get_ipython_dir_2, Testcase to see if we can call get_ipython_dir without Exceptions."""
229 genutils.get_home_dir = lambda : "someplace"
230 os.name = "posix"
231 ipdir = genutils.get_ipython_dir()
232 nt.assert_equal(ipdir, os.path.abspath(os.path.join("someplace", ".ipython")))
233
234 @with_enivronment
235 def test_get_ipython_dir_3():
236 """test_get_ipython_dir_3, Testcase to see if we can call get_ipython_dir without Exceptions."""
237 genutils.get_home_dir = lambda : "someplace"
238 os.name = "nt"
27 ipdir = genutils.get_ipython_dir()
239 ipdir = genutils.get_ipython_dir()
240 nt.assert_equal(ipdir, os.path.abspath(os.path.join("someplace", "_ipython")))
241
242
243 #
244 # Tests for get_security_dir
245 #
28
246
247 @with_enivronment
29 def test_get_security_dir():
248 def test_get_security_dir():
30 """Make sure we can get the ipython/security directory."""
249 """Testcase to see if we can call get_security_dir without Exceptions."""
31 sdir = genutils.get_security_dir()
250 sdir = genutils.get_security_dir()
32 No newline at end of file
251
252
253 #
254 # Tests for popkey
255 #
256
257 def test_popkey_1():
258 """test_popkey_1, Basic usage test of popkey
259 """
260 dct = dict(a=1, b=2, c=3)
261 nt.assert_equal(genutils.popkey(dct, "a"), 1)
262 nt.assert_equal(dct, dict(b=2, c=3))
263 nt.assert_equal(genutils.popkey(dct, "b"), 2)
264 nt.assert_equal(dct, dict(c=3))
265 nt.assert_equal(genutils.popkey(dct, "c"), 3)
266 nt.assert_equal(dct, dict())
267
268 def test_popkey_2():
269 """test_popkey_2, Test to see that popkey of non occuring keys
270 generates a KeyError exception
271 """
272 dct = dict(a=1, b=2, c=3)
273 nt.assert_raises(KeyError, genutils.popkey, dct, "d")
274
275 def test_popkey_3():
276 """test_popkey_3, Tests to see that popkey calls returns the correct value
277 and that the key/value was removed from the dict.
278 """
279 dct = dict(a=1, b=2, c=3)
280 nt.assert_equal(genutils.popkey(dct, "A", 13), 13)
281 nt.assert_equal(dct, dict(a=1, b=2, c=3))
282 nt.assert_equal(genutils.popkey(dct, "B", 14), 14)
283 nt.assert_equal(dct, dict(a=1, b=2, c=3))
284 nt.assert_equal(genutils.popkey(dct, "C", 15), 15)
285 nt.assert_equal(dct, dict(a=1, b=2, c=3))
286 nt.assert_equal(genutils.popkey(dct, "a"), 1)
287 nt.assert_equal(dct, dict(b=2, c=3))
288 nt.assert_equal(genutils.popkey(dct, "b"), 2)
289 nt.assert_equal(dct, dict(c=3))
290 nt.assert_equal(genutils.popkey(dct, "c"), 3)
291 nt.assert_equal(dct, dict())
@@ -303,6 +303,19 Most of the release process is automated by the :file:`release` script in the
303
303
304 #. Celebrate!
304 #. Celebrate!
305
305
306 Porting to 3.0
307 ==============
308 There are no definite plans for porting of IPython to python 3. The major
309 issue is the dependency on twisted framework for the networking/threading
310 stuff. It is possible that it the traditional IPython interactive console
311 could be ported more easily since it has no such dependency. Here are a few
312 things that will need to be considered when doing such a port especially
313 if we want to have a codebase that works directly on both 2.x and 3.x.
314
315 1. The syntax for exceptions changed (PEP 3110). The old
316 `except exc, var` changed to `except exc as var`. At last
317 count there was 78 occurences of this usage in the codebase
318
306 .. [Bazaar] Bazaar. http://bazaar-vcs.org/
319 .. [Bazaar] Bazaar. http://bazaar-vcs.org/
307 .. [Launchpad] Launchpad. http://www.launchpad.net/ipython
320 .. [Launchpad] Launchpad. http://www.launchpad.net/ipython
308 .. [reStructuredText] reStructuredText. http://docutils.sourceforge.net/rst.html
321 .. [reStructuredText] reStructuredText. http://docutils.sourceforge.net/rst.html
General Comments 0
You need to be logged in to leave comments. Login now