From 654803d6af45c820876f342f22dfec9b675d6f63 Mon Sep 17 00:00:00 2001 From: Min RK Date: Thu, 26 Oct 2017 14:47:13 +0200 Subject: [PATCH] Avoid triggering extra logic in get_ipython_dir when performing migration IPython's get_ipython_dir always returns a writable directory that exists, creating an empty one if the default resolution doesn't find one. We don't want to trigger all of this when checking for old config files to migrate, so reimplement a simpler check. --- jupyter_core/application.py | 5 ++--- jupyter_core/migrate.py | 24 +++++++++++++++--------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/jupyter_core/application.py b/jupyter_core/application.py index 312850b..e3fcef7 100644 --- a/jupyter_core/application.py +++ b/jupyter_core/application.py @@ -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() diff --git a/jupyter_core/migrate.py b/jupyter_core/migrate.py index 16d4d7c..d8f9f4a 100644 --- a/jupyter_core/migrate.py +++ b/jupyter_core/migrate.py @@ -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 @@ -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()