def expand_path(view, path):
    """
    Expand ST build system and OS environment variables to normalized path
    that allows collapsing up-level references for basic path manipulation
    through combination of variables and/or separators, i.e.:
        "python_interpreter": "$project_path/../../virtual/bin/python",
        "python_package_paths": ["$home/.buildout/eggs"]

    :type view: sublime.View
    :type path: str
    :rtype: str
    """
    subl_vars = {}
    try:
        subl_vars['$file'] = view.file_name()
        subl_vars['$packages'] = sublime.packages_path()

        try:
            subl_vars['$project'] = view.window().project_file_name()
        except __HOLE__:
            subl_vars['$project'] = get_project_file_name(view.window())

        subl_vars = split_path(subl_vars, ['$file', '$project'])
        if '$' in path or '%' in path:
            exp_path = path
            for k in sorted(subl_vars, key=len, reverse=True):
                if subl_vars[k]:
                    exp_path = exp_path.replace(k, subl_vars[k])
            exp_path = os.path.normpath(os.path.expandvars(exp_path))
            if os.path.exists(exp_path):
                path = exp_path
    except Exception:
        logger.exception('Exception while expanding "{0}"'.format(path))

    return path
dataset/ETHPy150Open srusskih/SublimeJEDI/sublime_jedi/utils.py/expand_path