environment/lib/python2.7/site-packages/IPython/utils/path.py
def get_ipython_dir():
    """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.
    """

    env = os.environ
    pjoin = os.path.join


    ipdir_def = '.ipython'
    xdg_def = 'ipython'

    home_dir = get_home_dir()
    xdg_dir = get_xdg_dir()
    
    # import pdb; pdb.set_trace()  # dbg
    if 'IPYTHON_DIR' in env:
        warnings.warn('The environment variable IPYTHON_DIR is deprecated. '
                      'Please use IPYTHONDIR instead.')
    ipdir = env.get('IPYTHONDIR', env.get('IPYTHON_DIR', None))
    if ipdir is None:
        # not set explicitly, use XDG_CONFIG_HOME or HOME
        home_ipdir = pjoin(home_dir, ipdir_def)
        if xdg_dir:
            # use XDG, as long as the user isn't already
            # using $HOME/.ipython and *not* XDG/ipython

            xdg_ipdir = pjoin(xdg_dir, xdg_def)

            if _writable_dir(xdg_ipdir) or not _writable_dir(home_ipdir):
                ipdir = xdg_ipdir

        if ipdir is None:
            # not using XDG
            ipdir = home_ipdir

    ipdir = os.path.normpath(os.path.expanduser(ipdir))

    if os.path.exists(ipdir) and not _writable_dir(ipdir):
        # ipdir exists, but is not writable
        warnings.warn("IPython dir '%s' is not a writable location,"
                        " using a temp directory."%ipdir)
        ipdir = tempfile.mkdtemp()
    elif not os.path.exists(ipdir):
        parent = ipdir.rsplit(os.path.sep, 1)[0]
        if not _writable_dir(parent):
            # ipdir does not exist and parent isn't writable
            warnings.warn("IPython parent '%s' is not a writable location,"
                        " using a temp directory."%parent)
            ipdir = tempfile.mkdtemp()

    return py3compat.cast_unicode(ipdir, fs_encoding)
def get_ipython_dir():
    """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.
    """

    env = os.environ
    pjoin = os.path.join


    ipdir_def = '.ipython'
    xdg_def = 'ipython'

    home_dir = get_home_dir()
    xdg_dir = get_xdg_dir()
    
    # import pdb; pdb.set_trace()  # dbg
    if 'IPYTHON_DIR' in env:
        warnings.warn('The environment variable IPYTHON_DIR is deprecated. '
                      'Please use IPYTHONDIR instead.')
    ipdir = env.get('IPYTHONDIR', env.get('IPYTHON_DIR', None))
    if ipdir is None:
        # not set explicitly, use XDG_CONFIG_HOME or HOME
        home_ipdir = pjoin(home_dir, ipdir_def)
        if xdg_dir:
            # use XDG, as long as the user isn't already
            # using $HOME/.ipython and *not* XDG/ipython

            xdg_ipdir = pjoin(xdg_dir, xdg_def)

            if _writable_dir(xdg_ipdir) or not _writable_dir(home_ipdir):
                ipdir = xdg_ipdir

        if ipdir is None:
            # not using XDG
            ipdir = home_ipdir

    ipdir = os.path.normpath(os.path.expanduser(ipdir))

    if os.path.exists(ipdir) and not _writable_dir(ipdir):
        # ipdir exists, but is not writable
        warnings.warn("IPython dir '%s' is not a writable location,"
                        " using a temp directory."%ipdir)
        ipdir = tempfile.mkdtemp()
    elif not os.path.exists(ipdir):
        parent = ipdir.rsplit(os.path.sep, 1)[0]
        if not _writable_dir(parent):
            # ipdir does not exist and parent isn't writable
            warnings.warn("IPython parent '%s' is not a writable location,"
                        " using a temp directory."%parent)
            ipdir = tempfile.mkdtemp()

    return py3compat.cast_unicode(ipdir, fs_encoding)
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.