MCPcopy Create free account
hub / github.com/ipython/ipython / get_ipython_dir

Function get_ipython_dir

IPython/paths.py:15–70  ·  view source on GitHub ↗

Get the IPython directory for this platform and user. This uses the logic in `get_home_dir` to find the home directory and then adds .ipython to the end of the path.

()

Source from the content-addressed store, hash-verified

13from IPython.utils import py3compat
14
15def get_ipython_dir() -> str:
16 """Get the IPython directory for this platform and user.
17
18 This uses the logic in `get_home_dir` to find the home directory
19 and then adds .ipython to the end of the path.
20 """
21
22 env = os.environ
23 pjoin = os.path.join
24
25
26 ipdir_def = '.ipython'
27
28 home_dir = get_home_dir()
29 xdg_dir = get_xdg_dir()
30
31 if 'IPYTHON_DIR' in env:
32 warn('The environment variable IPYTHON_DIR is deprecated since IPython 3.0. '
33 'Please use IPYTHONDIR instead.', DeprecationWarning)
34 ipdir = env.get('IPYTHONDIR', env.get('IPYTHON_DIR', None))
35 if ipdir is None:
36 # not set explicitly, use ~/.ipython
37 ipdir = pjoin(home_dir, ipdir_def)
38 if xdg_dir:
39 # Several IPython versions (up to 1.x) defaulted to .config/ipython
40 # on Linux. We have decided to go back to using .ipython everywhere
41 xdg_ipdir = pjoin(xdg_dir, 'ipython')
42
43 if _writable_dir(xdg_ipdir):
44 cu = compress_user
45 if os.path.exists(ipdir):
46 warn(('Ignoring {0} in favour of {1}. Remove {0} to '
47 'get rid of this message').format(cu(xdg_ipdir), cu(ipdir)))
48 elif os.path.islink(xdg_ipdir):
49 warn(('{0} is deprecated. Move link to {1} to '
50 'get rid of this message').format(cu(xdg_ipdir), cu(ipdir)))
51 else:
52 warn('Moving {0} to {1}'.format(cu(xdg_ipdir), cu(ipdir)))
53 shutil.move(xdg_ipdir, ipdir)
54
55 ipdir = os.path.normpath(os.path.expanduser(ipdir))
56
57 if os.path.exists(ipdir) and not _writable_dir(ipdir):
58 # ipdir exists, but is not writable
59 warn("IPython dir '{0}' is not a writable location,"
60 " using a temp directory.".format(ipdir))
61 ipdir = tempfile.mkdtemp()
62 elif not os.path.exists(ipdir):
63 parent = os.path.dirname(ipdir)
64 if not _writable_dir(parent):
65 # ipdir does not exist and parent isn't writable
66 warn("IPython parent '{0}' is not a writable location,"
67 " using a temp directory.".format(parent))
68 ipdir = tempfile.mkdtemp()
69 assert isinstance(ipdir, str), "all path manipulation should be str(unicode), but are not."
70 return ipdir
71
72

Callers 8

get_ipython_dirFunction · 0.90
load_default_configFunction · 0.90
load_subconfigMethod · 0.90
_ipython_dir_defaultMethod · 0.90
ProfileListClass · 0.90
init_ipython_dirMethod · 0.90
get_ipython_cache_dirFunction · 0.70
locate_profileFunction · 0.70

Calls 4

get_home_dirFunction · 0.90
get_xdg_dirFunction · 0.90
_writable_dirFunction · 0.90
formatMethod · 0.45

Tested by

no test coverage detected