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

Add opt-in support for XDG_CONFIG_HOME, XDG_DATA_HOME #186

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 26 additions & 12 deletions jupyter_core/paths.py
Expand Up @@ -53,7 +53,8 @@ def _mkdtemp_once(name):
def jupyter_config_dir():
"""Get the Jupyter config directory for this platform and user.

Returns JUPYTER_CONFIG_DIR if defined, else ~/.jupyter
Returns the first valid path from JUPYTER_CONFIG_DIR if defined, ~/.jupyter
if it exists, and XDG_CONFIG_HOME if defined, falling back to ~/.jupyter.
"""

env = os.environ
Expand All @@ -65,8 +66,16 @@ def jupyter_config_dir():
if env.get('JUPYTER_CONFIG_DIR'):
return env['JUPYTER_CONFIG_DIR']

return pjoin(home_dir, '.jupyter')
default = pjoin(home_dir, '.jupyter')
xdg = env.get('XDG_CONFIG_HOME')

# Check XDG_CONFIG_HOME if and only if .jupyter doesn't exist.
# This ensures that existing installs keep working until explicit opt-in.
if not exists(default) and xdg:
return pjoin(xdg, 'jupyter')

return default


def jupyter_data_dir():
"""Get the config directory for Jupyter data files.
Expand All @@ -81,21 +90,26 @@ def jupyter_data_dir():
return env['JUPYTER_DATA_DIR']

home = get_home_dir()
xdg = env.get('XDG_DATA_HOME')

if sys.platform == 'darwin':
return os.path.join(home, 'Library', 'Jupyter')
elif os.name == 'nt':
default = pjoin(home, 'Library', 'Jupyter')

# Use XDG_DATA_HOME if and only if the default doesn't exist.
if not exists(default) and xdg:
return pjoin(xdg, 'jupyter')
return default

if os.name == 'nt':
appdata = os.environ.get('APPDATA', None)
if appdata:
return pjoin(appdata, 'jupyter')
else:
return pjoin(jupyter_config_dir(), 'data')
else:
# Linux, non-OS X Unix, AIX, etc.
xdg = env.get("XDG_DATA_HOME", None)
if not xdg:
xdg = pjoin(home, '.local', 'share')
return pjoin(xdg, 'jupyter')
return pjoin(jupyter_config_dir(), 'data')

# Linux, non-OS X Unix, AIX, etc.
if not xdg:
xdg = pjoin(home, '.local', 'share')
return pjoin(xdg, 'jupyter')


def jupyter_runtime_dir():
Expand Down