Skip to content

Commit

Permalink
Trac #15972: IPython ProfileDirError if IPython was never run
Browse files Browse the repository at this point in the history
The following fails if IPython was never run before:
{{{
./sage -t src/sage/misc/ascii_art.py
**********************************************************************
File "src/sage/misc/ascii_art.py", line 42, in sage.misc.ascii_art
Failed example:
    shell = get_test_shell()
Exception raised:
    Traceback (most recent call last):
      File "/usr/local/src/sage-config/local/lib/python2.7/site-
packages/sage/doctest/forker.py", line 480, in _run
        self.execute(example, compiled, test.globs)
      File "/usr/local/src/sage-config/local/lib/python2.7/site-
packages/sage/doctest/forker.py", line 839, in execute
        exec compiled in globs
      File "<doctest sage.misc.ascii_art[6]>", line 1, in <module>
        shell = get_test_shell()
      File "/usr/local/src/sage-config/local/lib/python2.7/site-
packages/sage/misc/interpreter.py", line 549, in get_test_shell
        app.initialize(argv=[])
      File "<string>", line 2, in initialize
      File "/usr/local/src/sage-config/local/lib/python2.7/site-
packages/IPython/config/application.py", line 89, in catch_config_error
        return method(app, *args, **kwargs)
      File "/usr/local/src/sage-config/local/lib/python2.7/site-
packages/IPython/terminal/ipapp.py", line 312, in initialize
        super(TerminalIPythonApp, self).initialize(argv)
      File "<string>", line 2, in initialize
      File "/usr/local/src/sage-config/local/lib/python2.7/site-
packages/IPython/config/application.py", line 89, in catch_config_error
        return method(app, *args, **kwargs)
      File "/usr/local/src/sage-config/local/lib/python2.7/site-
packages/IPython/core/application.py", line 381, in initialize
        self.load_config_file()
      File "/usr/local/src/sage-config/local/lib/python2.7/site-
packages/sage/misc/interpreter.py", line 626, in load_config_file
        get_ipython_dir(), 'sage').location
      File "/usr/local/src/sage-config/local/lib/python2.7/site-
packages/IPython/core/profiledir.py", line 242, in
find_profile_dir_by_name
        raise ProfileDirError('Profile directory not found in paths: %s'
% dirname)
    ProfileDirError: Profile directory not found in paths: profile_sage
**********************************************************************
}}}

Running `./sage` once fixes this problem but the following always fails:
{{{
./sage --nodotsage -t src/sage/misc/ascii_art.py
}}}

URL: http://trac.sagemath.org/15972
Reported by: jdemeyer
Ticket author(s): John Palmieri
Reviewer(s): Volker Braun
  • Loading branch information
Release Manager authored and vbraun committed Mar 31, 2014
2 parents e046d7a + 53a7d7f commit 47619bc
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/sage/misc/interpreter.py
Expand Up @@ -614,17 +614,35 @@ def __init__(self, **kwargs):


def load_config_file(self, *args, **kwds):
"""
TESTS:
Test that :trac:`15972` has been fixed::
sage: from sage.misc.temporary_file import tmp_dir
sage: from sage.misc.interpreter import SageTerminalApp
sage: d = tmp_dir()
sage: IPYTHONDIR = os.environ['IPYTHONDIR']
sage: os.environ['IPYTHONDIR'] = d
sage: SageTerminalApp().load_config_file()
sage: os.environ['IPYTHONDIR'] = IPYTHONDIR
"""
from IPython.config.loader import PyFileConfigLoader, ConfigFileNotFound
from IPython.core.profiledir import ProfileDir
from IPython.core.profiledir import ProfileDir, ProfileDirError
from IPython.utils.path import get_ipython_dir

conf = Config()
conf._merge(DEFAULT_SAGE_CONFIG)
conf._merge(self.command_line_config)

# Get user config.
sage_profile_dir = ProfileDir.find_profile_dir_by_name(
get_ipython_dir(), 'sage').location
try:
sage_profile_dir = ProfileDir.find_profile_dir_by_name(
get_ipython_dir(), 'sage').location
except ProfileDirError:
d = ProfileDir.create_profile_dir_by_name(
get_ipython_dir(), 'sage')
sage_profile_dir = d.location
try:
cl = PyFileConfigLoader('ipython_config.py', sage_profile_dir)
conf._merge(cl.load_config())
Expand Down

0 comments on commit 47619bc

Please sign in to comment.