MCPcopy Index your code
hub / github.com/python/cpython / find_spec

Method find_spec

Lib/zipimport.py:98–123  ·  view source on GitHub ↗

Create a ModuleSpec for the specified module. Returns None if the module cannot be found.

(self, fullname, target=None)

Source from the content-addressed store, hash-verified

96
97
98 def find_spec(self, fullname, target=None):
99 """Create a ModuleSpec for the specified module.
100
101 Returns None if the module cannot be found.
102 """
103 module_info = _get_module_info(self, fullname)
104 if module_info is not None:
105 return _bootstrap.spec_from_loader(fullname, self, is_package=module_info)
106 else:
107 # Not a module or regular package. See if this is a directory, and
108 # therefore possibly a portion of a namespace package.
109
110 # We're only interested in the last path component of fullname
111 # earlier components are recorded in self.prefix.
112 modpath = _get_module_path(self, fullname)
113 if _is_dir(self, modpath):
114 # This is possibly a portion of a namespace
115 # package. Return the string representing its path,
116 # without a trailing separator.
117 path = f'{self.archive}{path_sep}{modpath}'
118 spec = _bootstrap.ModuleSpec(name=fullname, loader=None,
119 is_package=True)
120 spec.submodule_search_locations.append(path)
121 return spec
122 else:
123 return None
124
125 def get_code(self, fullname):
126 """get_code(fullname) -> code object.

Callers 7

extend_pathFunction · 0.45
get_dataFunction · 0.45
_find_moduleFunction · 0.45
runMethod · 0.45
_get_module_detailsFunction · 0.45
getFilesForNameFunction · 0.45

Calls 4

_get_module_infoFunction · 0.85
_get_module_pathFunction · 0.85
_is_dirFunction · 0.85
appendMethod · 0.45

Tested by

no test coverage detected