Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 69ea816

Browse files
committed
ipcluster, ipcontroller and ipengine now all call user_setup to make sure that the ipython dir exists. I also found some subtle bugs about how the various ipython directories were being handled. Now, all of these script call get_log_dir() and get_security_dir() to make sure that these sub-dirs of ipythondir exist as well.
1 parent ffa7707 commit 69ea816

7 files changed

Lines changed: 62 additions & 25 deletions

File tree

IPython/genutils.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1007,7 +1007,17 @@ def get_security_dir():
10071007
else:
10081008
os.chmod(security_dir, 0700)
10091009
return security_dir
1010-
1010+
1011+
def get_log_dir():
1012+
"""Get the IPython log directory.
1013+
1014+
If the log directory does not exist, it is created.
1015+
"""
1016+
log_dir = os.path.join(get_ipython_dir(), 'log')
1017+
if not os.path.isdir(log_dir):
1018+
os.mkdir(log_dir, 0777)
1019+
return log_dir
1020+
10111021
#****************************************************************************
10121022
# strings and text
10131023

IPython/kernel/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@
1515
deferred/Twisted using clients.
1616
"""
1717
__docformat__ = "restructuredtext en"
18-
#-------------------------------------------------------------------------------
18+
#-----------------------------------------------------------------------------
1919
# Copyright (C) 2008 The IPython Development Team
2020
#
2121
# Distributed under the terms of the BSD License. The full license is in
2222
# the file COPYING, distributed as part of this software.
23-
#-------------------------------------------------------------------------------
24-
23+
#-----------------------------------------------------------------------------

IPython/kernel/config/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
# Imports
1616
#-------------------------------------------------------------------------------
1717

18+
import os, sys
1819
from os.path import join as pjoin
1920

2021
from IPython.external.configobj import ConfigObj
@@ -23,6 +24,7 @@
2324

2425
default_kernel_config = ConfigObj()
2526

27+
# This will raise OSError if ipythondir doesn't exist.
2628
security_dir = get_security_dir()
2729

2830
#-------------------------------------------------------------------------------

IPython/kernel/scripts/ipcluster.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,21 @@
2929

3030
from IPython.external import argparse
3131
from IPython.external import Itpl
32-
from IPython.genutils import get_ipython_dir, num_cpus
32+
from IPython.genutils import get_ipython_dir, get_log_dir, get_security_dir
33+
from IPython.genutils import num_cpus
3334
from IPython.kernel.fcutil import have_crypto
35+
36+
# Create various ipython directories if they don't exist.
37+
# This must be done before IPython.kernel.config is imported.
38+
from IPython.iplib import user_setup
39+
if os.name == 'posix':
40+
rc_suffix = ''
41+
else:
42+
rc_suffix = '.ini'
43+
user_setup(get_ipython_dir(), rc_suffix, mode='install', interactive=False)
44+
get_log_dir()
45+
get_security_dir()
46+
3447
from IPython.kernel.config import config_manager as kernel_config_manager
3548
from IPython.kernel.error import SecurityError, FileTimeoutError
3649
from IPython.kernel.fcutil import have_crypto

IPython/kernel/scripts/ipcontroller.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,18 @@
3838
from IPython.kernel import controllerservice
3939
from IPython.kernel.fcutil import check_furl_file_security
4040

41+
# Create various ipython directories if they don't exist.
42+
# This must be done before IPython.kernel.config is imported.
43+
from IPython.iplib import user_setup
44+
from IPython.genutils import get_ipython_dir, get_log_dir, get_security_dir
45+
if os.name == 'posix':
46+
rc_suffix = ''
47+
else:
48+
rc_suffix = '.ini'
49+
user_setup(get_ipython_dir(), rc_suffix, mode='install', interactive=False)
50+
get_log_dir()
51+
get_security_dir()
52+
4153
from IPython.kernel.config import config_manager as kernel_config_manager
4254
from IPython.config.cutils import import_item
4355

@@ -116,7 +128,6 @@ def register(empty, ref, furl_file):
116128
# appears to other processes, the buffer has the flushed
117129
# and the file has been closed
118130
temp_furl_file = get_temp_furlfile(furl_file)
119-
log.msg(temp_furl_file)
120131
client_tub.registerReference(ref, furlFile=temp_furl_file)
121132
os.rename(temp_furl_file, furl_file)
122133

@@ -169,7 +180,6 @@ def register(empty, ref, furl_file):
169180
# appears to other processes, the buffer has the flushed
170181
# and the file has been closed
171182
temp_furl_file = get_temp_furlfile(furl_file)
172-
log.msg(temp_furl_file)
173183
engine_tub.registerReference(ref, furlFile=temp_furl_file)
174184
os.rename(temp_furl_file, furl_file)
175185

@@ -341,12 +351,6 @@ def init_config():
341351
dest="logfile",
342352
help="log file name (default is stdout)"
343353
)
344-
parser.add_option(
345-
"--ipythondir",
346-
type="string",
347-
dest="ipythondir",
348-
help="look for config files and profiles in this directory"
349-
)
350354
parser.add_option(
351355
"-r",
352356
action="store_true",
@@ -356,7 +360,6 @@ def init_config():
356360

357361
(options, args) = parser.parse_args()
358362

359-
kernel_config_manager.update_config_obj_from_default_file(options.ipythondir)
360363
config = kernel_config_manager.get_config_obj()
361364

362365
# Update with command line options

IPython/kernel/scripts/ipengine.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,19 @@
3333
from IPython.kernel.core.config import config_manager as core_config_manager
3434
from IPython.config.cutils import import_item
3535
from IPython.kernel.engineservice import EngineService
36+
37+
# Create various ipython directories if they don't exist.
38+
# This must be done before IPython.kernel.config is imported.
39+
from IPython.iplib import user_setup
40+
from IPython.genutils import get_ipython_dir, get_log_dir, get_security_dir
41+
if os.name == 'posix':
42+
rc_suffix = ''
43+
else:
44+
rc_suffix = '.ini'
45+
user_setup(get_ipython_dir(), rc_suffix, mode='install', interactive=False)
46+
get_log_dir()
47+
get_security_dir()
48+
3649
from IPython.kernel.config import config_manager as kernel_config_manager
3750
from IPython.kernel.engineconnector import EngineConnector
3851

@@ -148,18 +161,9 @@ def init_config():
148161
dest="logfile",
149162
help="log file name (default is stdout)"
150163
)
151-
parser.add_option(
152-
"--ipythondir",
153-
type="string",
154-
dest="ipythondir",
155-
help="look for config files and profiles in this directory"
156-
)
157164

158165
(options, args) = parser.parse_args()
159166

160-
kernel_config_manager.update_config_obj_from_default_file(options.ipythondir)
161-
core_config_manager.update_config_obj_from_default_file(options.ipythondir)
162-
163167
kernel_config = kernel_config_manager.get_config_obj()
164168
# Now override with command line options
165169
if options.furl_file is not None:

IPython/tests/test_genutils.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,6 @@ def QueryValueEx(x, y):
210210
home_dir = genutils.get_home_dir()
211211
nt.assert_equal(home_dir, abspath(HOME_TEST_DIR))
212212

213-
214213
#
215214
# Tests for get_ipython_dir
216215
#
@@ -239,7 +238,6 @@ def test_get_ipython_dir_3():
239238
ipdir = genutils.get_ipython_dir()
240239
nt.assert_equal(ipdir, os.path.abspath(os.path.join("someplace", "_ipython")))
241240

242-
243241
#
244242
# Tests for get_security_dir
245243
#
@@ -249,6 +247,14 @@ def test_get_security_dir():
249247
"""Testcase to see if we can call get_security_dir without Exceptions."""
250248
sdir = genutils.get_security_dir()
251249

250+
#
251+
# Tests for get_log_dir
252+
#
253+
254+
@with_enivronment
255+
def test_get_log_dir():
256+
"""Testcase to see if we can call get_log_dir without Exceptions."""
257+
sdir = genutils.get_log_dir()
252258

253259
#
254260
# Tests for popkey

0 commit comments

Comments
 (0)