def extend_path(path, name):
if not isinstance(path, list):<EOL><INDENT>return path<EOL><DEDENT>pname = os.path.join(*name.split('<STR_LIT:.>'))  <EOL>init_py = "<STR_LIT>" + os.extsep + "<STR_LIT>"<EOL>path = path[:]<EOL>for dir in config.plugin_path:<EOL><INDENT>if not os.path.isdir(dir):<EOL><INDENT>if config.debug("<STR_LIT>"):<EOL><INDENT>print_debug("<STR_LIT>" % dir)<EOL><DEDENT>continue<EOL><DEDENT>subdir = os.path.join(dir, pname)<EOL>initfile = os.path.join(subdir, init_py)<EOL>if subdir not in path and os.path.isfile(initfile):<EOL><INDENT>path.append(subdir)<EOL><DEDENT><DEDENT>return path<EOL>
Extend a package's path.

    Intended use is to place the following code in a package's __init__.py:

        from pkgutil import extend_path
        __path__ = extend_path(__path__, __name__)

    This will add to the package's __path__ all subdirectories of
    directories on 'config.plugin_path' named after the package.  This is
    useful if one wants to distribute different parts of a single logical
    package as multiple directories.

    If the input path is not a list (as is the case for frozen
    packages) it is returned unchanged.  The input path is not
    modified; an extended copy is returned.  Items are only appended
    to the copy at the end.

    It is assumed that 'plugin_path' is a sequence.  Items of 'plugin_path'
    that are not (unicode or 8-bit) strings referring to existing
    directories are ignored.  Unicode items of sys.path that cause
    errors when used as filenames may cause this function to raise an
    exception (in line with os.path.isdir() behavior).