Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid triggering extra logic in IPython.paths.get_ipython_dir when performing migration #118

Merged
merged 1 commit into from
Oct 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions jupyter_core/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,9 @@ def migrate_config(self):
return

from .migrate import get_ipython_dir, migrate

ipdir = get_ipython_dir()

# No IPython dir, nothing to migrate
if not os.path.exists(ipdir):
if not os.path.exists(get_ipython_dir()):
return

migrate()
Expand Down
24 changes: 15 additions & 9 deletions jupyter_core/migrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,6 @@
from traitlets.log import get_logger

from .utils import ensure_dir_exists
try:
from IPython.paths import get_ipython_dir
except ImportError:
# IPython < 4
try:
from IPython.utils.path import get_ipython_dir
except ImportError:
def get_ipython_dir():
return os.environ.get('IPYTHONDIR', os.path.expanduser('~/.ipython'))

from .paths import jupyter_config_dir, jupyter_data_dir
from .application import JupyterApp
Expand Down Expand Up @@ -72,6 +63,21 @@ def get_ipython_dir():
regex(r'\bIPython\.nbconvert\b'): 'nbconvert',
}


def get_ipython_dir():
"""Return the IPython directory location.

Not imported from IPython because the IPython implementation
ensures that a writable directory exists,
creating a temporary directory if not.
We don't want to trigger that when checking if migration should happen.

We only need to support the IPython < 4 behavior for migration,
so importing for forward-compatibility and edge cases is not important.
"""
return os.environ.get('IPYTHONDIR', os.path.expanduser('~/.ipython'))


def migrate_dir(src, dst):
"""Migrate a directory from src to dst"""
log = get_logger()
Expand Down