@@ -22,7 +22,7 @@ def _warn_for_function(warning, function):
22
22
23
23
24
24
class PluginValidationError (Exception ):
25
- """ plugin failed validation.
25
+ """plugin failed validation.
26
26
27
27
:param object plugin: the plugin which failed validation,
28
28
may be a module or an arbitrary object.
@@ -51,7 +51,7 @@ def __dir__(self):
51
51
52
52
53
53
class PluginManager :
54
- """ Core :py:class:`.PluginManager` class which manages registration
54
+ """Core :py:class:`.PluginManager` class which manages registration
55
55
of plugin objects and 1:N hook calling.
56
56
57
57
You can register new hooks by calling :py:meth:`add_hookspecs(module_or_class)
@@ -80,9 +80,9 @@ def _hookexec(self, hook_name, methods, kwargs, firstresult):
80
80
return self ._inner_hookexec (hook_name , methods , kwargs , firstresult )
81
81
82
82
def register (self , plugin , name = None ):
83
- """ Register a plugin and return its canonical name or ``None`` if the name
83
+ """Register a plugin and return its canonical name or ``None`` if the name
84
84
is blocked from registering. Raise a :py:class:`ValueError` if the plugin
85
- is already registered. """
85
+ is already registered."""
86
86
plugin_name = name or self .get_canonical_name (plugin )
87
87
88
88
if plugin_name in self ._name2plugin or plugin in self ._plugin2hookcallers :
@@ -131,8 +131,8 @@ def parse_hookimpl_opts(self, plugin, name):
131
131
return res
132
132
133
133
def unregister (self , plugin = None , name = None ):
134
- """ unregister a plugin object and all its contained hook implementations
135
- from internal data structures. """
134
+ """unregister a plugin object and all its contained hook implementations
135
+ from internal data structures."""
136
136
if name is None :
137
137
assert plugin is not None , "one of name or plugin needs to be specified"
138
138
name = self .get_name (plugin )
@@ -150,17 +150,17 @@ def unregister(self, plugin=None, name=None):
150
150
return plugin
151
151
152
152
def set_blocked (self , name ):
153
- """ block registrations of the given name, unregister if already registered. """
153
+ """block registrations of the given name, unregister if already registered."""
154
154
self .unregister (name = name )
155
155
self ._name2plugin [name ] = None
156
156
157
157
def is_blocked (self , name ):
158
- """ return ``True`` if the given plugin name is blocked. """
158
+ """return ``True`` if the given plugin name is blocked."""
159
159
return name in self ._name2plugin and self ._name2plugin [name ] is None
160
160
161
161
def add_hookspecs (self , module_or_class ):
162
- """ add new hook specifications defined in the given ``module_or_class``.
163
- Functions are recognized if they have been decorated accordingly. """
162
+ """add new hook specifications defined in the given ``module_or_class``.
163
+ Functions are recognized if they have been decorated accordingly."""
164
164
names = []
165
165
for name in dir (module_or_class ):
166
166
spec_opts = self .parse_hookspec_opts (module_or_class , name )
@@ -186,31 +186,31 @@ def parse_hookspec_opts(self, module_or_class, name):
186
186
return getattr (method , self .project_name + "_spec" , None )
187
187
188
188
def get_plugins (self ):
189
- """ return the set of registered plugins. """
189
+ """return the set of registered plugins."""
190
190
return set (self ._plugin2hookcallers )
191
191
192
192
def is_registered (self , plugin ):
193
- """ Return ``True`` if the plugin is already registered. """
193
+ """Return ``True`` if the plugin is already registered."""
194
194
return plugin in self ._plugin2hookcallers
195
195
196
196
def get_canonical_name (self , plugin ):
197
- """ Return canonical name for a plugin object. Note that a plugin
197
+ """Return canonical name for a plugin object. Note that a plugin
198
198
may be registered under a different name which was specified
199
199
by the caller of :py:meth:`register(plugin, name) <.PluginManager.register>`.
200
200
To obtain the name of an registered plugin use :py:meth:`get_name(plugin)
201
201
<.PluginManager.get_name>` instead."""
202
202
return getattr (plugin , "__name__" , None ) or str (id (plugin ))
203
203
204
204
def get_plugin (self , name ):
205
- """ Return a plugin or ``None`` for the given name. """
205
+ """Return a plugin or ``None`` for the given name."""
206
206
return self ._name2plugin .get (name )
207
207
208
208
def has_plugin (self , name ):
209
- """ Return ``True`` if a plugin with the given name is registered. """
209
+ """Return ``True`` if a plugin with the given name is registered."""
210
210
return self .get_plugin (name ) is not None
211
211
212
212
def get_name (self , plugin ):
213
- """ Return name for registered plugin or ``None`` if not registered. """
213
+ """Return name for registered plugin or ``None`` if not registered."""
214
214
for name , val in self ._name2plugin .items ():
215
215
if plugin == val :
216
216
return name
@@ -251,7 +251,7 @@ def _verify_hook(self, hook, hookimpl):
251
251
)
252
252
253
253
def check_pending (self ):
254
- """ Verify that all hooks which have not been verified against
254
+ """Verify that all hooks which have not been verified against
255
255
a hook specification are optional, otherwise raise :py:class:`.PluginValidationError`."""
256
256
for name in self .hook .__dict__ :
257
257
if name [0 ] != "_" :
@@ -266,7 +266,7 @@ def check_pending(self):
266
266
)
267
267
268
268
def load_setuptools_entrypoints (self , group , name = None ):
269
- """ Load modules from querying the specified setuptools ``group``.
269
+ """Load modules from querying the specified setuptools ``group``.
270
270
271
271
:param str group: entry point group to load plugins
272
272
:param str name: if given, loads only plugins with the given ``name``.
@@ -291,20 +291,20 @@ def load_setuptools_entrypoints(self, group, name=None):
291
291
return count
292
292
293
293
def list_plugin_distinfo (self ):
294
- """ return list of distinfo/plugin tuples for all setuptools registered
295
- plugins. """
294
+ """return list of distinfo/plugin tuples for all setuptools registered
295
+ plugins."""
296
296
return list (self ._plugin_distinfo )
297
297
298
298
def list_name_plugin (self ):
299
- """ return list of name/plugin pairs. """
299
+ """return list of name/plugin pairs."""
300
300
return list (self ._name2plugin .items ())
301
301
302
302
def get_hookcallers (self , plugin ):
303
- """ get all hook callers for the specified plugin. """
303
+ """get all hook callers for the specified plugin."""
304
304
return self ._plugin2hookcallers .get (plugin )
305
305
306
306
def add_hookcall_monitoring (self , before , after ):
307
- """ add before/after tracing functions for all hooks
307
+ """add before/after tracing functions for all hooks
308
308
and return an undo function which, when called,
309
309
will remove the added tracers.
310
310
@@ -334,7 +334,7 @@ def undo():
334
334
return undo
335
335
336
336
def enable_tracing (self ):
337
- """ enable tracing of hook calls and return an undo function. """
337
+ """enable tracing of hook calls and return an undo function."""
338
338
hooktrace = self .trace .root .get ("hook" )
339
339
340
340
def before (hook_name , methods , kwargs ):
@@ -349,9 +349,9 @@ def after(outcome, hook_name, methods, kwargs):
349
349
return self .add_hookcall_monitoring (before , after )
350
350
351
351
def subset_hook_caller (self , name , remove_plugins ):
352
- """ Return a new :py:class:`._hooks._HookCaller` instance for the named method
352
+ """Return a new :py:class:`._hooks._HookCaller` instance for the named method
353
353
which manages calls to all registered plugins except the
354
- ones from remove_plugins. """
354
+ ones from remove_plugins."""
355
355
orig = getattr (self .hook , name )
356
356
plugins_to_remove = [plug for plug in remove_plugins if hasattr (plug , name )]
357
357
if plugins_to_remove :
0 commit comments