def get_ipython_dir():
env = os.environ<EOL>pjoin = os.path.join<EOL>ipdir_def = '<STR_LIT>'<EOL>xdg_def = '<STR_LIT>'<EOL>home_dir = get_home_dir()<EOL>xdg_dir = get_xdg_dir()<EOL>if '<STR_LIT>' in env:<EOL><INDENT>warnings.warn('<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT>ipdir = env.get('<STR_LIT>', env.get('<STR_LIT>', None))<EOL>if ipdir is None:<EOL><INDENT>home_ipdir = pjoin(home_dir, ipdir_def)<EOL>if xdg_dir:<EOL><INDENT>xdg_ipdir = pjoin(xdg_dir, xdg_def)<EOL>if _writable_dir(xdg_ipdir) or not _writable_dir(home_ipdir):<EOL><INDENT>ipdir = xdg_ipdir<EOL><DEDENT><DEDENT>if ipdir is None:<EOL><INDENT>ipdir = home_ipdir<EOL><DEDENT><DEDENT>ipdir = os.path.normpath(os.path.expanduser(ipdir))<EOL>if os.path.exists(ipdir) and not _writable_dir(ipdir):<EOL><INDENT>warnings.warn("<STR_LIT>"<EOL>"<STR_LIT>"%ipdir)<EOL>ipdir = tempfile.mkdtemp()<EOL><DEDENT>elif not os.path.exists(ipdir):<EOL><INDENT>parent = ipdir.rsplit(os.path.sep, <NUM_LIT:1>)[<NUM_LIT:0>]<EOL>if not _writable_dir(parent):<EOL><INDENT>warnings.warn("<STR_LIT>"<EOL>"<STR_LIT>"%parent)<EOL>ipdir = tempfile.mkdtemp()<EOL><DEDENT><DEDENT>return py3compat.cast_unicode(ipdir, fs_encoding)<EOL>
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.