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