本文整理匯總了Python中importlib_metadata.distributions方法的典型用法代碼示例。如果您正苦於以下問題:Python importlib_metadata.distributions方法的具體用法?Python importlib_metadata.distributions怎麽用?Python importlib_metadata.distributions使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類importlib_metadata
的用法示例。
在下文中一共展示了importlib_metadata.distributions方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _mark_plugins_for_rewrite
# 需要導入模塊: import importlib_metadata [as 別名]
# 或者: from importlib_metadata import distributions [as 別名]
def _mark_plugins_for_rewrite(self, hook):
"""
Given an importhook, mark for rewrite any top-level
modules or packages in the distribution package for
all pytest plugins.
"""
self.pluginmanager.rewrite_hook = hook
if os.environ.get("PYTEST_DISABLE_PLUGIN_AUTOLOAD"):
# We don't autoload from setuptools entry points, no need to continue.
return
package_files = (
str(file)
for dist in importlib_metadata.distributions()
if any(ep.group == "pytest11" for ep in dist.entry_points)
for file in dist.files or []
)
for name in _iter_rewritable_modules(package_files):
hook.mark_rewrite(name)
示例2: load_setuptools_entrypoints
# 需要導入模塊: import importlib_metadata [as 別名]
# 或者: from importlib_metadata import distributions [as 別名]
def load_setuptools_entrypoints(self, group, name=None):
""" Load modules from querying the specified setuptools ``group``.
:param str group: entry point group to load plugins
:param str name: if given, loads only plugins with the given ``name``.
:rtype: int
:return: return the number of loaded plugins by this call.
"""
count = 0
for dist in importlib_metadata.distributions():
for ep in dist.entry_points:
if (
ep.group != group
or (name is not None and ep.name != name)
# already registered
or self.get_plugin(ep.name)
or self.is_blocked(ep.name)
):
continue
plugin = ep.load()
self.register(plugin, name=ep.name)
self._plugin_distinfo.append((plugin, DistFacade(dist)))
count += 1
return count
示例3: get_all_entry_points
# 需要導入模塊: import importlib_metadata [as 別名]
# 或者: from importlib_metadata import distributions [as 別名]
def get_all_entry_points():
"""
Get all entry points related to ``ros2cli`` and any of its extensions.
:returns: mapping of entry point names to ``EntryPoint`` instances
:rtype: dict
"""
extension_points = get_entry_points(EXTENSION_POINT_GROUP_NAME)
entry_points = defaultdict(dict)
for dist in importlib_metadata.distributions():
for ep in dist.entry_points:
# skip groups which are not registered as extension points
if ep.group not in extension_points:
continue
entry_points[ep.group][ep.name] = (dist, ep)
return entry_points
示例4: test_package_discovery
# 需要導入模塊: import importlib_metadata [as 別名]
# 或者: from importlib_metadata import distributions [as 別名]
def test_package_discovery(self):
dists = list(distributions())
assert all(
isinstance(dist, Distribution)
for dist in dists
)
assert any(
dist.metadata['Name'] == 'egginfo-pkg'
for dist in dists
)
assert any(
dist.metadata['Name'] == 'distinfo-pkg'
for dist in dists
)
示例5: test_invalid_usage
# 需要導入模塊: import importlib_metadata [as 別名]
# 或者: from importlib_metadata import distributions [as 別名]
def test_invalid_usage(self):
with self.assertRaises(ValueError):
list(distributions(context='something', name='else'))
示例6: test_discovery
# 需要導入模塊: import importlib_metadata [as 別名]
# 或者: from importlib_metadata import distributions [as 別名]
def test_discovery(self):
"""
Discovering distributions should succeed even if
there is an invalid path on sys.path.
"""
importlib_metadata.distributions()
示例7: list_extensions
# 需要導入模塊: import importlib_metadata [as 別名]
# 或者: from importlib_metadata import distributions [as 別名]
def list_extensions() -> List[ExtensionInfo]:
"""
List all installed Chaos Toolkit extensions in the current environment.
Notice, for now we can only list extensions that start with `chaostoolkit-`
in their package name.
This is not as powerful and solid as we want it to be. The trick is that we
can't rely on any metadata inside extensions to tell us they exist and
what functionnality they provide either. Python has the concept of trove
classifiers on packages but we can't extend them yet so they are of no use
to us.
In a future version, we will provide a mechanism from packages to support
a better detection.
"""
infos = []
distros = importlib_metadata.distributions()
seen = []
for dist in distros:
info = dist.metadata
name = info['Name']
if name == "chaostoolkit-lib":
continue
if name in seen:
continue
seen.append(name)
if name.startswith("chaostoolkit-"):
ext = ExtensionInfo(
name=name,
version=info["Version"],
summary=info["Summary"],
license=info["License"],
author=info["Author"],
url=info["Home-page"])
infos.append(ext)
return infos