def find_spec(modpath, path=None):
_path = path or sys.path<EOL>modpath = modpath[:]<EOL>submodule_path = None<EOL>module_parts = modpath[:]<EOL>processed = []<EOL>while modpath:<EOL><INDENT>modname = modpath.pop(<NUM_LIT:0>)<EOL>finder, spec = _find_spec_with_path(<EOL>_path, modname, module_parts, processed, submodule_path or path<EOL>)<EOL>processed.append(modname)<EOL>if modpath:<EOL><INDENT>submodule_path = finder.contribute_to_path(spec, processed)<EOL><DEDENT>if spec.type == ModuleType.PKG_DIRECTORY:<EOL><INDENT>spec = spec._replace(submodule_search_locations=submodule_path)<EOL><DEDENT><DEDENT>return spec<EOL>
Find a spec for the given module.

    :type modpath: list or tuple
    :param modpath:
      split module's name (i.e name of a module or package split
      on '.'), with leading empty strings for explicit relative import

    :type path: list or None
    :param path:
      optional list of path where the module or package should be
      searched (use sys.path if nothing or None is given)

    :rtype: ModuleSpec
    :return: A module spec, which describes how the module was
             found and where.