def expand_path(view, path):
    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 AttributeError:
            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
Expand ST build system and OS environment variables to normalized path
dataset/ETHPy150Open srusskih/SublimeJEDI/sublime_jedi/utils.py/expand_path