In Python, we would tend to use a Dependency Injection approach (one of
Uncle Bob's SOLID principles).
I have written a program which, as part of the non-core functionality, contains a module to generate email. This is currently very specific
to my organisation, so the main program contains
import myorg.mailer
This module is specific to my organisation in that it can ask an
internal server to generate individualised salutations for a given UID
which is known within the organisation.
I want to share the code with other institutions, so I would like to
1. replace the organisation-specific mailer with a generic one
2. allow an organisation-specific mailer to be used instead of the
generic one, if so desired
In Python, we would tend to use a Dependency Injection approach (one of
Uncle Bob's SOLID principles).
On 16/03/2023 01.47, Loris Bennett wrote:[snip]
I have written a program which, as part of the non-core functionality,
contains a module to generate email. This is currently very specific
to my organisation, so the main program contains
  import myorg.mailer
This module is specific to my organisation in that it can ask an
internal server to generate individualised salutations for a given UID
which is known within the organisation.
I want to share the code with other institutions, so I would like to
  1. replace the organisation-specific mailer with a generic one
  2. allow an organisation-specific mailer to be used instead of the
     generic one, if so desired
This may call for the plug-in pattern, ie the user will choose whether
to plug-in the specific, or the generic, module.
In Python, we would tend to use a Dependency Injection approach (one of
Uncle Bob's SOLID principles).
I do something similar to Thomas. (Also MIT licensed). I like objects. I like type hints.
Each plugin needs to have check and purpose functions and accepts either PluginSpec (by default) or AddonSpec if it defines addon = True
There is a PyPi library called pluggy (not used it). I've used informal >approaches using an ABC as a framework/reminder (see @George's
response).
On Thu, Mar 16, 2023 at 07:45:18AM +1300, dn via Python-list wrote:
There is a PyPi library called pluggy (not used it). I've used
informal approaches using an ABC as a framework/reminder (see
@George's response).
typing.Protocol is also useful here as the plugin interface can be
defined separately not requiring inheriting from an ABC.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 300 |
Nodes: | 16 (2 / 14) |
Uptime: | 72:44:11 |
Calls: | 6,714 |
Calls today: | 2 |
Files: | 12,246 |
Messages: | 5,357,083 |