def expand_path(path):
    """
    Auto search some variables defined in path string, such as:
        $[PROJECT]/files
        $[app_name]/files
    for $[PROJECT] will be replaced with uliweb application apps_dir directory
    and others will be treated as a normal python package, so uliweb will
    use pkg_resources to get the path of the package
    
    update: 0.2.5 changed from ${} to $[]

    Also apply with os.path.expandvars(os.path.expanduser(path))
    """
    from uliweb import application
    
    def replace(m):
        txt = m.groups()[0]
        if txt == 'PROJECT':
            return application.apps_dir
        else:
            return pkg.resource_filename(txt, '')
    p = re.sub(r_expand_path, replace, path)
    return os.path.expandvars(os.path.expanduser(path))
Auto search some variables defined in path string, such as:
        $[PROJECT]/files
        $[app_name]/files
    for $[PROJECT] will be replaced with uliweb application apps_dir directory
    and others will be treated as a normal python package, so uliweb will
    use pkg_resources to get the path of the package
    
    update: 0.2.5 changed from ${} to $[]

    Also apply with os.path.expandvars(os.path.expanduser(path))