##// END OF EJS Templates
Merge pull request #4457 from takluyver/ipython-dir-default...
Paul Ivanov -
r13488:dbb715d2 merge
parent child Browse files
Show More
@@ -0,0 +1,5 b''
1 * Previous versions of IPython on Linux would use the XDG config directory,
2 creating :file:`~/.config/ipython` by default. We have decided to go
3 back to :file:`~/.ipython` for consistency among systems. IPython will
4 issue a warning if it finds the XDG location, and will move it to the new
5 location if there isn't already a directory there.
@@ -45,10 +45,9 b' Usage'
45
45
46 This file is typically installed in the `IPYTHONDIR` directory, and there
46 This file is typically installed in the `IPYTHONDIR` directory, and there
47 is a separate configuration directory for each profile. The default profile
47 is a separate configuration directory for each profile. The default profile
48 directory will be located in $IPYTHONDIR/profile_default. For Linux users,
48 directory will be located in $IPYTHONDIR/profile_default. IPYTHONDIR
49 IPYTHONDIR defaults to `$HOME/.config/ipython`, and for other Unix systems
49 defaults to to `$HOME/.ipython`. For Windows users, $HOME resolves to
50 to `$HOME/.ipython`. For Windows users, $HOME resolves to C:\\Documents
50 C:\\Documents and Settings\\YourUserName in most instances.
51 and Settings\\YourUserName in most instances.
52
51
53 To initialize a profile with the default configuration file, do::
52 To initialize a profile with the default configuration file, do::
54
53
@@ -273,7 +273,6 b' def get_ipython_dir():'
273
273
274
274
275 ipdir_def = '.ipython'
275 ipdir_def = '.ipython'
276 xdg_def = 'ipython'
277
276
278 home_dir = get_home_dir()
277 home_dir = get_home_dir()
279 xdg_dir = get_xdg_dir()
278 xdg_dir = get_xdg_dir()
@@ -284,20 +283,21 b' def get_ipython_dir():'
284 'Please use IPYTHONDIR instead.')
283 'Please use IPYTHONDIR instead.')
285 ipdir = env.get('IPYTHONDIR', env.get('IPYTHON_DIR', None))
284 ipdir = env.get('IPYTHONDIR', env.get('IPYTHON_DIR', None))
286 if ipdir is None:
285 if ipdir is None:
287 # not set explicitly, use XDG_CONFIG_HOME or HOME
286 # not set explicitly, use ~/.ipython
288 home_ipdir = pjoin(home_dir, ipdir_def)
287 ipdir = pjoin(home_dir, ipdir_def)
289 if xdg_dir:
288 if xdg_dir:
290 # use XDG, as long as the user isn't already
289 # Several IPython versions (up to 1.x) defaulted to .config/ipython
291 # using $HOME/.ipython and *not* XDG/ipython
290 # on Linux. We have decided to go back to using .ipython everywhere
292
291 xdg_ipdir = pjoin(xdg_dir, 'ipython')
293 xdg_ipdir = pjoin(xdg_dir, xdg_def)
292
294
293 if _writable_dir(xdg_ipdir):
295 if _writable_dir(xdg_ipdir) or not _writable_dir(home_ipdir):
294 cu = compress_user
296 ipdir = xdg_ipdir
295 if os.path.exists(ipdir):
297
296 warnings.warn(('Ignoring {0} in favour of {1}. Remove {0} '
298 if ipdir is None:
297 'to get rid of this message').format(cu(xdg_ipdir), cu(ipdir)))
299 # not using XDG
298 else:
300 ipdir = home_ipdir
299 warnings.warn('Moving {0} to {1}'.format(cu(xdg_ipdir), cu(ipdir)))
300 os.rename(xdg_ipdir, ipdir)
301
301
302 ipdir = os.path.normpath(os.path.expanduser(ipdir))
302 ipdir = os.path.normpath(os.path.expanduser(ipdir))
303
303
@@ -14,10 +14,12 b''
14
14
15 from __future__ import with_statement
15 from __future__ import with_statement
16
16
17 import errno
17 import os
18 import os
18 import shutil
19 import shutil
19 import sys
20 import sys
20 import tempfile
21 import tempfile
22 import warnings
21 from contextlib import contextmanager
23 from contextlib import contextmanager
22
24
23 from os.path import join, abspath, split
25 from os.path import join, abspath, split
@@ -128,6 +130,15 b' def teardown_environment():'
128 # Build decorator that uses the setup_environment/setup_environment
130 # Build decorator that uses the setup_environment/setup_environment
129 with_environment = with_setup(setup_environment, teardown_environment)
131 with_environment = with_setup(setup_environment, teardown_environment)
130
132
133 @contextmanager
134 def patch_get_home_dir(dirpath):
135 orig_get_home_dir = path.get_home_dir
136 path.get_home_dir = lambda : dirpath
137 try:
138 yield
139 finally:
140 path.get_home_dir = orig_get_home_dir
141
131 @skip_if_not_win32
142 @skip_if_not_win32
132 @with_environment
143 @with_environment
133 def test_get_home_dir_1():
144 def test_get_home_dir_1():
@@ -225,74 +236,96 b' def test_get_ipython_dir_1():'
225 @with_environment
236 @with_environment
226 def test_get_ipython_dir_2():
237 def test_get_ipython_dir_2():
227 """test_get_ipython_dir_2, Testcase to see if we can call get_ipython_dir without Exceptions."""
238 """test_get_ipython_dir_2, Testcase to see if we can call get_ipython_dir without Exceptions."""
228 path.get_home_dir = lambda : "someplace"
239 with patch_get_home_dir('someplace'):
229 path.get_xdg_dir = lambda : None
240 path.get_xdg_dir = lambda : None
230 path._writable_dir = lambda path: True
241 path._writable_dir = lambda path: True
231 os.name = "posix"
242 os.name = "posix"
232 env.pop('IPYTHON_DIR', None)
243 env.pop('IPYTHON_DIR', None)
233 env.pop('IPYTHONDIR', None)
244 env.pop('IPYTHONDIR', None)
234 env.pop('XDG_CONFIG_HOME', None)
245 env.pop('XDG_CONFIG_HOME', None)
235 ipdir = path.get_ipython_dir()
246 ipdir = path.get_ipython_dir()
236 nt.assert_equal(ipdir, os.path.join("someplace", ".ipython"))
247 nt.assert_equal(ipdir, os.path.join("someplace", ".ipython"))
237
248
238 @with_environment
249 @with_environment
239 def test_get_ipython_dir_3():
250 def test_get_ipython_dir_3():
240 """test_get_ipython_dir_3, use XDG if defined, and .ipython doesn't exist."""
251 """test_get_ipython_dir_3, move XDG if defined, and .ipython doesn't exist."""
241 path.get_home_dir = lambda : "someplace"
252 tmphome = TemporaryDirectory()
242 path._writable_dir = lambda path: True
253 try:
243 os.name = "posix"
254 with patch_get_home_dir(tmphome.name):
244 env.pop('IPYTHON_DIR', None)
255 os.name = "posix"
245 env.pop('IPYTHONDIR', None)
256 env.pop('IPYTHON_DIR', None)
246 env['XDG_CONFIG_HOME'] = XDG_TEST_DIR
257 env.pop('IPYTHONDIR', None)
247 ipdir = path.get_ipython_dir()
258 env['XDG_CONFIG_HOME'] = XDG_TEST_DIR
248 if sys.platform == "darwin":
259
249 expected = os.path.join("someplace", ".ipython")
260 with warnings.catch_warnings(record=True) as w:
250 else:
261 ipdir = path.get_ipython_dir()
251 expected = os.path.join(XDG_TEST_DIR, "ipython")
262
252 nt.assert_equal(ipdir, expected)
263 nt.assert_equal(ipdir, os.path.join(tmphome.name, ".ipython"))
264 if sys.platform != 'darwin':
265 nt.assert_equal(len(w), 1)
266 nt.assert_in('Moving', str(w[0]))
267 finally:
268 tmphome.cleanup()
253
269
254 @with_environment
270 @with_environment
255 def test_get_ipython_dir_4():
271 def test_get_ipython_dir_4():
256 """test_get_ipython_dir_4, use XDG if both exist."""
272 """test_get_ipython_dir_4, warn if XDG and home both exist."""
257 path.get_home_dir = lambda : HOME_TEST_DIR
273 with patch_get_home_dir(HOME_TEST_DIR):
258 os.name = "posix"
274 os.name = "posix"
259 env.pop('IPYTHON_DIR', None)
275 env.pop('IPYTHON_DIR', None)
260 env.pop('IPYTHONDIR', None)
276 env.pop('IPYTHONDIR', None)
261 env['XDG_CONFIG_HOME'] = XDG_TEST_DIR
277 env['XDG_CONFIG_HOME'] = XDG_TEST_DIR
262 ipdir = path.get_ipython_dir()
278 try:
263 if sys.platform == "darwin":
279 os.mkdir(os.path.join(XDG_TEST_DIR, 'ipython'))
264 expected = os.path.join(HOME_TEST_DIR, ".ipython")
280 except OSError as e:
265 else:
281 if e.errno != errno.EEXIST:
266 expected = os.path.join(XDG_TEST_DIR, "ipython")
282 raise
267 nt.assert_equal(ipdir, expected)
283
284 with warnings.catch_warnings(record=True) as w:
285 ipdir = path.get_ipython_dir()
286
287 nt.assert_equal(ipdir, os.path.join(HOME_TEST_DIR, ".ipython"))
288 if sys.platform != 'darwin':
289 nt.assert_equal(len(w), 1)
290 nt.assert_in('Ignoring', str(w[0]))
268
291
269 @with_environment
292 @with_environment
270 def test_get_ipython_dir_5():
293 def test_get_ipython_dir_5():
271 """test_get_ipython_dir_5, use .ipython if exists and XDG defined, but doesn't exist."""
294 """test_get_ipython_dir_5, use .ipython if exists and XDG defined, but doesn't exist."""
272 path.get_home_dir = lambda : HOME_TEST_DIR
295 with patch_get_home_dir(HOME_TEST_DIR):
273 os.name = "posix"
296 os.name = "posix"
274 env.pop('IPYTHON_DIR', None)
297 env.pop('IPYTHON_DIR', None)
275 env.pop('IPYTHONDIR', None)
298 env.pop('IPYTHONDIR', None)
276 env['XDG_CONFIG_HOME'] = XDG_TEST_DIR
299 env['XDG_CONFIG_HOME'] = XDG_TEST_DIR
277 os.rmdir(os.path.join(XDG_TEST_DIR, 'ipython'))
300 try:
278 ipdir = path.get_ipython_dir()
301 os.rmdir(os.path.join(XDG_TEST_DIR, 'ipython'))
279 nt.assert_equal(ipdir, IP_TEST_DIR)
302 except OSError as e:
303 if e.errno != errno.ENOENT:
304 raise
305 ipdir = path.get_ipython_dir()
306 nt.assert_equal(ipdir, IP_TEST_DIR)
280
307
281 @with_environment
308 @with_environment
282 def test_get_ipython_dir_6():
309 def test_get_ipython_dir_6():
283 """test_get_ipython_dir_6, use XDG if defined and neither exist."""
310 """test_get_ipython_dir_6, use home over XDG if defined and neither exist."""
284 xdg = os.path.join(HOME_TEST_DIR, 'somexdg')
311 xdg = os.path.join(HOME_TEST_DIR, 'somexdg')
285 os.mkdir(xdg)
312 os.mkdir(xdg)
286 shutil.rmtree(os.path.join(HOME_TEST_DIR, '.ipython'))
313 shutil.rmtree(os.path.join(HOME_TEST_DIR, '.ipython'))
287 path.get_home_dir = lambda : HOME_TEST_DIR
314 with patch_get_home_dir(HOME_TEST_DIR):
288 path.get_xdg_dir = lambda : xdg
315 orig_get_xdg_dir = path.get_xdg_dir
289 os.name = "posix"
316 path.get_xdg_dir = lambda : xdg
290 env.pop('IPYTHON_DIR', None)
317 try:
291 env.pop('IPYTHONDIR', None)
318 os.name = "posix"
292 env.pop('XDG_CONFIG_HOME', None)
319 env.pop('IPYTHON_DIR', None)
293 xdg_ipdir = os.path.join(xdg, "ipython")
320 env.pop('IPYTHONDIR', None)
294 ipdir = path.get_ipython_dir()
321 env.pop('XDG_CONFIG_HOME', None)
295 nt.assert_equal(ipdir, xdg_ipdir)
322 with warnings.catch_warnings(record=True) as w:
323 ipdir = path.get_ipython_dir()
324
325 nt.assert_equal(ipdir, os.path.join(HOME_TEST_DIR, '.ipython'))
326 nt.assert_equal(len(w), 0)
327 finally:
328 path.get_xdg_dir = orig_get_xdg_dir
296
329
297 @with_environment
330 @with_environment
298 def test_get_ipython_dir_7():
331 def test_get_ipython_dir_7():
@@ -45,8 +45,7 b" or 'ipython \\-\\-help\\-all' for all available command\\(hyline options."
45 \fIIPYTHONDIR\fR
45 \fIIPYTHONDIR\fR
46 .RS 4
46 .RS 4
47 This is the location where IPython stores all its configuration files. The default
47 This is the location where IPython stores all its configuration files. The default
48 on most platforms is $HOME/.ipython, but on Linux IPython respects the XDG config
48 is $HOME/.ipython if IPYTHONDIR is not defined.
49 specification, which will put IPYTHONDIR in $HOME/.config/ipython by default.
50
49
51 You can see the computed value of IPYTHONDIR with `ipython locate`.
50 You can see the computed value of IPYTHONDIR with `ipython locate`.
52
51
@@ -12,8 +12,7 b' Outdated configuration information that might still be useful'
12 This section will help you set various things in your environment for
12 This section will help you set various things in your environment for
13 your IPython sessions to be as efficient as possible. All of IPython's
13 your IPython sessions to be as efficient as possible. All of IPython's
14 configuration information, along with several example files, is stored
14 configuration information, along with several example files, is stored
15 in a directory named by default $HOME/.config/ipython if $HOME/.config
15 in a directory named by default $HOME/.ipython. You can change this by
16 exists (Linux), or $HOME/.ipython as a secondary default. You can change this by
17 defining the environment variable IPYTHONDIR, or at runtime with the
16 defining the environment variable IPYTHONDIR, or at runtime with the
18 command line option -ipythondir.
17 command line option -ipythondir.
19
18
@@ -270,21 +270,17 b' following algorithm:'
270
270
271 * If not, the value returned by :func:`IPython.utils.path.get_ipython_dir`
271 * If not, the value returned by :func:`IPython.utils.path.get_ipython_dir`
272 is used. This function will first look at the :envvar:`IPYTHONDIR`
272 is used. This function will first look at the :envvar:`IPYTHONDIR`
273 environment variable and then default to a platform-specific default.
273 environment variable and then default to :file:`~/.ipython`.
274 Historical support for the :envvar:`IPYTHON_DIR` environment variable will
274 Historical support for the :envvar:`IPYTHON_DIR` environment variable will
275 be removed in a future release.
275 be removed in a future release.
276
276
277 On posix systems (Linux, Unix, etc.), IPython respects the ``$XDG_CONFIG_HOME``
277 For most users, the configuration directory will be :file:`~/.ipython`.
278 part of the `XDG Base Directory`_ specification. If ``$XDG_CONFIG_HOME`` is
279 defined and exists ( ``XDG_CONFIG_HOME`` has a default interpretation of
280 :file:`$HOME/.config`), then IPython's config directory will be located in
281 :file:`$XDG_CONFIG_HOME/ipython`. If users still have an IPython directory
282 in :file:`$HOME/.ipython`, then that will be used. in preference to the
283 system default.
284
278
285 For most users, the default value will simply be something like
279 Previous versions of IPython on Linux would use the XDG config directory,
286 :file:`$HOME/.config/ipython` on Linux, or :file:`$HOME/.ipython`
280 creating :file:`~/.config/ipython` by default. We have decided to go
287 elsewhere.
281 back to :file:`~/.ipython` for consistency among systems. IPython will
282 issue a warning if it finds the XDG location, and will move it to the new
283 location if there isn't already a directory there.
288
284
289 Once the location of the IPython directory has been determined, you need to know
285 Once the location of the IPython directory has been determined, you need to know
290 which profile you are using. For users with a single configuration, this will
286 which profile you are using. For users with a single configuration, this will
@@ -531,5 +527,3 b' Here are the main requirements we wanted our configuration system to have:'
531 dynamic language and you don't always know everything that needs to be
527 dynamic language and you don't always know everything that needs to be
532 configured when a program starts.
528 configured when a program starts.
533
529
534
535 .. _`XDG Base Directory`: http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
@@ -26,10 +26,10 b' the command line, simply because they are not practical here. Look into'
26 your configuration files for details on those. There are separate configuration
26 your configuration files for details on those. There are separate configuration
27 files for each profile, and the files look like "ipython_config.py" or
27 files for each profile, and the files look like "ipython_config.py" or
28 "ipython_config_<frontendname>.py". Profile directories look like
28 "ipython_config_<frontendname>.py". Profile directories look like
29 "profile_profilename" and are typically installed in the IPYTHONDIR directory.
29 "profile_profilename" and are typically installed in the IPYTHONDIR directory,
30 For Linux users, this will be $HOME/.config/ipython, and for other users it
30 which defaults to :file:`$HOME/.ipython`. For Windows users, :envvar:`HOME`
31 will be $HOME/.ipython. For Windows users, $HOME resolves to C:\\Documents and
31 resolves to :file:`C:\\Documents and Settings\\YourUserName` in most
32 Settings\\YourUserName in most instances.
32 instances.
33
33
34
34
35 Eventloop integration
35 Eventloop integration
@@ -181,8 +181,7 b' Configuration'
181 Much of IPython can be tweaked through :ref:`configuration <config_overview>`.
181 Much of IPython can be tweaked through :ref:`configuration <config_overview>`.
182 To get started, use the command ``ipython profile create`` to produce the
182 To get started, use the command ``ipython profile create`` to produce the
183 default config files. These will be placed in
183 default config files. These will be placed in
184 :file:`~/.ipython/profile_default` or
184 :file:`~/.ipython/profile_default`, and contain comments explaining
185 :file:`~/.config/ipython/profile_default`, and contain comments explaining
186 what the various options do.
185 what the various options do.
187
186
188 Profiles allow you to use IPython for different tasks, keeping separate config
187 Profiles allow you to use IPython for different tasks, keeping separate config
@@ -627,7 +627,7 b' the engines.'
627 .. note::
627 .. note::
628
628
629 The log output of ipcontroller above shows you where the json files were written.
629 The log output of ipcontroller above shows you where the json files were written.
630 They will be in :file:`~/.ipython` (or :file:`~/.config/ipython`) under
630 They will be in :file:`~/.ipython` under
631 :file:`profile_default/security/ipcontroller-engine.json`
631 :file:`profile_default/security/ipcontroller-engine.json`
632
632
633 3. start the engines, using the connection file::
633 3. start the engines, using the connection file::
@@ -644,7 +644,7 b' A couple of notes:'
644 then you need not specify its path directly, only the profile (assumes the path exists,
644 then you need not specify its path directly, only the profile (assumes the path exists,
645 otherwise you must create it first)::
645 otherwise you must create it first)::
646
646
647 [engine.host.n] $ scp controller.host:.ipython/profile_default/security/ipcontroller-engine.json ~/.config/ipython/profile_ssh/security/
647 [engine.host.n] $ scp controller.host:.ipython/profile_default/security/ipcontroller-engine.json ~/.ipython/profile_ssh/security/
648 [engine.host.n] $ ipengine --profile=ssh
648 [engine.host.n] $ ipengine --profile=ssh
649
649
650 Of course, if you fetch the file into the default profile, no arguments must be passed to
650 Of course, if you fetch the file into the default profile, no arguments must be passed to
General Comments 0
You need to be logged in to leave comments. Login now