6from typing
import Collection, Iterable, Iterator, List, Mapping, NamedTuple, Optional
37 """IMetadataProvider that reads metadata files from a dictionary.
39 This also maps metadata decoding exceptions to our internal exception type.
42 def __init__(self, metadata: Mapping[str, bytes], wheel_name: str) ->
None:
52 except UnicodeDecodeError
as e:
55 f
"Error decoding metadata for {self._wheel_name}: {e} in {name} file"
67 def run_script(self, script_name: str, namespace: str) ->
None:
72 def __init__(self, dist: pkg_resources.Distribution) ->
None:
92 dist =
dist_cls(base_dir, project_name=dist_name, metadata=metadata)
98 metadata_contents: bytes,
101 ) -> BaseDistribution:
103 "METADATA": metadata_contents,
108 project_name=project_name,
113 def from_wheel(cls, wheel: Wheel, name: str) -> BaseDistribution:
116 info_dir, _ = parse_wheel(zf, name)
118 path.split(
"/", 1)[-1]: read_wheel_metadata_file(zf, path)
124 except UnsupportedWheel
as e:
135 return self.
_dist.location
146 return normalize_path(location)
150 return self.
_dist.egg_info
159 except AttributeError:
164 return canonicalize_name(self.
_dist.project_name)
167 def version(self) -> DistributionVersion:
168 return parse_version(self.
_dist.version)
171 return self.
_dist.has_metadata(str(path))
174 yield from self.
_dist.metadata_listdir(
"scripts")
178 if not self.
_dist.has_metadata(name):
179 raise FileNotFoundError(name)
180 content = self.
_dist.get_metadata(name)
186 for group, entries
in self.
_dist.get_entry_map().items():
188 name, _, value = str(entry_point).partition(
"=")
193 :raises NoneMetadataError: if the distribution reports `has_metadata()`
194 True but `get_metadata()` returns None.
197 metadata_name =
"METADATA"
199 metadata_name =
"PKG-INFO"
202 except FileNotFoundError:
216 return self.
_dist.requires(extras)
219 return self.
_dist.extras
223 def __init__(self, ws: pkg_resources.WorkingSet) ->
None:
231 def from_paths(cls, paths: Optional[List[str]]) -> BaseEnvironment:
235 for dist
in self.
_ws:
239 """Find a distribution matching the ``name`` in the environment.
241 This searches from *all* distributions available in the environment, to
242 match the behavior of ``pkg_resources.get_distribution()``.
244 canonical_name = canonicalize_name(name)
267 self.
_ws.require(name)