本文整理汇总了Python中entrypoints.get_single方法的典型用法代码示例。如果您正苦于以下问题:Python entrypoints.get_single方法的具体用法?Python entrypoints.get_single怎么用?Python entrypoints.get_single使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类entrypoints
的用法示例。
在下文中一共展示了entrypoints.get_single方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_load_zip
# 需要导入模块: import entrypoints [as 别名]
# 或者: from entrypoints import get_single [as 别名]
def test_load_zip(tmpdir):
whl_file = str(tmpdir / 'parmesan-1.2.whl')
with ZipFile(whl_file, 'w') as whl:
whl.writestr('parmesan-1.2.dist-info/entry_points.txt',
b'[entrypoints.test.inzip]\na = edam:gouda')
whl.writestr('gruyere-2!1b4.dev0.egg-info/entry_points.txt',
b'[entrypoints.test.inzip]\nb = wensleydale:gouda')
ep = entrypoints.get_single('entrypoints.test.inzip', 'a', [str(whl_file)])
assert ep.module_name == 'edam'
assert ep.object_name == 'gouda'
assert ep.distro.name == 'parmesan'
assert ep.distro.version == '1.2'
ep2 = entrypoints.get_single('entrypoints.test.inzip', 'b', [str(whl_file)])
assert ep2.module_name == 'wensleydale'
assert ep2.object_name == 'gouda'
assert ep2.distro.name == 'gruyere'
assert ep2.distro.version == '2!1b4.dev0'
示例2: _enable
# 需要导入模块: import entrypoints [as 别名]
# 或者: from entrypoints import get_single [as 别名]
def _enable(self, name: str, **options) -> None:
if name not in self._plugins:
try:
ep = entrypoints.get_single(self.entry_point_group, name)
except entrypoints.NoSuchEntryPoint:
if name in self.entrypoint_err_messages:
raise ValueError(self.entrypoint_err_messages[name])
else:
raise
value = cast(PluginType, ep.load())
self.register(name, value)
self._active_name = name
self._active = self._plugins[name]
for key in set(options.keys()) & set(self._global_settings.keys()):
self._global_settings[key] = options.pop(key)
self._options = options
示例3: load_backend
# 需要导入模块: import entrypoints [as 别名]
# 或者: from entrypoints import get_single [as 别名]
def load_backend(backend_name):
# Static backends
if backend_name in MLFLOW_BACKENDS:
return MLFLOW_BACKENDS[backend_name]()
# backends from plugin
try:
backend_builder = entrypoints.get_single(ENTRYPOINT_GROUP_NAME,
backend_name).load()
return backend_builder()
except entrypoints.NoSuchEntryPoint:
# TODO Should be a error when all backends are migrated here
available_entrypoints = entrypoints.get_group_all(
ENTRYPOINT_GROUP_NAME)
available_plugins = [
entrypoint.name for entrypoint in available_entrypoints]
__logger__.warning("Backend '%s' is not available. Available plugins are %s",
backend_name, available_plugins + list(MLFLOW_BACKENDS.keys()))
return None
示例4: _get_entrypoints_lib
# 需要导入模块: import entrypoints [as 别名]
# 或者: from entrypoints import get_single [as 别名]
def _get_entrypoints_lib(group, name=None):
import entrypoints
# Monkey patch some attributes for better API compatibility
entrypoints.EntryPoint.dist = property(lambda self: self.distro)
if name:
return entrypoints.get_single(group, name)
else:
from collections import OrderedDict
# Copied from 'get_group_named()' except that it preserves order
result = OrderedDict()
for ep in entrypoints.get_group_all(group):
if ep.name not in result:
result[ep.name] = ep
return result
示例5: test_get_single
# 需要导入模块: import entrypoints [as 别名]
# 或者: from entrypoints import get_single [as 别名]
def test_get_single():
ep = entrypoints.get_single('entrypoints.test1', 'abc', sample_path)
assert ep.module_name == 'foo'
assert ep.object_name == 'abc'
ep2 = entrypoints.get_single('entrypoints.test1', 'njn', sample_path)
assert ep2.module_name == 'qux.extn'
assert ep2.object_name == 'Njn.load'
示例6: test_dot_prefix
# 需要导入模块: import entrypoints [as 别名]
# 或者: from entrypoints import get_single [as 别名]
def test_dot_prefix():
ep = entrypoints.get_single('blogtool.parsers', '.rst', sample_path)
assert ep.object_name == 'SomeClass.some_classmethod'
assert ep.extras == ['reST']
group = entrypoints.get_group_named('blogtool.parsers', sample_path)
assert set(group.keys()) == {'.rst'}
示例7: test_load
# 需要导入模块: import entrypoints [as 别名]
# 或者: from entrypoints import get_single [as 别名]
def test_load():
ep = entrypoints.EntryPoint('get_ep', 'entrypoints', 'get_single', None)
obj = ep.load()
assert obj is entrypoints.get_single
# The object part is optional (e.g. pytest plugins use just a module ref)
ep = entrypoints.EntryPoint('ep_mod', 'entrypoints', None)
obj = ep.load()
assert obj is entrypoints
示例8: test_bad
# 需要导入模块: import entrypoints [as 别名]
# 或者: from entrypoints import get_single [as 别名]
def test_bad():
bad_path = [osp.join(samples_dir, 'packages3')]
with warnings.catch_warnings(record=True) as w:
group = entrypoints.get_group_named('entrypoints.test1', bad_path)
assert 'bad' not in group
assert len(w) == 1
with warnings.catch_warnings(record=True) as w2, \
pytest.raises(entrypoints.NoSuchEntryPoint):
ep = entrypoints.get_single('entrypoints.test1', 'bad')
assert len(w) == 1
示例9: _get_language_exporter
# 需要导入模块: import entrypoints [as 别名]
# 或者: from entrypoints import get_single [as 别名]
def _get_language_exporter(self, lang_name):
"""Find an exporter for the language name from notebook metadata.
Uses the nbconvert.exporters.script group of entry points.
Returns None if no exporter is found.
"""
if lang_name not in self._lang_exporters:
try:
Exporter = entrypoints.get_single(
'nbconvert.exporters.script', lang_name).load()
except entrypoints.NoSuchEntryPoint:
self._lang_exporters[lang_name] = None
else:
self._lang_exporters[lang_name] = Exporter(parent=self)
return self._lang_exporters[lang_name]
示例10: get_exporter
# 需要导入模块: import entrypoints [as 别名]
# 或者: from entrypoints import get_single [as 别名]
def get_exporter(name):
"""Given an exporter name or import path, return a class ready to be instantiated
Raises ValueError if exporter is not found
"""
if name == 'ipynb':
name = 'notebook'
try:
return entrypoints.get_single('nbconvert.exporters', name).load()
except entrypoints.NoSuchEntryPoint:
try:
return entrypoints.get_single('nbconvert.exporters', name.lower()).load()
except entrypoints.NoSuchEntryPoint:
pass
if '.' in name:
try:
return import_item(name)
except ImportError:
log = get_logger()
log.error("Error importing %s" % name, exc_info=True)
raise ValueError('Unknown exporter "%s", did you mean one of: %s?'
% (name, ', '.join(get_export_names())))