Expand home directory

def _expand_path(cwd, user):
    '''
    Expand home directory
    '''
    try:
        to_expand = '~' + user if user else '~'
    except TypeError:
        # Users should never be numeric but if we don't account for this then
        # we're going to get a traceback if someone passes this invalid input.
        to_expand = '~' + six.text_type(user) if user else '~'
    try:
        return os.path.join(os.path.expanduser(to_expand), cwd)
    except AttributeError:
        return os.path.join(os.path.expanduser(to_expand), six.text_type(cwd))