MCPcopy Index your code
hub / github.com/ipython/ipython / get_ipython_dir

Function get_ipython_dir

IPython/paths.py:19–72  ·  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

17
18
19def get_ipython_dir() -> str:
20 """Get the IPython directory for this platform and user.
21
22 This uses the logic in `get_home_dir` to find the home directory
23 and then adds .ipython to the end of the path.
24 """
25
26 env = os.environ
27 pjoin = os.path.join
28
29
30 ipdir_def = '.ipython'
31
32 home_dir = get_home_dir()
33 xdg_dir = get_xdg_dir()
34
35 ipdir = env.get("IPYTHONDIR", None)
36 if ipdir is None:
37 # not set explicitly, use ~/.ipython
38 ipdir = pjoin(home_dir, ipdir_def)
39 if xdg_dir:
40 # Several IPython versions (up to 1.x) defaulted to .config/ipython
41 # on Linux. We have decided to go back to using .ipython everywhere
42 xdg_ipdir = pjoin(xdg_dir, 'ipython')
43
44 if _writable_dir(xdg_ipdir):
45 cu = compress_user
46 if os.path.exists(ipdir):
47 warn(('Ignoring {0} in favour of {1}. Remove {0} to '
48 'get rid of this message').format(cu(xdg_ipdir), cu(ipdir)))
49 elif os.path.islink(xdg_ipdir):
50 warn(('{0} is deprecated. Move link to {1} to '
51 'get rid of this message').format(cu(xdg_ipdir), cu(ipdir)))
52 else:
53 ipdir = xdg_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 else:
70 os.makedirs(ipdir, exist_ok=True)
71 assert isinstance(ipdir, str), "all path manipulation should be str(unicode), but are not."
72 return ipdir
73
74
75def get_ipython_cache_dir() -> str:

Callers 7

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.85
locate_profileFunction · 0.85

Calls 5

get_home_dirFunction · 0.90
get_xdg_dirFunction · 0.90
_writable_dirFunction · 0.90
getMethod · 0.80
formatMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…