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

Skip to content

Commit f256659

Browse files
committed
load bundled profiles without having to use 'profile create' or '--init'
This lets `ipython profile=math` etc. behave as expected on first use. *only* bundled config files, and not generated ones will be staged in this way. Extra tweak: ProfileDir.copy_config_file returns True on copy, False on no-op.
1 parent cc9aebe commit f256659

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

IPython/core/application.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
# Imports
2828
#-----------------------------------------------------------------------------
2929

30+
import glob
3031
import logging
3132
import os
3233
import shutil
@@ -254,8 +255,8 @@ def init_profile_dir(self):
254255
def init_config_files(self):
255256
"""[optionally] copy default config files into profile dir."""
256257
# copy config files
258+
path = self.builtin_profile_dir
257259
if self.copy_config_files:
258-
path = self.builtin_profile_dir
259260
src = self.profile
260261

261262
cfg = self.config_file_name
@@ -266,6 +267,19 @@ def init_config_files(self):
266267
self.profile_dir.copy_config_file(cfg, path=path, overwrite=self.overwrite)
267268
else:
268269
self.stage_default_config_file()
270+
else:
271+
# Still stage *bundled* config files, but not generated ones
272+
# This is necessary for `ipython profile=sympy` to load the profile
273+
# on the first go
274+
files = glob.glob(os.path.join(path, '*.py'))
275+
for fullpath in files:
276+
cfg = os.path.basename(fullpath)
277+
if self.profile_dir.copy_config_file(cfg, path=path, overwrite=False):
278+
# file was copied
279+
self.log.warn("Staging bundled %s from %s into %r"%(
280+
cfg, self.profile, self.profile_dir.location)
281+
)
282+
269283

270284
def stage_default_config_file(self):
271285
"""auto generate default config file, and stage it into the profile."""

IPython/core/profiledir.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,12 @@ def copy_config_file(self, config_file, path=None, overwrite=False):
123123
"""
124124
dst = os.path.join(self.location, config_file)
125125
if os.path.isfile(dst) and not overwrite:
126-
return
126+
return False
127127
if path is None:
128128
path = os.path.join(get_ipython_package_dir(), u'config', u'profile', u'default')
129129
src = os.path.join(path, config_file)
130130
shutil.copy(src, dst)
131+
return True
131132

132133
@classmethod
133134
def create_profile_dir(cls, profile_dir, config=None):

0 commit comments

Comments
 (0)