Skip to content

Commit f5660f6

Browse files
authored
Merge pull request #222 from florianbussmann/windows-store-fix
Return canonical path when using %APPDATA% on NT
2 parents 2dc34f7 + d9195a7 commit f5660f6

File tree

3 files changed

+26
-28
lines changed

3 files changed

+26
-28
lines changed

jupyter_core/paths.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import errno
1515
import tempfile
1616
import warnings
17+
from pathlib import Path
1718

1819
from contextlib import contextmanager
1920

@@ -37,7 +38,7 @@ def get_home_dir():
3738
homedir = os.path.expanduser('~')
3839
# Next line will make things work even when /home/ is a symlink to
3940
# /usr/home as it is on FreeBSD, for example
40-
homedir = os.path.realpath(homedir)
41+
homedir = str(Path(homedir).resolve())
4142
return homedir
4243

4344
_dtemps = {}
@@ -90,7 +91,7 @@ def jupyter_data_dir():
9091
elif os.name == 'nt':
9192
appdata = os.environ.get('APPDATA', None)
9293
if appdata:
93-
return pjoin(appdata, 'jupyter')
94+
return str(Path(appdata, 'jupyter').resolve())
9495
else:
9596
return pjoin(jupyter_config_dir(), 'data')
9697
else:

jupyter_core/tests/mocking.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,3 @@ def __exit__(self, *args):
2929
patch.object(os, 'name', 'posix'),
3030
patch.object(sys, 'platform', 'linux2'),
3131
)
32-
33-
windows = MultiPatch(
34-
patch.object(os, 'name', 'nt'),
35-
patch.object(sys, 'platform', 'win32'),
36-
)

jupyter_core/tests/test_paths.py

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
secure_write, is_hidden, is_file_hidden
2020
)
2121

22-
from .mocking import darwin, windows, linux
22+
from .mocking import darwin, linux
2323

2424
pjoin = os.path.join
2525

@@ -36,8 +36,6 @@
3636
'XDG_RUNTIME_DIR': '',
3737
})
3838

39-
appdata = patch.dict('os.environ', {'APPDATA': 'appdata'})
40-
4139
no_config_env = patch.dict('os.environ', {
4240
'JUPYTER_CONFIG_DIR': '',
4341
'JUPYTER_DATA_DIR': '',
@@ -50,7 +48,7 @@
5048

5149

5250
def realpath(path):
53-
return os.path.realpath(os.path.expanduser(path))
51+
return os.path.abspath(os.path.realpath(os.path.expanduser(path)))
5452

5553
home_jupyter = realpath('~/.jupyter')
5654

@@ -65,6 +63,7 @@ def test_envset():
6563
assert not paths.envset(f"FOO_{v}")
6664
assert not paths.envset("THIS_VARIABLE_SHOULD_NOT_BE_SET")
6765

66+
@pytest.mark.skipif(sys.platform == "win32", reason="does not run on windows")
6867
def test_config_dir_darwin():
6968
with darwin, no_config_env:
7069
config = jupyter_config_dir()
@@ -74,23 +73,24 @@ def test_config_dir_darwin():
7473
config = jupyter_config_dir()
7574
assert config == jupyter_config_env
7675

77-
76+
@pytest.mark.skipif(sys.platform != "win32", reason="only run on windows")
7877
def test_config_dir_windows():
79-
with windows, no_config_env:
78+
with no_config_env:
8079
config = jupyter_config_dir()
8180
assert config == home_jupyter
8281

83-
with windows, config_env:
82+
with config_env:
8483
config = jupyter_config_dir()
8584
assert config == jupyter_config_env
8685

8786

87+
@pytest.mark.skipif(sys.platform == "win32", reason="does not run on windows")
8888
def test_config_dir_linux():
89-
with windows, no_config_env:
89+
with linux, no_config_env:
9090
config = jupyter_config_dir()
9191
assert config == home_jupyter
9292

93-
with windows, config_env:
93+
with linux, config_env:
9494
config = jupyter_config_dir()
9595
assert config == jupyter_config_env
9696

@@ -102,6 +102,7 @@ def test_data_dir_env():
102102
assert data == data_env
103103

104104

105+
@pytest.mark.skipif(sys.platform == "win32", reason="does not run on windows")
105106
def test_data_dir_darwin():
106107
with darwin:
107108
data = jupyter_data_dir()
@@ -112,18 +113,18 @@ def test_data_dir_darwin():
112113
data = jupyter_data_dir()
113114
assert data == realpath('~/Library/Jupyter')
114115

115-
116+
@pytest.mark.skipif(sys.platform != "win32", reason="only run on windows")
116117
def test_data_dir_windows():
117-
with windows, appdata:
118-
data = jupyter_data_dir()
119-
assert data == pjoin('appdata', 'jupyter')
118+
data = jupyter_data_dir()
119+
assert data == realpath(pjoin(os.environ.get('APPDATA', None), 'jupyter'))
120120

121-
with windows, appdata, xdg:
121+
with xdg:
122122
# windows should ignore xdg
123123
data = jupyter_data_dir()
124-
assert data == pjoin('appdata', 'jupyter')
124+
assert data == realpath(pjoin(os.environ.get('APPDATA', None), 'jupyter'))
125125

126126

127+
@pytest.mark.skipif(sys.platform == "win32", reason="does not run on windows")
127128
def test_data_dir_linux():
128129
with linux, no_xdg:
129130
data = jupyter_data_dir()
@@ -141,6 +142,7 @@ def test_runtime_dir_env():
141142
assert runtime == rtd_env
142143

143144

145+
@pytest.mark.skipif(sys.platform == "win32", reason="does not run on windows")
144146
def test_runtime_dir_darwin():
145147
with darwin:
146148
runtime = jupyter_runtime_dir()
@@ -151,18 +153,18 @@ def test_runtime_dir_darwin():
151153
runtime = jupyter_runtime_dir()
152154
assert runtime == realpath('~/Library/Jupyter/runtime')
153155

154-
156+
@pytest.mark.skipif(sys.platform != "win32", reason="only run on windows")
155157
def test_runtime_dir_windows():
156-
with windows, appdata:
157-
runtime = jupyter_runtime_dir()
158-
assert runtime == pjoin('appdata', 'jupyter', 'runtime')
158+
runtime = jupyter_runtime_dir()
159+
assert runtime == realpath(pjoin(os.environ.get('APPDATA', None), 'jupyter', 'runtime'))
159160

160-
with windows, appdata, xdg:
161+
with xdg:
161162
# windows should ignore xdg
162163
runtime = jupyter_runtime_dir()
163-
assert runtime == pjoin('appdata', 'jupyter', 'runtime')
164+
assert runtime == realpath(pjoin(os.environ.get('APPDATA', None), 'jupyter', 'runtime'))
164165

165166

167+
@pytest.mark.skipif(sys.platform == "win32", reason="does not run on windows")
166168
def test_runtime_dir_linux():
167169
with linux, no_xdg:
168170
runtime = jupyter_runtime_dir()

0 commit comments

Comments
 (0)