当前位置: 首页>>代码示例>>Python>>正文


Python EntryPoint.parse方法代码示例

本文整理汇总了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 
开发者ID:daq-tools,项目名称:kotori,代码行数:25,代码来源:core.py

示例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) 
开发者ID:caronc,项目名称:nzb-subliminal,代码行数:22,代码来源:__init__.py

示例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 
开发者ID:gltn,项目名称:stdm,代码行数:20,代码来源:__init__.py

示例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 
开发者ID:morpheus65535,项目名称:bazarr,代码行数:19,代码来源:extensions.py

示例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) 
开发者ID:morpheus65535,项目名称:bazarr,代码行数:21,代码来源:extensions.py

示例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 
开发者ID:morpheus65535,项目名称:bazarr,代码行数:22,代码来源:extensions.py

示例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 
开发者ID:openai,项目名称:retro-contest,代码行数:22,代码来源:agent.py

示例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
        ) 
开发者ID:calmjs,项目名称:calmjs,代码行数:29,代码来源:test_artifact.py

示例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
        ) 
开发者ID:calmjs,项目名称:calmjs,代码行数:36,代码来源:test_artifact.py

示例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]) 
开发者ID:calmjs,项目名称:calmjs,代码行数:15,代码来源:test_module.py

示例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]) 
开发者ID:calmjs,项目名称:calmjs,代码行数:16,代码来源:test_module.py

示例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}) 
开发者ID:calmjs,项目名称:calmjs,代码行数:14,代码来源:test_base.py

示例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 
开发者ID:calmjs,项目名称:calmjs,代码行数:9,代码来源:mocks.py

示例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 
开发者ID:caronc,项目名称:nzb-subliminal,代码行数:12,代码来源:transformers.py

示例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()) 
开发者ID:caronc,项目名称:nzb-subliminal,代码行数:16,代码来源:transformers.py


注:本文中的pkg_resources.EntryPoint.parse方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。