本文整理汇总了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