##// END OF EJS Templates
More cleaning and enforcing of types....
Matthias Bussonnier -
Show More
@@ -70,7 +70,7 b' def get_ipython_dir() -> str:'
70 return ipdir
70 return ipdir
71
71
72
72
73 def get_ipython_cache_dir():
73 def get_ipython_cache_dir() -> str:
74 """Get the cache directory it is created if it does not exist."""
74 """Get the cache directory it is created if it does not exist."""
75 xdgdir = get_xdg_cache_dir()
75 xdgdir = get_xdg_cache_dir()
76 if xdgdir is None:
76 if xdgdir is None:
@@ -81,13 +81,14 b' def get_ipython_cache_dir():'
81 elif not _writable_dir(xdgdir):
81 elif not _writable_dir(xdgdir):
82 return get_ipython_dir()
82 return get_ipython_dir()
83
83
84 return py3compat.cast_unicode(ipdir, fs_encoding)
84 return ipdir
85
85
86
86
87 def get_ipython_package_dir():
87 def get_ipython_package_dir() -> str:
88 """Get the base directory where IPython itself is installed."""
88 """Get the base directory where IPython itself is installed."""
89 ipdir = os.path.dirname(IPython.__file__)
89 ipdir = os.path.dirname(IPython.__file__)
90 return py3compat.cast_unicode(ipdir, fs_encoding)
90 assert isinstance(ipdir, str)
91 return ipdir
91
92
92
93
93 def get_ipython_module_path(module_str):
94 def get_ipython_module_path(module_str):
@@ -169,7 +169,7 b' class HomeDirError(Exception):'
169 pass
169 pass
170
170
171
171
172 def get_home_dir(require_writable=False):
172 def get_home_dir(require_writable=False) -> str:
173 """Return the 'home' directory, as a unicode string.
173 """Return the 'home' directory, as a unicode string.
174
174
175 Uses os.path.expanduser('~'), and checks for writability.
175 Uses os.path.expanduser('~'), and checks for writability.
@@ -197,21 +197,18 b' def get_home_dir(require_writable=False):'
197 if not _writable_dir(homedir) and os.name == 'nt':
197 if not _writable_dir(homedir) and os.name == 'nt':
198 # expanduser failed, use the registry to get the 'My Documents' folder.
198 # expanduser failed, use the registry to get the 'My Documents' folder.
199 try:
199 try:
200 try:
200 import winreg as wreg
201 import winreg as wreg # Py 3
201 with wreg.OpenKey(
202 except ImportError:
203 import _winreg as wreg # Py 2
204 key = wreg.OpenKey(
205 wreg.HKEY_CURRENT_USER,
202 wreg.HKEY_CURRENT_USER,
206 r"Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders"
203 r"Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders"
207 )
204 ) as key:
208 homedir = wreg.QueryValueEx(key,'Personal')[0]
205 homedir = wreg.QueryValueEx(key,'Personal')[0]
209 key.Close()
210 except:
206 except:
211 pass
207 pass
212
208
213 if (not require_writable) or _writable_dir(homedir):
209 if (not require_writable) or _writable_dir(homedir):
214 return py3compat.cast_unicode(homedir, fs_encoding)
210 assert isinstance(homedir, str), "Homedir shoudl be unicode not bytes"
211 return homedir
215 else:
212 else:
216 raise HomeDirError('%s is not a writable dir, '
213 raise HomeDirError('%s is not a writable dir, '
217 'set $HOME environment variable to override' % homedir)
214 'set $HOME environment variable to override' % homedir)
General Comments 0
You need to be logged in to leave comments. Login now