本文整理匯總了Python中pkg_resources.EntryPoint.parse方法的典型用法代碼示例。如果您正苦於以下問題:Python EntryPoint.parse方法的具體用法?Python EntryPoint.parse怎麽用?Python EntryPoint.parse使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pkg_resources.EntryPoint
的用法示例。
在下文中一共展示了EntryPoint.parse方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: load_entrypoint
# 需要導入模塊: from pkg_resources import EntryPoint [as 別名]
# 或者: from pkg_resources.EntryPoint import parse [as 別名]
def load_entrypoint(cls, reference, onerror='raise'):
# Resolve entrypoint
expression = u'_ = {reference}'.format(reference=reference)
try:
entrypoint = EntryPoint.parse(expression)
except:
log.failure('Error parsing entrypoint "{reference}" from expression "{expression}"',
reference=reference, expression=expression)
raise
# Load entrypoint
try:
thing = entrypoint.load(require=False)
except:
log.failure('Error loading entrypoint "{reference}"', reference=reference)
if onerror == 'raise':
raise
elif onerror == 'ignore':
return cls.noop_callable
#raise
return thing
示例2: __getitem__
# 需要導入模塊: from pkg_resources import EntryPoint [as 別名]
# 或者: from pkg_resources.EntryPoint import parse [as 別名]
def __getitem__(self, name):
"""Get a converter, lazy loading it if necessary"""
if name in self.converters:
return self.converters[name]
for ep in iter_entry_points(self.entry_point):
if ep.name == name:
self.converters[ep.name] = ep.load()()
return self.converters[ep.name]
for ep in (EntryPoint.parse(c) for c in self.registered_converters + self.internal_converters):
if ep.name == name:
# `require` argument of ep.load() is deprecated in newer versions of setuptools
if hasattr(ep, 'resolve'):
plugin = ep.resolve()
elif hasattr(ep, '_load'):
plugin = ep._load()
else:
plugin = ep.load(require=False)
self.converters[ep.name] = plugin()
return self.converters[ep.name]
raise KeyError(name)
示例3: load_model
# 需要導入模塊: from pkg_resources import EntryPoint [as 別名]
# 或者: from pkg_resources.EntryPoint import parse [as 別名]
def load_model(dotted_name):
"""Import module and use module-level variable".
:param dotted_name: path to model in form of string: ``some.python.module:Class``
.. versionchanged:: 0.5.4
"""
if isinstance(dotted_name, six.string_types):
if ':' not in dotted_name:
# backwards compatibility
warnings.warn('model should be in form of module.model:User '
'and not module.model.User', exceptions.MigrateDeprecationWarning)
dotted_name = ':'.join(dotted_name.rsplit('.', 1))
return EntryPoint.parse('x=%s' % dotted_name).load(False)
else:
# Assume it's already loaded.
return dotted_name
示例4: list_entry_points
# 需要導入模塊: from pkg_resources import EntryPoint [as 別名]
# 或者: from pkg_resources.EntryPoint import parse [as 別名]
def list_entry_points(self):
# copy of default extensions
eps = list(super(RegistrableExtensionManager, self).list_entry_points())
# internal extensions
for iep in self.internal_extensions:
ep = EntryPoint.parse(iep)
if ep.name not in [e.name for e in eps]:
eps.append(ep)
# registered extensions
for rep in self.registered_extensions:
ep = EntryPoint.parse(rep)
if ep.name not in [e.name for e in eps]:
eps.append(ep)
return eps
示例5: register
# 需要導入模塊: from pkg_resources import EntryPoint [as 別名]
# 或者: from pkg_resources.EntryPoint import parse [as 別名]
def register(self, entry_point):
"""Register an extension
:param str entry_point: extension to register (entry point syntax).
:raise: ValueError if already registered.
"""
if entry_point in self.registered_extensions:
raise ValueError('Extension already registered')
ep = EntryPoint.parse(entry_point)
if ep.name in self.names():
raise ValueError('An extension with the same name already exist')
ext = self._load_one_plugin(ep, False, (), {}, False)
self.extensions.append(ext)
if self._extensions_by_name is not None:
self._extensions_by_name[ext.name] = ext
self.registered_extensions.insert(0, entry_point)
示例6: unregister
# 需要導入模塊: from pkg_resources import EntryPoint [as 別名]
# 或者: from pkg_resources.EntryPoint import parse [as 別名]
def unregister(self, entry_point):
"""Unregister a provider
:param str entry_point: provider to unregister (entry point syntax).
"""
if entry_point not in self.registered_extensions:
raise ValueError('Extension not registered')
ep = EntryPoint.parse(entry_point)
self.registered_extensions.remove(entry_point)
if self._extensions_by_name is not None:
del self._extensions_by_name[ep.name]
for i, ext in enumerate(self.extensions):
if ext.name == ep.name:
del self.extensions[i]
break
#: Provider manager
示例7: run
# 需要導入模塊: from pkg_resources import EntryPoint [as 別名]
# 或者: from pkg_resources.EntryPoint import parse [as 別名]
def run(agent=None, socketdir='tmp/sock', daemonize=False, args=[]):
if daemonize:
pid = os.fork()
if pid > 0:
return
if agent is None:
print('Running agent: random_agent')
agent = random_agent
elif not callable(agent):
print('Running agent: %s' % agent)
entrypoint = EntryPoint.parse('entry=' + agent)
agent = entrypoint.load(False)
else:
print('Running agent: %r' % agent)
env = make(socketdir)
try:
agent(env, *args)
except gre.GymRemoteError:
pass
示例8: test_conflict_registration
# 需要導入模塊: from pkg_resources import EntryPoint [as 別名]
# 或者: from pkg_resources.EntryPoint import parse [as 別名]
def test_conflict_registration(self):
# create an empty working set for a clean-slate test.
cwd = utils.mkdtemp(self)
mock_ws = WorkingSet([])
registry = ArtifactRegistry('calmjs.artifacts', _working_set=mock_ws)
# using named case for case sensitivity test.
st = join(cwd, 'calmjs_artifacts', 'Simple.js')
dist_ = Distribution(cwd, project_name='pkg', version='1.0')
dist_.egg_info = cwd # just lazy
s1 = EntryPoint.parse('Simple.js = dummy_builder:builder1')
s1.dist = dist_
s2 = EntryPoint.parse('Simple.js = dummy_builder:builder2')
s2.dist = dist_
with pretty_logging(stream=mocks.StringIO()) as stream:
registry.register_entry_point(s1)
# normal registry usage shouldn't be able to do this.
registry.register_entry_point(s2)
log = stream.getvalue()
self.assertIn(
"entry point 'Simple.js = dummy_builder:builder2' from package "
"'pkg 1.0' resolves to the path '%s' which was already "
"registered to entry point 'Simple.js = dummy_builder:builder1'; "
"conflicting entry point registration will be ignored." % st,
log
)
示例9: test_normcase_registration
# 需要導入模塊: from pkg_resources import EntryPoint [as 別名]
# 或者: from pkg_resources.EntryPoint import parse [as 別名]
def test_normcase_registration(self):
# create an empty working set for a clean-slate test.
cwd = utils.mkdtemp(self)
mock_ws = WorkingSet([])
dist_ = Distribution(cwd, project_name='pkg', version='1.0')
dist_.egg_info = cwd # just lazy
registry = ArtifactRegistry('calmjs.artifacts', _working_set=mock_ws)
# case sensitive test; have to patch the normcase at artifact
# module with the nt version
from ntpath import normcase as nt_normcase
utils.stub_item_attr_value(self, artifact, 'normcase', nt_normcase)
# using named case for case sensitivity test.
c1 = EntryPoint.parse('case.js = dummy_builder:builder1')
c1.dist = dist_
c2 = EntryPoint.parse('Case.js = dummy_builder:builder2')
c2.dist = dist_
# use the error one
ct = join(cwd, 'calmjs_artifacts', 'Case.js')
with pretty_logging(stream=mocks.StringIO()) as stream:
registry.register_entry_point(c1)
registry.register_entry_point(c2)
log = stream.getvalue()
self.assertIn(
"entry point 'Case.js = dummy_builder:builder2' from package "
"'pkg 1.0' resolves to the path '%s' which was already "
"registered to entry point 'case.js = dummy_builder:builder1'; "
"conflicting entry point registration will be ignored." % ct,
log
)
self.assertIn(
"the file mapping error is caused by this platform's case-"
"insensitive filename", log
)
示例10: test_module_registry_standard
# 需要導入模塊: from pkg_resources import EntryPoint [as 別名]
# 或者: from pkg_resources.EntryPoint import parse [as 別名]
def test_module_registry_standard(self):
with pretty_logging(stream=mocks.StringIO()):
self.registry.register_entry_points([EntryPoint.parse(
'calmjs.testing.module1 = calmjs.testing.module1')])
self.assertEqual(sorted(
key for key, value in self.registry.iter_records()
), [
'calmjs.testing.module1',
])
module1 = self.registry.get_record('calmjs.testing.module1')
key = 'calmjs/testing/module1/hello'
self.assertEqual(sorted(module1.keys()), [key])
示例11: test_module_registry_pythonic
# 需要導入模塊: from pkg_resources import EntryPoint [as 別名]
# 或者: from pkg_resources.EntryPoint import parse [as 別名]
def test_module_registry_pythonic(self):
registry = PythonicModuleRegistry(__name__)
with pretty_logging(stream=mocks.StringIO()):
registry.register_entry_points([EntryPoint.parse(
'calmjs.testing.module1 = calmjs.testing.module1')])
self.assertEqual(sorted(
key for key, value in registry.iter_records()
), [
'calmjs.testing.module1',
])
module1 = registry.get_record('calmjs.testing.module1')
key = 'calmjs.testing.module1.hello'
self.assertEqual(sorted(module1.keys()), [key])
示例12: test_dummy_implemented_manual_entrypoint
# 需要導入模塊: from pkg_resources import EntryPoint [as 別名]
# 或者: from pkg_resources.EntryPoint import parse [as 別名]
def test_dummy_implemented_manual_entrypoint(self):
from calmjs.testing import module1
registry = DummyModuleRegistry(__name__)
with pretty_logging(stream=mocks.StringIO()) as s:
registry.register_entry_point(
EntryPoint.parse(
'calmjs.testing.module1 = calmjs.testing.module1')
)
# no dist.
self.assertIn('manually registering entry_point', s.getvalue())
result = registry.get_record('calmjs.testing.module1')
self.assertEqual(result, {'calmjs.testing.module1': module1})
示例13: iter_entry_points
# 需要導入模塊: from pkg_resources import EntryPoint [as 別名]
# 或者: from pkg_resources.EntryPoint import parse [as 別名]
def iter_entry_points(self, name):
items = self.items.get(name, [])
for item in items:
entry_point = item if isinstance(
item, EntryPoint) else EntryPoint.parse(item)
entry_point.dist = self.dist
yield entry_point
示例14: register_module
# 需要導入模塊: from pkg_resources import EntryPoint [as 別名]
# 或者: from pkg_resources.EntryPoint import parse [as 別名]
def register_module(self, name=None, module_name=None, attrs=(), entry_point=None):
if entry_point:
ep = EntryPoint.parse(entry_point)
else:
ep = EntryPoint(name, module_name, attrs)
loaded = self._load_one_plugin(ep, invoke_on_load=True, invoke_args=(), invoke_kwds={})
if loaded:
self.extensions.append(loaded)
self.extensions = self.order_extensions(self.extensions)
self._extensions_by_name = None
示例15: _find_entry_points
# 需要導入模塊: from pkg_resources import EntryPoint [as 別名]
# 或者: from pkg_resources.EntryPoint import parse [as 別名]
def _find_entry_points(self, namespace):
entry_points = {}
# Internal entry points
if namespace == self.namespace:
for internal_entry_point_str in self._internal_entry_points:
internal_entry_point = EntryPoint.parse(internal_entry_point_str)
entry_points[internal_entry_point.name] = internal_entry_point
# Package entry points
setuptools_entrypoints = super(DefaultTransformerExtensionManager, self)._find_entry_points(namespace)
for setuptools_entrypoint in setuptools_entrypoints:
entry_points[setuptools_entrypoint.name] = setuptools_entrypoint
return list(entry_points.values())