You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							85 lines
						
					
					
						
							1.9 KiB
						
					
					
				
			
		
		
	
	
							85 lines
						
					
					
						
							1.9 KiB
						
					
					
				| # pylint: disable=no-self-argument
 | |
| from configspec import *
 | |
| from shepherd import PluginInterface, plugin_class, plugin_function, plugin_hook, plugin_attachment
 | |
| 
 | |
| """
 | |
| Plugin to test the plugin class systems and the various decorator markers
 | |
| """
 | |
| 
 | |
| 
 | |
| interface = PluginInterface()
 | |
| 
 | |
| 
 | |
| confspec = ConfigSpecification()
 | |
| confspec.add_spec("spec1", StringSpec(helptext="helping!"))
 | |
| 
 | |
| 
 | |
| @plugin_function
 | |
| def module_function(a):
 | |
|     return F"module func {a}"
 | |
| 
 | |
| 
 | |
| @plugin_hook
 | |
| def module_hook(a, b):
 | |
|     pass
 | |
| 
 | |
| 
 | |
| @plugin_attachment("module_hook")
 | |
| def module_attachment(a, b):
 | |
|     return F"module attachment {a} {b}"
 | |
| 
 | |
| 
 | |
| @plugin_class
 | |
| class ClassPlugin():
 | |
|     def __init__(self):
 | |
|         self.config = interface.config
 | |
|         self.interface = interface
 | |
|         self.plugins = interface.plugins
 | |
|         self.hooks = interface.hooks
 | |
| 
 | |
|     # Interface functions
 | |
|     @plugin_function
 | |
|     def instance_method(self, a):
 | |
|         return F"instance method {a}"
 | |
| 
 | |
|     @plugin_function
 | |
|     @classmethod
 | |
|     def class_method(cls, a):
 | |
|         return F"class method {a}"
 | |
| 
 | |
|     @plugin_function
 | |
|     @staticmethod
 | |
|     def static_method(a):
 | |
|         return F"static method {a}"
 | |
| 
 | |
|     # Hooks
 | |
|     @plugin_hook(name="instance_hook")
 | |
|     def instance_hook_name(a, b):
 | |
|         pass
 | |
| 
 | |
|     @plugin_hook
 | |
|     @staticmethod
 | |
|     def static_hook(a, b):
 | |
|         pass
 | |
| 
 | |
|     @plugin_hook
 | |
|     @staticmethod
 | |
|     def static_hook2(a, b):
 | |
|         pass
 | |
| 
 | |
|     # Attachments (these are bound before attachment, so self and cls work as normal, and are
 | |
|     # not included in the signature)
 | |
|     @plugin_attachment("instance_hook")
 | |
|     def instance_attach(self, a, b):
 | |
|         return F"instance attachment {a} {b}"
 | |
| 
 | |
|     @plugin_attachment("static_hook2")
 | |
|     @classmethod
 | |
|     def class_attach(cls, a, b):
 | |
|         return F"class attachment {a} {b}"
 | |
| 
 | |
|     @plugin_attachment("classtestplugin.static_hook")
 | |
|     @staticmethod
 | |
|     def static_attach(a, b):
 | |
|         return F"static attachment {a} {b}"
 |