simplify load_setuptools_entrypoints and refine comments/docstrings
--HG-- branch : more_plugin
This commit is contained in:
		
							parent
							
								
									c54afbe42e
								
							
						
					
					
						commit
						b2d66b9e7b
					
				|  | @ -800,7 +800,10 @@ class Config(object): | |||
|             args[:] = self.getini("addopts") + args | ||||
|         self._checkversion() | ||||
|         self.pluginmanager.consider_preparse(args) | ||||
|         try: | ||||
|             self.pluginmanager.load_setuptools_entrypoints("pytest11") | ||||
|         except ImportError as e: | ||||
|             self.warn("I2", "could not load setuptools entry import: %s" % (e,)) | ||||
|         self.pluginmanager.consider_env() | ||||
|         self.known_args_namespace = ns = self._parser.parse_known_args(args) | ||||
|         try: | ||||
|  |  | |||
|  | @ -256,10 +256,6 @@ class PluginManager(object): | |||
|             return hc | ||||
|         return orig | ||||
| 
 | ||||
|     def get_canonical_name(self, plugin): | ||||
|         """ Return canonical name for a plugin object. """ | ||||
|         return getattr(plugin, "__name__", None) or str(id(plugin)) | ||||
| 
 | ||||
|     def register(self, plugin, name=None): | ||||
|         """ Register a plugin and return its canonical name or None if the name | ||||
|         is blocked from registering.  Raise a ValueError if the plugin is already | ||||
|  | @ -344,6 +340,13 @@ class PluginManager(object): | |||
|         """ Return True if the plugin is already registered. """ | ||||
|         return plugin in self._plugin2hookcallers | ||||
| 
 | ||||
|     def get_canonical_name(self, plugin): | ||||
|         """ Return canonical name for a plugin object. Note that a plugin | ||||
|         may be registered under a different name which was specified | ||||
|         by the caller of register(plugin, name). To obtain the name | ||||
|         of an registered plugin use ``get_name(plugin)`` instead.""" | ||||
|         return getattr(plugin, "__name__", None) or str(id(plugin)) | ||||
| 
 | ||||
|     def get_plugin(self, name): | ||||
|         """ Return a plugin or None for the given name. """ | ||||
|         return self._name2plugin.get(name) | ||||
|  | @ -386,14 +389,11 @@ class PluginManager(object): | |||
|                                 "unknown hook %r in plugin %r" %(name, plugin)) | ||||
| 
 | ||||
|     def load_setuptools_entrypoints(self, entrypoint_name): | ||||
|         """ Load modules from querying the specified entrypoint name. | ||||
|         Return None if setuptools was not operable, otherwise | ||||
|         the number of loaded plugins. """ | ||||
|         try: | ||||
|         """ Load modules from querying the specified setuptools entrypoint name. | ||||
|         Return the number of loaded plugins. """ | ||||
|         from pkg_resources import iter_entry_points, DistributionNotFound | ||||
|         except ImportError: | ||||
|             return # XXX issue a warning | ||||
|         for ep in iter_entry_points(entrypoint_name): | ||||
|             # is the plugin registered or blocked? | ||||
|             if self.get_plugin(ep.name) or ep.name in self._name2plugin: | ||||
|                 continue | ||||
|             try: | ||||
|  |  | |||
|  | @ -419,8 +419,8 @@ class TestAddMethodOrdering: | |||
|     def test_load_setuptools_not_installed(self, monkeypatch, pm): | ||||
|         monkeypatch.setitem(py.std.sys.modules, 'pkg_resources', | ||||
|             py.std.types.ModuleType("pkg_resources")) | ||||
|         assert pm.load_setuptools_entrypoints("qwe") is None | ||||
|         # ok, we did not explode | ||||
|         with pytest.raises(ImportError): | ||||
|             pm.load_setuptools_entrypoints("qwe") | ||||
| 
 | ||||
| 
 | ||||
| class TestPytestPluginInteractions: | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue