Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

To live is always desirable. -- Eleen the Capellan, "Friday's Child", stardate 3498.9


devel / comp.lang.python / Re: Implementing a plug-in mechanism

SubjectAuthor
* Implementing a plug-in mechanismLoris Bennett
+- Re: Implementing a plug-in mechanismWeatherby,Gerard
+* Re: Implementing a plug-in mechanismdn
|+- Re: Implementing a plug-in mechanismStefan Ram
|`- Re: Implementing a plug-in mechanismStefan Ram
+- Re: Implementing a plug-in mechanismThomas Passin
+- Re: Implementing a plug-in mechanismWeatherby,Gerard
+- Re: Implementing a plug-in mechanismThomas Passin
`* Re: Implementing a plug-in mechanismSimon Ward
 `- Re: Implementing a plug-in mechanismLoris Bennett

1
Implementing a plug-in mechanism

<87wn3iqiz4.fsf@hornfels.zedat.fu-berlin.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=22438&group=comp.lang.python#22438

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: loris.be...@fu-berlin.de (Loris Bennett)
Newsgroups: comp.lang.python
Subject: Implementing a plug-in mechanism
Date: Wed, 15 Mar 2023 13:47:43 +0100
Organization: ZEDAT, Freie Universität Berlin
Lines: 26
Message-ID: <87wn3iqiz4.fsf@hornfels.zedat.fu-berlin.de>
Mime-Version: 1.0
Content-Type: text/plain
X-Trace: news.uni-berlin.de hZHUE5o/0IoaxLtXrR8QZAzTdvp5xMfZ9VubwgsPHIE8Hk
Cancel-Lock: sha1:ysEIDlQWfsqF28BB91CyzQlrvdQ=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
 by: Loris Bennett - Wed, 15 Mar 2023 12:47 UTC

Hi,

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

Is importlib the way to go here or is there another approach?

Cheers,

Loris
--
This signature is currently under constuction.

Re: Implementing a plug-in mechanism

<mailman.2333.1678900753.20444.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=22448&group=comp.lang.python#22448

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: gweathe...@uchc.edu (Weatherby,Gerard)
Newsgroups: comp.lang.python
Subject: Re: Implementing a plug-in mechanism
Date: Wed, 15 Mar 2023 17:18:52 +0000
Lines: 47
Message-ID: <mailman.2333.1678900753.20444.python-list@python.org>
References: <87wn3iqiz4.fsf@hornfels.zedat.fu-berlin.de>
<SJ0PR14MB5864E9733F83AB49A333123CB9BF9@SJ0PR14MB5864.namprd14.prod.outlook.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable
X-Trace: news.uni-berlin.de Iq45celM3RZeAQZygcplIg67MH7lMxjW5tTjQhSV946g==
Return-Path: <prvs=0438124b24=gweatherby@uchc.edu>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=uchc.edu header.i=@uchc.edu header.b=WQJcJ416;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.050
X-Spam-Evidence: '*H*': 0.90; '*S*': 0.00; 'class,': 0.05; '2023':
0.07; 'approach?': 0.09; 'mechanism': 0.09; 'module.': 0.09;
'organisation': 0.09; 'received:namprd14.prod.outlook.com': 0.09;
'cheers,': 0.11; 'import': 0.15; 'url:mailman': 0.15; '***': 0.16;
'bennett': 0.16; 'non-core': 0.16;
'received:nam02-sn1-obe.outbound.protection.outlook.com': 0.16;
'uid': 0.16; 'url:urldefense': 0.16; 'url:v3': 0.16; 'which,':
0.16; 'instead': 0.17; 'to:addr:python-list': 0.20; 'written':
0.22; 'code': 0.23; 'to:name:python-list@python.org': 0.24;
'url:listinfo': 0.25; 'opening': 0.26; 'received:edu': 0.26;
'wednesday,': 0.26; 'email addr:python.org&gt;': 0.28; 'module':
0.31; 'program': 0.31; 'python-list': 0.32; 'there': 0.33;
'march': 0.33; 'server': 0.33; 'header:In-Reply-To:1': 0.34;
'yes,': 0.35; 'header:Received:8': 0.36; 'couple': 0.37;
'received:filterd': 0.37; 'received:pps.filterd': 0.37;
'currently': 0.37; 'main': 0.37; 'url-ip:13.107/16': 0.38; 'way':
0.38; 'date:': 0.39; 'use': 0.39; 'base': 0.40; 'want': 0.40;
'charset:windows-1252': 0.60; 'email.': 0.61; 'skip:o 10': 0.61;
'from:': 0.62; 'to:': 0.62; 'skip:i 20': 0.62; 'here': 0.62;
'internal': 0.63; 'skip:o 20': 0.63; 'share': 0.63; 'your': 0.64;
'url-ip:104.18/16': 0.67; 'url-ip:52.6/16': 0.69; 'within': 0.69;
'url-ip:lookup error': 0.70; 'clicking': 0.76; 'signature': 0.76;
'links.': 0.81; 'known': 0.84; 'attention:': 0.84; 'email name:&lt
;python-list': 0.84; 'i\x92ve': 0.84; 'skip:& 50': 0.84
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=uchc.edu;
h=from : to : subject :
date : message-id : references : in-reply-to : content-type :
mime-version; s=UCHC03162020;
bh=jzya19UNfQ+HLEp9vJMjz4l/myX6WmonBicRvfPyE7c=;
b=WQJcJ416DhVG7RCb5jDn1f71c2XpBzK1OVkwHsmNF73/0vfywMR2wxEPjtwwpQRgEiRe
EyCcDOUbxSx+kBarHWMIuUxh74Q8H/eXqFwI6P4X5nVdKgju2Joh6tXZrz/xA294Mi6N
vuxJpozBg8H1me3T0HWItpuuPvxbeZBzifMc2eMJWr53F67OhdCcAj43+mM7smFtZ/eM
l4+8gCN0p1BXK8mQVnVpK1p2oOEtshgQEqp/kyarnQ+39FGWy8WPDSPVqqZE6crOACNo
FzcuvL2ByO7+VScjJ+Yx4B6Ps/WfjGrkbKK6hauLMz5wqYvxBrO5VbnsO9WqA6A1eZBP hA==
ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none;
b=D2+2TwR+rPgklCVsVrP7M4smn2mA919v/NycBE/OjuC0AG+qY5xoifyrnxwlAm5Cyk8KXWcImgCbqiZQGyI2z5kh17sYV2S4ZH3yCayWY/lj9PC6pnpHRYPsdDu4bnHdPmegaPYkIQjTh9/GSOjy4GtUrwAweGlfba/XAt4AeE1LLsXYALy4SMcN5N3UmkupLQdLwh4wHUtpnbkJ7iLd1egZ7YC/T1hP2SV7CFpXx73ucTEbz4mF1PPtVDgUJr77kA/ttjGdFqDAXJkza31jxpYrMImepJKhYDqkbMjvhRVE3X6ROlE0hSegYwEf+VIUgF4IwJEFK0yqYUdM6uy3JQ==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com;
s=arcselector9901;
h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1;
bh=jzya19UNfQ+HLEp9vJMjz4l/myX6WmonBicRvfPyE7c=;
b=lZPW56XjstLuxkR63R51zKZ84Yq2IlY4RKshFOUOhBS898iVAFAkNH+PA5hXA6jzSONPSba5EraBkJy8f/aNB8DxIeeANIEKxMOg8u42MNVqunP/7Vd28iNOY0wY8yKsFTshR0n5TngIy+vStxqsbX+DFcevseIQvyyLHc2kkkZRQqjn8Sb4Cb9TuiqPlJqif02VtZ3nGQe3fR85VlV8Iq12VUwgN5ShAN6Ve8LjdkxYAZTDh5G+vLDcyz5KAjMRjGNYNUcXzdpwP511AqLgkF3ziVfWQTnF1/T2qPt1cUkCmvlw/pxSXMccW1Ul6sBy4bAGg2aA/fhOum7p6hVLjg==
ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass
smtp.mailfrom=uchc.edu; dmarc=pass action=none header.from=uchc.edu;
dkim=pass header.d=uchc.edu; arc=none
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=uchc.onmicrosoft.com;
s=selector2-uchc-onmicrosoft-com;
h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck;
bh=jzya19UNfQ+HLEp9vJMjz4l/myX6WmonBicRvfPyE7c=;
b=GFDg+6wiM2A7jpXNwnnmUVG1I1AbrLMuWOd1rnYfdum571TiCjkci946NaATc/NB8poS6QmVv6gUtyT0LppsTG9OvPuGJ7zgcJTjPIHsUmLR90BUKrxPkV385pMuajv7lZ+NKE5MZ5rzCDmnHbaSp7/Lr2ROGXTjkfGoo5bwuOM=
Thread-Topic: Implementing a plug-in mechanism
Thread-Index: AQHZV2AaIf1srRZA50Ok+wkRWAmYgq78FQ+S
In-Reply-To: <87wn3iqiz4.fsf@hornfels.zedat.fu-berlin.de>
Accept-Language: en-US
Content-Language: en-US
X-MS-Has-Attach:
X-MS-TNEF-Correlator:
x-ms-publictraffictype: Email
x-ms-traffictypediagnostic: SJ0PR14MB5864:EE_|MW5PR14MB5499:EE_
x-ms-office365-filtering-correlation-id: dd33ee42-2f0e-40d4-3f1c-08db25795949
x-ms-exchange-senderadcheck: 1
x-ms-exchange-antispam-relay: 0
x-microsoft-antispam: BCL:0;
x-microsoft-antispam-message-info: 2WPd943mYFYpjsjkG7Anronuqov/B1xt/dcQuOwP02Jygl2vwnRQLd0L8kaJN9XQlvNovNAxib3EZ0SGau9bLsxf4YKbuopoLDoTXc7S9iV64HCnQvyGB8o5cHRsrD1s2gEyrNJDn797SXH8toNELE3ePXatrqzap9UIrAJ6+sPt7qCe0dLs0F1/AiFw5waWcHpehpG/YtpAsOjOAciIKT5n5waisNyMyejb0lG0ItIfU1vufNaYVBl+2XmMDB9dw9QiMJ/48ZtlslozCRziJFVWCO4O6w86GYFb3ONEQZR1nXAC/YdHdtImfVY8Px99BrFdXGzG9WG5VqGeYu3TEPo5gVH2KU72Hmo+XU9TF/Ne8zSyjWzNixPdsGjTJVms6HFbzg5rXUurblBCnagEamcoyv8MxgX/GU3+1VT5R7wX97sOqlhdm9f1okSMZiWpuohhc0hqvsrJ7OjCiBmzKQzx5mdWQ+Sy0+cW6JeMBHfRfhX10QVtgYMqh0ks5ZTpv3yViT8VjK+/GkNS37HzWMgjBTJj7nf6dcVMekLGrEZBxmswBNCFDuyl4Y8Io6Rse4K1rqDTLFPnwKuoQ1WjK4t6T6TZmCrgnwOCFJ6Lzh5dyEYZy0rm0euVRTtNJS5qw2SAeMjmiMWyI9UJAZpQ/Y7wNXMCgUu9/zecYiD+xCQNItVX+uPUPOLzOmfp82B6
x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:;
IPV:NLI; SFV:NSPM; H:SJ0PR14MB5864.namprd14.prod.outlook.com; PTR:; CAT:NONE;
SFS:(13230025)(136003)(366004)(39860400002)(396003)(376002)(346002)(451199018)(166002)(186003)(55016003)(38070700005)(110136005)(38100700002)(786003)(86362001)(316002)(75432002)(33656002)(122000001)(3480700007)(41320700001)(26005)(53546011)(6506007)(9686003)(5660300002)(71200400001)(52536014)(966005)(8936002)(41300700001)(8676002)(66446008)(66476007)(478600001)(2906002)(66556008)(66946007)(7696005)(76116006)(91956017)(21615005)(64756008);
DIR:OUT; SFP:1101;
x-ms-exchange-antispam-messagedata-chunkcount: 1
x-ms-exchange-antispam-messagedata-0: U60OF9ZP3Xv+0koRtYFKFMHv96uFxF9efNUeL7rBzOzgIpOc4u1cgIED
Fvwf71OzQvru5eKaV+RNJfBjUGs0pDB8FIiiXPxGFQe9/SwpWQDsUj56
I/ndRN4P45WjqyH0MuPQ6AxB+0NIvOHHm35lphf2VAWgEeNgWpUyPZHI
61TJOU/IDKGoMJ37UJozIvf3OQzEGlq3/ntpTA/A4/7aAMfY8qsyaEVf
JuJoXG94l2igKXrAHtOWCD2p9u35Mr5qoOfJXBCWUZUg5kztAhGm+JEO
p8JhV3xoGuLS/+NGT1lCPb2DQ1UFkuAAWALlKxey+5nDwcbgovaZzYfA
FcLtPELOcTDQ3UPgvmnN+lcx5mCheyfSwBMupjxR6B0dN007U6xtTmem
7r7T4AUhTvowpKGF547/EuQ9o1myEVaMqOQ2PA2wqQFZTKFJ8xZnfYkq
fkyJdZeLAMUGu3OVMuC1phLn1H2cN9AX65qZWaJO9kPIVsDIfSMQ1ET9
a+gszjFQ7xkG5OBGx4y33D//wUGUDp0isshcmI2SDQ6kYRpgUsjNPzOR
VnNJlkXX5BMPdw0q22mG+1bwXqlGF4fBplq9rzztP8h6lk2UARcSLEl0
x4n5SErWAqvYv/wWb8trbaSCvUEg6cBZT9j8lqrPDHwpRQ9Gn/Il9TRZ
JnVUVbOilU5h8fsXr5qN5V+XY6Vj4OooV+2QUWiWhZOGYLO7yRKy2veJ
MkL9iLJTfxLcx6phkHymvvldGGqmF5q5LhrXi5YkGc6xjm3eOc4uvUsb
vpnCziD5oaxCTE/d9WR5AS8FTdWfiYhTabwpJRmAB2nN0NmAzlzdxaIg
3lykmIDzriH6Jiw2Qmvhdc7az9l7FDMj1vjLx/4Va/FTcXJwKgIjmpN1
XOWY3wYwc0HLtBG4CbBUmb+VgAutHajPtJkI8IldjExtbyHjMvNrLLnc
kIGzn/FNy2UW9c6jSJ44ZrbMkVs2xO4Z/pQYjP6dALsoxMf+VpCeuZEd
TFY5A7VXQ9gr8+o2z9zs+PsCe6sCHZ6tcmVC29+G7+oBVCaBHHoJHwa5
/OnUx+go0YTh5S0KQT/Lehurj0tdv4A87qnNAmSo94pqVfAxKXfX1t16
X3Mnkmw9QcffYbD+LBVDWPt/rgsIOg4lFhzEKl3DOGphPnaMyP1rmmlM
el2nx/ugUbUppHTeixQ1SljbBd6MOcpy6LW9lFkmaOIad5wXmMCZ6mvJ
vxv53AlisriOpTb8I7tIpSsPqepivsMoplfyzCwjyftMBmiDbGvKJ3Ey
1rSnzuivHnotl1YBCMKp2TXUdjRHVONcLVgJGIaG4VNy5iBus5e+tt31
JHvDr67rApLl8B5Sm+06I11Xn+uyEGQxBU6O9yKJ1F9J4oJbrUM2FiPe
ryJ0vrfLjR+y0cOFL6uQbUpEfwIBrFPAwJ8WtNCqxiKxGfP8fq69x6Tt
2mwMTXxOC+v/O4dNEnWI3Zor8TWoTtGPfzBtyFUvml6ZWDwlA5lGn708
prusyKB3cUfLo4Hz7CyQW3bq85CjoHQx3XuYanm5enz8XukWIkTeBJF4
q48VAVEujwPLq8ccdG1neGdMpane/eCal5c3uwu82K04XCe5skPjig
==
X-MS-Exchange-CrossTenant-AuthAs: Internal
X-MS-Exchange-CrossTenant-AuthSource: SJ0PR14MB5864.namprd14.prod.outlook.com
X-MS-Exchange-CrossTenant-Network-Message-Id: dd33ee42-2f0e-40d4-3f1c-08db25795949
X-MS-Exchange-CrossTenant-originalarrivaltime: 15 Mar 2023 17:18:52.1819 (UTC)
X-MS-Exchange-CrossTenant-fromentityheader: Hosted
X-MS-Exchange-CrossTenant-id: 5c82d83a-818a-4c16-b540-ded2344a7ad3
X-MS-Exchange-CrossTenant-mailboxtype: HOSTED
X-MS-Exchange-CrossTenant-userprincipalname: Iyb23uClrWU9jUU48wg/wovuPEZlZnbWvQ87hIpCQLeqUpijuCWtn84uk9VVn6nEK4hyt4MsdL96nDxlS2Oo4A==
X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW5PR14MB5499
X-Proofpoint-GUID: IcniBAalxAQ9Pj-lAmxi5qZrue7cHLNl
X-Proofpoint-ORIG-GUID: IcniBAalxAQ9Pj-lAmxi5qZrue7cHLNl
X-Proofpoint-Virus-Version: vendor=baseguard
engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22
definitions=2023-03-15_08,2023-03-15_01,2023-02-09_01
X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0
lowpriorityscore=0
suspectscore=0 mlxscore=0 mlxlogscore=571 spamscore=0 malwarescore=0
impostorscore=0 phishscore=0 bulkscore=0 priorityscore=1501 adultscore=0
clxscore=1011 classifier=spam adjust=0 reason=mlx scancount=1
engine=8.12.0-2302240000 definitions=main-2303150144
X-Content-Filtered-By: Mailman/MimeDel 2.1.39
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <SJ0PR14MB5864E9733F83AB49A333123CB9BF9@SJ0PR14MB5864.namprd14.prod.outlook.com>
X-Mailman-Original-References: <87wn3iqiz4.fsf@hornfels.zedat.fu-berlin.de>
 by: Weatherby,Gerard - Wed, 15 Mar 2023 17:18 UTC

Yes, that works, and I’ve used that on a couple of projects.

Another alternative is defining an Abstract Base Class, https://docs.python..org/3/library/abc.html, and having an institution-specific implementation passed into your module.

From: Python-list <python-list-bounces+gweatherby=uchc.edu@python.org> on behalf of Loris Bennett <loris.bennett@fu-berlin.de>
Date: Wednesday, March 15, 2023 at 1:03 PM
To: python-list@python.org <python-list@python.org>
Subject: Implementing a plug-in mechanism
*** Attention: This is an external email. Use caution responding, opening attachments or clicking on links. ***

Hi,

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

Is importlib the way to go here or is there another approach?

Cheers,

Loris

--
This signature is currently under constuction.
--
https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!izCZs2X5PFeGpCF4TrtdDABzPqCFFT5i89Zsu-msRJAIpyWZYybdHDOFdxno9J3JvpNsRRQK9w72qgYj0MjlB2L-LsVXW1o$<https://urldefense.com/v3/__https:/mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!izCZs2X5PFeGpCF4TrtdDABzPqCFFT5i89Zsu-msRJAIpyWZYybdHDOFdxno9J3JvpNsRRQK9w72qgYj0MjlB2L-LsVXW1o$>

Re: Implementing a plug-in mechanism

<mailman.2334.1678906282.20444.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=22449&group=comp.lang.python#22449

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: PythonL...@DancesWithMice.info (dn)
Newsgroups: comp.lang.python
Subject: Re: Implementing a plug-in mechanism
Date: Thu, 16 Mar 2023 07:45:18 +1300
Organization: DWM
Lines: 35
Message-ID: <mailman.2334.1678906282.20444.python-list@python.org>
References: <87wn3iqiz4.fsf@hornfels.zedat.fu-berlin.de>
<f7c8f51b-e371-7a6a-c025-3fc0b69cd8ab@DancesWithMice.info>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de b9Aw6i4jLz0YIEcUET51iAm1oJX+h5uEEYENSnN1zZBA==
Return-Path: <PythonList@DancesWithMice.info>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=danceswithmice.info header.i=@danceswithmice.info
header.b=ekpin6FG; dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.004
X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'pypi': 0.05;
'url:courses': 0.07; '=dn': 0.09; 'approaches': 0.09;
'from:addr:danceswithmice.info': 0.09; 'from:addr:pythonlist':
0.09; 'module.': 0.09; 'organisation': 0.09; 'import': 0.15;
'bennett': 0.16; 'message-id:@DancesWithMice.info': 0.16; 'non-
core': 0.16; 'received:51.254': 0.16; 'received:51.254.211': 0.16;
'received:51.254.211.219': 0.16; 'received:cloud': 0.16;
'received:rangi.cloud': 0.16; 'uid': 0.16; 'which,': 0.16;
'wrote:': 0.16; 'instead': 0.17; 'to:addr:python-list': 0.20;
'written': 0.22; "i've": 0.22; 'code': 0.23; 'python,': 0.25;
'discussion': 0.25; 'library': 0.26; 'pattern': 0.26; 'header
:User-Agent:1': 0.30; 'approach': 0.31; 'module': 0.31;
'header:Organization:1': 0.31; 'program': 0.31;
'received:192.168.1': 0.32; 'there': 0.33; 'server': 0.33; 'header
:In-Reply-To:1': 0.34; 'currently': 0.37; 'main': 0.37; 'using':
0.37; 'received:192.168': 0.37; 'use': 0.39; '(see': 0.40; 'want':
0.40; 'email.': 0.61; 'skip:o 10': 0.61; "there's": 0.61;
'internal': 0.63; 'skip:o 20': 0.63; 'share': 0.63; 'received:51':
0.64; 'url-ip:104.18/16': 0.67; 'choose': 0.67; 'within': 0.69;
'known': 0.84; 'practical': 0.84; 'tend': 0.91
DKIM-Filter: OpenDKIM Filter v2.11.0 vps.rangi.cloud C1C5D5C1A
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=danceswithmice.info;
s=staff; t=1678905928;
bh=PzB51aA5nm+BEHghSxbMuLW9ME0UkX7u0ZWAMBtPfCs=;
h=Date:Subject:To:References:From:In-Reply-To:From;
b=ekpin6FGAG2aFdZzwFW6o3QMsCG3EaMHKQxKrTnNGCgWWPFmITwp2VvW4Zaus7emJ
8HHMbtq6qmtUz6bEpvDLgTLD1kp0mJb8+PC+Rxq+zYaBSaE+m1z890JigMbgYtaCtn
jAOB4wfP2IGj6/ABr/iN390HqX5X3mA1ZAmskGPy6FCObtZCE9vU8qg6VOBzniul2y
uDgZ8JsaT3HJqvkPY06vf/9NUyW1PGhVqbY3jckijFCtp1k3AaWkQzrucIyxXNnihx
2iA3iOPq/yRSWvNSwsVyLjLDUPVzo9Q/+IxOEFOtCIgvbw9PY9mWvzYzj60MHIicqR
KU3E7gQm58mWQ==
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.8.0
Content-Language: en-GB
In-Reply-To: <87wn3iqiz4.fsf@hornfels.zedat.fu-berlin.de>
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <f7c8f51b-e371-7a6a-c025-3fc0b69cd8ab@DancesWithMice.info>
X-Mailman-Original-References: <87wn3iqiz4.fsf@hornfels.zedat.fu-berlin.de>
 by: dn - Wed, 15 Mar 2023 18:45 UTC

On 16/03/2023 01.47, Loris Bennett wrote:
> 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).

There's a rather abstract description of the plugin pattern at
https://martinfowler.com/eaaCatalog/plugin.html

OpenClassrooms has a more practical discussion at
https://openclassrooms.com/en/courses/6397806-design-your-software-architecture-using-industry-standard-patterns/6896171-plug-in-architecture

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).

--
Regards,
=dn

Re: Implementing a plug-in mechanism

<plugin-20230315201022@ram.dialup.fu-berlin.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=22450&group=comp.lang.python#22450

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!news.szaf.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram...@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.lang.python
Subject: Re: Implementing a plug-in mechanism
Date: 15 Mar 2023 19:11:44 GMT
Organization: Stefan Ram
Lines: 23
Expires: 1 Apr 2024 11:59:58 GMT
Message-ID: <plugin-20230315201022@ram.dialup.fu-berlin.de>
References: <87wn3iqiz4.fsf@hornfels.zedat.fu-berlin.de> <mailman.2334.1678906282.20444.python-list@python.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de BsEycaUC0bLcTV45LlfcowJp2yHIU3xj4I+e7VEaTjO74w
X-Copyright: (C) Copyright 2023 Stefan Ram. All rights reserved.
Distribution through any means other than regular usenet
channels is forbidden. It is forbidden to publish this
article in the Web, to change URIs of this article into links,
and to transfer the body without this notice, but quotations
of parts in other Usenet posts are allowed.
X-No-Archive: Yes
Archive: no
X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some
services to mirror the article in the web. But the article may
be kept on a Usenet archive server with only NNTP access.
X-No-Html: yes
Content-Language: en-US
Accept-Language: de-DE-1901, en-US, it, fr-FR
 by: Stefan Ram - Wed, 15 Mar 2023 19:11 UTC

dn <PythonList@DancesWithMice.info> writes:
>In Python, we would tend to use a Dependency Injection approach (one of
>Uncle Bob's SOLID principles).

What's wrong with (untested pseudo code):

import os

try:
import plugin
except ModuleNotFoundError:
plugin = None
print( f'No file "plugin.py" in "{os.getcwd()}".' )
print( f'This is no error.\n' )

greeting = "Hello World!"
if plugin: greeting = plugin.greeting

print( greeting )

?

Re: Implementing a plug-in mechanism

<plugin-20230315204207@ram.dialup.fu-berlin.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=22453&group=comp.lang.python#22453

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram...@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.lang.python
Subject: Re: Implementing a plug-in mechanism
Supersedes: <plugin-20230315201022@ram.dialup.fu-berlin.de>
Date: 15 Mar 2023 19:43:38 GMT
Organization: Stefan Ram
Lines: 24
Expires: 1 Apr 2024 11:59:58 GMT
Message-ID: <plugin-20230315204207@ram.dialup.fu-berlin.de>
References: <87wn3iqiz4.fsf@hornfels.zedat.fu-berlin.de> <mailman.2334.1678906282.20444.python-list@python.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de oskFlqefXQS0VbJpnHVZWA6waq/GDu1CgnUAiznCuk6mnY
X-Copyright: (C) Copyright 2023 Stefan Ram. All rights reserved.
Distribution through any means other than regular usenet
channels is forbidden. It is forbidden to publish this
article in the Web, to change URIs of this article into links,
and to transfer the body without this notice, but quotations
of parts in other Usenet posts are allowed.
X-No-Archive: Yes
Archive: no
X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some
services to mirror the article in the web. But the article may
be kept on a Usenet archive server with only NNTP access.
X-No-Html: yes
Content-Language: en-US
Accept-Language: de-DE-1901, en-US, it, fr-FR
 by: Stefan Ram - Wed, 15 Mar 2023 19:43 UTC

Supersedes: <plugin-20230315201022@ram.dialup.fu-berlin.de>
[started to use "sys.path" in the message]

dn <PythonList@DancesWithMice.info> writes:
>In Python, we would tend to use a Dependency Injection approach (one of
>Uncle Bob's SOLID principles).

What's wrong with (untested pseudo code):

try:
import plugin
except ModuleNotFoundError:
plugin = None
print( f'No file "plugin.py" in my sys.path.' )
print( f'This is no error.\n' )

greeting = "Hello World!"
if plugin: greeting = plugin.greeting

print( greeting )

?

Re: Implementing a plug-in mechanism

<mailman.2335.1678909459.20444.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=22454&group=comp.lang.python#22454

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: lis...@tompassin.net (Thomas Passin)
Newsgroups: comp.lang.python
Subject: Re: Implementing a plug-in mechanism
Date: Wed, 15 Mar 2023 15:42:10 -0400
Lines: 62
Message-ID: <mailman.2335.1678909459.20444.python-list@python.org>
References: <87wn3iqiz4.fsf@hornfels.zedat.fu-berlin.de>
<f7c8f51b-e371-7a6a-c025-3fc0b69cd8ab@DancesWithMice.info>
<6dd3ac28-d877-d5bf-a2b3-7fc72f2292c1@tompassin.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de 3ctiMyJjdJvQiKCt60HpmAFv5iw7tLart9yXmACJyPIw==
Return-Path: <list1@tompassin.net>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=tompassin.net header.i=@tompassin.net header.b=pK/FkVOF;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.004
X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'def': 0.04; 'variable':
0.05; 'modules': 0.07; '"""': 0.09; 'adapt': 0.09; 'module.':
0.09; 'modules.': 0.09; 'organisation': 0.09;
'received:23.83.212': 0.09; 'received:elm.relay.mailchannels.net':
0.09; 'import': 0.15; '"""import': 0.16; '[snip]': 0.16;
'bennett': 0.16; 'inspect': 0.16; 'like.': 0.16; 'non-core': 0.16;
'received:10.0.0': 0.16; 'received:64.90': 0.16;
'received:64.90.62': 0.16; 'received:64.90.62.162': 0.16;
'received:dreamhost.com': 0.16; 'uid': 0.16; 'which,': 0.16;
'wrote:': 0.16; 'instead': 0.17; 'pm,': 0.19; 'to:addr:python-
list': 0.20; 'written': 0.22; 'returns': 0.22; 'code': 0.23;
'python,': 0.25; 'project.': 0.27; 'header:User-Agent:1': 0.30;
'approach': 0.31; 'convention': 0.31; 'module': 0.31; 'program':
0.31; 'empty': 0.32; 'python-list': 0.32; 'received:10.0': 0.32;
'received:mailchannels.net': 0.32;
'received:relay.mailchannels.net': 0.32; "i'm": 0.33; 'there':
0.33; 'server': 0.33; 'header:In-Reply-To:1': 0.34; 'one.': 0.35;
'files': 0.36; 'currently': 0.37; 'main': 0.37; 'using': 0.37;
'directory': 0.37; 'could': 0.38; 'otherwise': 0.39; 'list': 0.39;
'use': 0.39; 'break': 0.39; 'files.': 0.40; 'want': 0.40; 'skip:o
10': 0.61; 'here': 0.62; 'internal': 0.63; 'skip:o 20': 0.63;
'feel': 0.63; 'share': 0.63; 'listed': 0.67; 'header:Received:6':
0.67; 'choose': 0.67; 'received:64': 0.67; 'files:': 0.69;
'within': 0.69; 'free': 0.72; 'mit': 0.76; 'known': 0.84;
'license,': 0.84; '\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0':
0.84; 'tend': 0.91
X-Sender-Id: dreamhost|x-authsender|tpassin@tompassin.net
ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1678909449; a=rsa-sha256;
cv=none;
b=AwHNLJ1IOut7nNOTcKgkVRhgzhacfA2V56hIZJHkJGYYbXckbboq43zFqULzFs6GcIpWSZ
2d1CEYSiTJ20fQVTuXqlIX5KE6iNu0IZ3F8Xh9lfCTqXaDxv/MMaDOx9LULnYUtH3iZwC6
InDY99vHzlR54RljbE+xkbCQZ6G70tlxBG48big6UpJJenlzh3shQYMGpwpI5l0DWA6Wct
0Qdh3pKoihPF+jS8HFrafTt79cIqhwTQ40L0xOm4lvyN/7MPpJUToffTsXg/Q7qf+BBQGj
moicgYWDDeEHZcTn3TTKM5JZ5+9wS5nhBtCY87Vi03J49YOGuzmhcEbSHhJaRw==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed;
d=mailchannels.net; s=arc-2022; t=1678909449;
h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
to:to:cc:mime-version:mime-version:content-type:content-type:
content-transfer-encoding:content-transfer-encoding:
in-reply-to:in-reply-to:references:references:dkim-signature;
bh=9nXTJZDEwSDoQPPqsEHC7XEaYMJdOlqKz1sCC9bxRsk=;
b=+CXpe00u3tp0go9lZdkdA6GHfp8av/JA4o+r8hXOHCLE5MF68F5b9F1bcPoimLgw4gZP1r
v6K1nfyAmlNBX7ZjqDhRkjaSeUuGrTm82mW2O0H2WOTfA8jxjovOfWqdaU6/IlKXaJ8GZw
rUUC4cqKFgw57z2TdourZVbESOWJCV+TDGB7uo9SERuWgGbB0SkguluyzGgq1fOArQlOYJ
eE4HXJyVkQietsJnaqV3hIfUaH3CZdVEz1Z9VNag0I0WagaOzzlAOah6E4QQIIrWW86tGS
hhkpT3OEaix6Bgfc/e6SIAVdOO5H4aKsCJMi+WOXNCkxCv3seFL64r8J9+Da6w==
ARC-Authentication-Results: i=1; rspamd-59dbd69698-mgnpd;
auth=pass smtp.auth=dreamhost smtp.mailfrom=list1@tompassin.net
X-Sender-Id: dreamhost|x-authsender|tpassin@tompassin.net
X-MC-Relay: Neutral
X-MailChannels-SenderId: dreamhost|x-authsender|tpassin@tompassin.net
X-MailChannels-Auth-Id: dreamhost
X-Tasty-Cold: 3a7522990747db45_1678909449264_1039991616
X-MC-Loop-Signature: 1678909449264:3015450600
X-MC-Ingress-Time: 1678909449264
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tompassin.net;
s=dreamhost; t=1678909448;
bh=9nXTJZDEwSDoQPPqsEHC7XEaYMJdOlqKz1sCC9bxRsk=;
h=Date:Subject:To:From:Content-Type:Content-Transfer-Encoding;
b=pK/FkVOFp3Lbk9gs+/1KTDTWU22m44rppv1C5KdJQZtXQwesQK4GbZeqdsghkmW/U
ZQAgdS2skxpfJ55ZX3UxQRoLYGION15Rbz/TcXY9yBggE+qWLVIXK+kfhpbp+bwQHc
IkK3rJZ9qyFJ1Pp8+/9KkpmEf4kYfll5/g/OL0NFGdTgGThwcOPo8a8v0sQux8Xvsg
Gp/TU4D1oYAJPoMcC7GtoybYPtH7laXY4Dui689+FY2CFuHrFTZ0yq5Z/kJLl02p7A
zpuHgrZ9FQzlr7jBRcifXmydZlv4K7V7Z3/BgGCB2M4a0hVYi/A6DisHXyAhWlTvu6
B2dftNPrRwBNQ==
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.8.0
Content-Language: en-US
In-Reply-To: <f7c8f51b-e371-7a6a-c025-3fc0b69cd8ab@DancesWithMice.info>
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <6dd3ac28-d877-d5bf-a2b3-7fc72f2292c1@tompassin.net>
X-Mailman-Original-References: <87wn3iqiz4.fsf@hornfels.zedat.fu-berlin.de>
<f7c8f51b-e371-7a6a-c025-3fc0b69cd8ab@DancesWithMice.info>
 by: Thomas Passin - Wed, 15 Mar 2023 19:42 UTC

On 3/15/2023 2:45 PM, dn via Python-list wrote:
> On 16/03/2023 01.47, Loris Bennett wrote:
>> 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).
[snip]

Here is (slightly modified) plugin code I'm using in one project. You
could use a naming convention to see if there is a plugin for a specific
organizations, or each module could contain a UID variable which you
could inspect to find the desired one. This code is under the MIT
License, so feel free to adapt it if you like.

def import_all_plugins(plugins_import_list, plugin_dir):
"""Import modules from the plugins directory and return a list of them.

If plugins_import_list is not empty or None, only import the ones
listed there. Otherwise import all ".py" files.

RETURNS
a list of successfully imported modules.
"""
modules = []

if not plugins_import_list:
plugins_import_list = []
for root, dirs, files in os.walk(plugin_dir):
if root == plugin_dir:
break
for f in files:
f, ext = os.path.splitext(f)
if ext == '.py':
plugins_import_list.append(f)

for f in plugins_import_list:
try:
mod = importlib.import_module(f'plugins.{f}')
modules.append(mod)
except ImportError as e:
print(f'{__name__}: {f} plugin: {e}')
continue
return modules

Re: Implementing a plug-in mechanism

<mailman.2336.1678919116.20444.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=22456&group=comp.lang.python#22456

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: gweathe...@uchc.edu (Weatherby,Gerard)
Newsgroups: comp.lang.python
Subject: Re: Implementing a plug-in mechanism
Date: Wed, 15 Mar 2023 22:06:18 +0000
Lines: 54
Message-ID: <mailman.2336.1678919116.20444.python-list@python.org>
References: <87wn3iqiz4.fsf@hornfels.zedat.fu-berlin.de>
<f7c8f51b-e371-7a6a-c025-3fc0b69cd8ab@DancesWithMice.info>
<6dd3ac28-d877-d5bf-a2b3-7fc72f2292c1@tompassin.net>
<SJ0PR14MB5864236FA1B3AA32FE37E2B4B9BF9@SJ0PR14MB5864.namprd14.prod.outlook.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable
X-Trace: news.uni-berlin.de XXeLByQpLVM5KeC0coUcPg9ZwwOscwYe1lF772kcWb3A==
Return-Path: <prvs=0438124b24=gweatherby@uchc.edu>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=uchc.edu header.i=@uchc.edu header.b=kQVyH9dt;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.067
X-Spam-Evidence: '*H*': 0.87; '*S*': 0.00; 'def': 0.04; 'modules':
0.07; 'received:namprd14.prod.outlook.com': 0.09; 'skip:_ 20':
0.09; '(unless': 0.16; '-&gt;': 0.16; 'assert': 0.16; 'objects.':
0.16; 'scanning': 0.16; 'uses': 0.19; 'to:addr:python-list': 0.20;
'to:name:python-list@python.org': 0.24; 'object': 0.26;
'received:edu': 0.26; 'purpose': 0.28; 'module': 0.31; 'but':
0.32; 'requires': 0.34; 'header:In-Reply-To:1': 0.34; 'files':
0.36; 'functions': 0.36; 'header:Received:8': 0.36; 'name:': 0.37;
'received:filterd': 0.37; 'received:pps.filterd': 0.37; "skip:'
10": 0.37; 'class': 0.37; 'directory': 0.37; 'url-ip:13.107/16':
0.38; 'list': 0.39; 'use': 0.39; 'something': 0.40; 'should':
0.40; 'charset:windows-1252': 0.60; 'skip:o 10': 0.61; 'skip:h
10': 0.61; 'skip:o 20': 0.63; 'true': 0.63; 'similar': 0.65;
'forget': 0.67; 'url-ip:104.18/16': 0.67; 'skip:i 40': 0.68;
'mit': 0.76; 'extra': 0.84
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=uchc.edu;
h=from : to : subject :
date : message-id : references : in-reply-to : content-type :
mime-version; s=UCHC03162020;
bh=ToReWpor/ignrMEIXGUG71nOyWI3OsDx7+tGfhcxnLI=;
b=kQVyH9dt8NimBftu6aJmwt4/acCwcc/2FOKjBiG4tZHcVOcCXTwIpiQTAfpNGbhK8AZ8
SUeEeMB2iEBgzBKkNaA9YPCleapRNPj0JvweS9uEoG/1zjommz5fNnHvtov4x94+z54U
5zQYlTLZDtr3MsuFc4g0vRHMRHJLJDIHVrRqXf+gGQ3H319hX9R9lPQIkGvSX0+WkeEq
1gPfRE+aC7VlNqV4eW5JkoAyWUIGUHyJqjaBQ0c/6Y5Rjdkwhjz69GMgZp3QuNoe7kwx
LhK4EWYCIS7RPzqi6j5nfKL/U6nCbrhK3gv4SSBzJCi4aJeQHaVXkkk7BNFj/71eD2ds PQ==
ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none;
b=iDTZ015BYUECVpLzjAYbIS9tyCQ9lqm1bVzCHTE8ioHS1BX+1H/vletblZVI4CRoT0mtkOwRoXG0gb908Uacvcj1HTt/O9eYrtwqCsTTg4eagnmfcpiip27xj6KZtC9h6HuCakDsbCcwDmdMLNaIcZj25yzNOQ3UXXLCzmn1f5ZHJO3viawJxyLsFQE2aGwFlORNifxLymG+41w6t/Qgdh3R0FTmRK3bSUocqUjjjLoAc97yCQ8meX4efK6CDBuubKp6os5WrTqfN6HYK0WGav3Hd0PwWm1z8BCeFF+ydIvPWkzfgJC9Hu5bTt8MPPtUCfSDM+EH64rtQPnoVXXh5A==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com;
s=arcselector9901;
h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1;
bh=ToReWpor/ignrMEIXGUG71nOyWI3OsDx7+tGfhcxnLI=;
b=cAxG8HWig0y4z9RYE64pyFHhcZxhyMJnp+n6GdYMz9NrBzwxoHWlKrwMJj1btNG2U4btTtkmWpmUpVngNsY+jtRueXdeXBSfRivPGsZgt+rFM3xMhRgbQU67J65S0u2yCrR3T3ufspRcqXdGMkDTxFADpR6ry1nq8KA1G5UPhY/Bx1FEOdvBZsYqDBnWxXHaeiVRKZ04+udbsdE2M+0tirNYcQbd62eWA0sK7wQdowt9saIzquqiJjFz/az4S9KBjOgbjgwLwCB2uDb2zutue5GnHWqmGtHMyadEzPRe6rBGD0QU0waVqHt9AHyOiWytFlrnUTQUEv1rvKDhuZRoXA==
ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass
smtp.mailfrom=uchc.edu; dmarc=pass action=none header.from=uchc.edu;
dkim=pass header.d=uchc.edu; arc=none
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=uchc.onmicrosoft.com;
s=selector2-uchc-onmicrosoft-com;
h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck;
bh=ToReWpor/ignrMEIXGUG71nOyWI3OsDx7+tGfhcxnLI=;
b=cpb+RaRNUSWvcPbMiOpf2ygAS0QugTjk9G7ph/4FMIheWNeY7h/bCng3vAlNC5cXQHyK5WxQqkgYZl0j1EM9+0J1qH43FVEaYx2CccjuB8ezHwt/nSKaxPR9XecYOg7ETRiJiM+d1jsRqxUOt0Pq2/p9C5lfCYhmPO90v4eArbk=
Thread-Topic: Implementing a plug-in mechanism
Thread-Index: AQHZV2AaIf1srRZA50Ok+wkRWAmYgq78LdMAgAAP4wCAACWClw==
In-Reply-To: <6dd3ac28-d877-d5bf-a2b3-7fc72f2292c1@tompassin.net>
Accept-Language: en-US
Content-Language: en-US
X-MS-Has-Attach:
X-MS-TNEF-Correlator:
x-ms-publictraffictype: Email
x-ms-traffictypediagnostic: SJ0PR14MB5864:EE_|DM4PR14MB6304:EE_
x-ms-office365-filtering-correlation-id: ecc18ab9-e878-4a8e-716f-08db25a180bc
x-ms-exchange-senderadcheck: 1
x-ms-exchange-antispam-relay: 0
x-microsoft-antispam: BCL:0;
x-microsoft-antispam-message-info: +gWj4AXCM+IAn5kASw2o68bERAQkbrG/DQf7IrG7TQYmGhpuT6ysWpL4NhL+2sJ6igIrzqXUlyrM0nubW3oeOZqxaUu4UdxNqGZOeFDMaP+zwCRAbHP51dyIWl0WUI/uP5f1TerpgxW2cFXYaxaDU0dLwI8nx4GnP+7bk9pA78dcyhaeKjaN/23XJmZOO9FCkMoRNfXShvfzetLnv+2ltJ/orO3LGbEy7hOtzhYewl8ocnXbinpnrG7ZSNPSdD+g+p8WgUZ/TCWMghzSxI+wwe0Ph5mt1phdJaEE0p++//+nskjQNHVVidU+gRUeCsoEIrf+Z16apSsXZcGOwc+M5FtvgLgonVPrZBRfL6Q9cbM51xjzERoOxy0hp1DY5UhHcLNYj4V3rLlNQCeqiAqWSKbWJ1RopwgZgtjs3Hs9PjH4WjeO8ldnDd4UPnE0SRaHwXNnbpxzMhYySVfpth5SleOxgmYndvyR9KnyXATxuMCqesXgvFwCoy0AqvUDej937QglbvtQa/+annD2lS6dT6c7jk/Tpl6xtrkMxBUDbhiBHLI7VHPA9zo8VSvKT49kTvUp3fiOI1SYzNCrPjpAaKCIxsE48EfxooQByrx6AZqaDmN4RpWCc3VJgNXs0BACCdQNRc4KFHfkO88470/25IWlSbdUsqjmvFAdE/l3b/0sjPFKPWGG9FP37Kzk+55Lc/y2OcAy+ueghLdAsqvraw==
x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:;
IPV:NLI; SFV:NSPM; H:SJ0PR14MB5864.namprd14.prod.outlook.com; PTR:; CAT:NONE;
SFS:(13230025)(396003)(376002)(136003)(346002)(366004)(39850400004)(451199018)(5660300002)(64756008)(83380400001)(75432002)(316002)(6916009)(3480700007)(7696005)(478600001)(71200400001)(6506007)(26005)(9686003)(186003)(41300700001)(41320700001)(76116006)(38070700005)(91956017)(8936002)(66946007)(55016003)(66556008)(66476007)(8676002)(33656002)(66446008)(52536014)(86362001)(786003)(38100700002)(122000001)(2906002);
DIR:OUT; SFP:1101;
x-ms-exchange-antispam-messagedata-chunkcount: 1
x-ms-exchange-antispam-messagedata-0: RvHDQmYLckeY4aI5uUyqn6RjHMSEYX0EuOcl/nnijAebiTlpcIH64LLx
FoI0PQ2nbQkKbqJBbgu5wYKZv0pndcPrcX0jyUdPNeuki3ItOyMMu2m7
0VWLRGer0T7wj/fIgoNH4Fkm11G23Y4kTWJRwEZX3VRjOybltIa5/qlh
T3ttqQQZtYvD5UXj7wXDCkf0NqNqU0J5TcH3v06XoNvanGfRsDb3hOp8
23JCyR7/Z3al7EceKwVy5ICWwAfkyu7YZe/8frkEyhN/i/HfnUWjdcd7
kgJ66rmNcwBNRVTaZZ9KXNjiArGuaaKDPq3+MUgLa+eueTMudAlp43ae
sX0mHCPzqM7q2LvTYPzZnlqWm/AYv3OXRB8ALdogNwMlS/IUPKg97BIw
JLY5yvnYNEH8ODr+GmCJT0tBGcBKUMfYjmp1KXIeBmcjbEB7aIRoIyQe
idJ8da70/JSo6f7xrJfzNxT2B5gW4b4eFYxbQq1p1Kt6lQ10+KeDFsgt
gdC1rIohxrNdpPE/rPZmWMlqZGXyVLBRCsQ12prUbBsvNBQfmG+15ApK
H68evG5SlbevruJDZxx19cAVyr75ku553Y942bz/0ayTiNFc1bEnIiIA
YCM4RcpAcmOUehUENI1/W4NkfE8dBQxhdrZywymcylTzu/j6BJTE3uXG
Ku0hhOlTTkPTGnk2Cx3DhwRACTbWJDqGZFel06LOcv9Dae2OsvBGcFec
BuaFEQ96NHfyBRcjFKEf0xDw9F5aEJJifjHd9+mqE8XUxiJpI10an0cf
AQK0fwxV6L/qmVAPWS57vecmpkdvCLLnLXxq+6xNgOvGhDoeN3fMhbOK
2C2GnvOwnQzwr30+CfDIQEL5lh7VZtJoL2K5fLnq+qGnDQBgaD0AkzdP
EyDFkk8Y5F3BhZF8+Cs7T22MrW5BespmQu7TowYU4hxCHq0wIc2MV9no
UNI05Av/sDk3FQutWJNK9zGr1Cm7Y9FMyn1gb9/2/L1VqCqz1o1dKCL6
UCd5d+J6BpQTTS+ASUUfBjO2DEkFtZwpcjZsnnKiiRqd3va3mv0Oi7UT
EcDJpflChyZDNwRSCKL+nmWCISgjooUMVOApfDvbU06+Qe613e3Zf7Wx
2n3q1YzkepdT5z9bPGNFmQEAMlzhKuf84qAn9TgprlRK3xTTSguRFlJ6
rWqsFXtfF3Ekmc0P80y0TOGGXrWsbCnOY6ypro1TiNMHbgtoEdTRtmOB
LCoFjl1AjSKFivZt5jtMEdl5kD9M4BGy72MkOvDMleWFxeyYkgZcZzbv
aDfK6GNrmizQBr2N+W1KvKvgD5THXWYcX+IrO79p62nJ8UyUnlnhEJgo
ee/VMSvV2oEjfA278LzCTr1/VKggpXIk8j4anX6b5dogsUIw48yI2gp+
GktX9DLkY1pomuR8ybL/f1C5776wFeBVP0aiRUnvHkiiWPOGt9ceolGM
APJpnngJDG6MO2ObckICj7h5wKzgkhNwNnoda/F2H19hG7B1D4nb5Tld
FCOeYO1a09eBnuyQqNobpeF7NhwhoZYfwJR9EVFE6dEsUWA+zSCJxMdv
XBR/81zXgmkakP2inIj3bqhImodofcA3cEUIBXzfU0rl17W7+/Jr8g
==
X-MS-Exchange-CrossTenant-AuthAs: Internal
X-MS-Exchange-CrossTenant-AuthSource: SJ0PR14MB5864.namprd14.prod.outlook.com
X-MS-Exchange-CrossTenant-Network-Message-Id: ecc18ab9-e878-4a8e-716f-08db25a180bc
X-MS-Exchange-CrossTenant-originalarrivaltime: 15 Mar 2023 22:06:18.2228 (UTC)
X-MS-Exchange-CrossTenant-fromentityheader: Hosted
X-MS-Exchange-CrossTenant-id: 5c82d83a-818a-4c16-b540-ded2344a7ad3
X-MS-Exchange-CrossTenant-mailboxtype: HOSTED
X-MS-Exchange-CrossTenant-userprincipalname: /1cfXWyiohCSTaD4hbz/9DYys01PgAPeokFZtqq4nsfpep8xgc9HWz82wJRNgRPVbxVqpd1VJmZp2WVQcWMBgg==
X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR14MB6304
X-Proofpoint-GUID: gyzNNaMD05TsXIY_EoToVSADuvZ75VWg
X-Proofpoint-ORIG-GUID: gyzNNaMD05TsXIY_EoToVSADuvZ75VWg
X-Proofpoint-Virus-Version: vendor=baseguard
engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22
definitions=2023-03-15_12,2023-03-15_01,2023-02-09_01
X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0
malwarescore=0
mlxlogscore=348 clxscore=1015 impostorscore=0 bulkscore=0 spamscore=0
priorityscore=1501 phishscore=0 mlxscore=0 lowpriorityscore=0 adultscore=0
suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1
engine=8.12.0-2303150001 definitions=main-2303150181
X-Content-Filtered-By: Mailman/MimeDel 2.1.39
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <SJ0PR14MB5864236FA1B3AA32FE37E2B4B9BF9@SJ0PR14MB5864.namprd14.prod.outlook.com>
X-Mailman-Original-References: <87wn3iqiz4.fsf@hornfels.zedat.fu-berlin.de>
<f7c8f51b-e371-7a6a-c025-3fc0b69cd8ab@DancesWithMice.info>
<6dd3ac28-d877-d5bf-a2b3-7fc72f2292c1@tompassin.net>
 by: Weatherby,Gerard - Wed, 15 Mar 2023 22:06 UTC

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

This requires a single-level plugin directory with no extra files in it (unless they start with _, like __init__.py)

And I should use os.path.splitext but I forget what’s it called and find it easier just to split.

# noinspection PyUnresolvedReferences
@dataclass
class NamedModule:
"""Datacheck module and its name"""
mod: object
name: str

def __post_init__(self):
"""Validate attributes"""
assert hasattr(self.mod, 'check')
assert hasattr(self.mod, 'purpose')

def check(self, inspec: Union[PluginSpec, AddonSpec]) -> PluginResult:
return self.mod.check(inspec)

@property
def purpose(self) -> str:
return self.mod.purpose()

@property
def addon(self) -> bool:
"""Return true if this module uses AddonSpec"""
return getattr(self.mod, 'addon', False)

class Integrity:

@property
def plugins(self) -> List[NamedModule]:
"""Get list of plugins by scanning plugin directory"""
modules = []
us = os.path.abspath(__file__)
plugin_dir = os.path.join(os.path.dirname(us), 'plugins')
de: os.DirEntry
for de in os.scandir(plugin_dir):
if not de.name.startswith('_'):
n = de.name.split('.')[0]
mod = importlib.import_module(f'.plugins.{n}', 'dataintegrity')
modules.append(NamedModule(mod, n))
return modules

Re: Implementing a plug-in mechanism

<mailman.2337.1678919897.20444.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=22457&group=comp.lang.python#22457

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: lis...@tompassin.net (Thomas Passin)
Newsgroups: comp.lang.python
Subject: Re: Implementing a plug-in mechanism
Date: Wed, 15 Mar 2023 18:38:09 -0400
Lines: 8
Message-ID: <mailman.2337.1678919897.20444.python-list@python.org>
References: <87wn3iqiz4.fsf@hornfels.zedat.fu-berlin.de>
<f7c8f51b-e371-7a6a-c025-3fc0b69cd8ab@DancesWithMice.info>
<6dd3ac28-d877-d5bf-a2b3-7fc72f2292c1@tompassin.net>
<SJ0PR14MB5864236FA1B3AA32FE37E2B4B9BF9@SJ0PR14MB5864.namprd14.prod.outlook.com>
<ec3458a2-3988-2f27-d1b3-6590bd3a3370@tompassin.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de feZLlwoWGSXOYxqGULsaTwr8ztSsTrUYSHm6uv/47ixA==
Return-Path: <list1@tompassin.net>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=tompassin.net header.i=@tompassin.net header.b=Jtw6KLsf;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.052
X-Spam-Evidence: '*H*': 0.90; '*S*': 0.00; 'confusing.': 0.16;
'objects.': 0.16; 'received:10.0.0': 0.16; 'received:64.90': 0.16;
'received:64.90.62': 0.16; 'received:64.90.62.162': 0.16;
'received:dreamhost.com': 0.16; 'wrote:': 0.16; 'pm,': 0.19;
'to:addr:python-list': 0.20; 'bit': 0.27; 'purpose': 0.28; 'header
:User-Agent:1': 0.30; 'checks': 0.32; 'received:10.0': 0.32;
'received:mailchannels.net': 0.32;
'received:relay.mailchannels.net': 0.32; 'use,': 0.33; 'header:In-
Reply-To:1': 0.34; 'functions': 0.36; 'something': 0.40; 'true':
0.63; 'similar': 0.65; 'header:Received:6': 0.67; 'received:64':
0.67; 'mit': 0.76
X-Sender-Id: dreamhost|x-authsender|tpassin@tompassin.net
ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1678919891; a=rsa-sha256;
cv=none;
b=NOh17oqK8re7W8zlimk/OSI6ywzhEch2Wax2umKJJU8aC3JnWzteGVg42zqVOiLRdK/FsX
PO4D+0MlkRbgcZkA2kBQot/2YBcBBb8X5y9NjSEUxyqo2W8sl4w1sjqVp37dBK9LMXeLcd
tuusfJz0r4MostQcDWZHEKC+3ullE1YHS3iLEV/Z3m17FGjnlg0puNQ760QicgWX3PqaXG
7GXOqotoyrEjGa2pmFy31BHh/pR/QZjQT5fdxlUUyRoJSKYdAl+d1dESLeSq2/e1ST+1zg
559wbbjZD60tEQKo1TkPuXgjIEdW58BxobHGYYSigcQk3taJDl6cveNpc5cZmg==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed;
d=mailchannels.net; s=arc-2022; t=1678919891;
h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
to:to:cc:mime-version:mime-version:content-type:content-type:
content-transfer-encoding:content-transfer-encoding:
in-reply-to:in-reply-to:references:references:dkim-signature;
bh=ayGafm2wOmPVo2V7RD7voJK85PjRK4g95zC74UFRUkQ=;
b=lnQhDX5OjtOfvRjwqsLizPhEyNULMYimYgyLV9szcwOAsNRq8IbUQ554TaCGAUuW53Ylzp
QM8dcpZN1vDDNfv96WgHDGo7xuO8ru103st7H1RbfNJQ6r3AMO65eJxo60A3UuAbHJKwIW
cj8liVkFf3iU0MbHu0ixspk/ueyGN/rFvRwkRR1+gh4TdNuyOQNzSZ5otwwO7b1LLwq4FQ
BlwLH4vdiUnu2NI6gcXUCkl73mXkcRa6KCOCq/Iw2fNBtaabvAY9Lx8XIPIo5+Yqeov8le
ZGmQDjy6BRuaCzwpECnL74mcKQmHCB2zmZCafWwWMOTKT/0EdJRGzJG2GM2MlA==
ARC-Authentication-Results: i=1; rspamd-59dbd69698-t8nwm;
auth=pass smtp.auth=dreamhost smtp.mailfrom=list1@tompassin.net
X-Sender-Id: dreamhost|x-authsender|tpassin@tompassin.net
X-MC-Relay: Neutral
X-MailChannels-SenderId: dreamhost|x-authsender|tpassin@tompassin.net
X-MailChannels-Auth-Id: dreamhost
X-Spicy-Whimsical: 584877801b9e0391_1678919891443_1683972862
X-MC-Loop-Signature: 1678919891443:3088945654
X-MC-Ingress-Time: 1678919891443
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tompassin.net;
s=dreamhost; t=1678919891;
bh=ayGafm2wOmPVo2V7RD7voJK85PjRK4g95zC74UFRUkQ=;
h=Date:Subject:To:From:Content-Type:Content-Transfer-Encoding;
b=Jtw6KLsfNGZqXCb1gONTh9rK+PKIu3qLDmdM3bDYTH5FebjQD85GQJfHKVnD9amfy
wwauFQuSArIhmThUnqhXcO264R2I6dZgbw62dN6+xsaFBeQMZVokgdzIiyA72GMfmL
80LK60VfomlWKn2McL5IctClLu2WZamAUnbFgRdt9v68vYPAeZFVY9PVPOQs9QHJvj
wzMfZpNZe6WaOsyR+mrj8whlJTFc9b6mHS/qnALLksU9VzndLf7N0s3UW6t/uzIguo
cAIlj9yl7z+zSv+5uDwppLQ8U9jll5opJ64IsryrsS+W7BowUNeD4+C80kh9KVd7K3
nXeXDMVumSdCg==
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.8.0
Content-Language: en-US
In-Reply-To: <SJ0PR14MB5864236FA1B3AA32FE37E2B4B9BF9@SJ0PR14MB5864.namprd14.prod.outlook.com>
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <ec3458a2-3988-2f27-d1b3-6590bd3a3370@tompassin.net>
X-Mailman-Original-References: <87wn3iqiz4.fsf@hornfels.zedat.fu-berlin.de>
<f7c8f51b-e371-7a6a-c025-3fc0b69cd8ab@DancesWithMice.info>
<6dd3ac28-d877-d5bf-a2b3-7fc72f2292c1@tompassin.net>
<SJ0PR14MB5864236FA1B3AA32FE37E2B4B9BF9@SJ0PR14MB5864.namprd14.prod.outlook.com>
 by: Thomas Passin - Wed, 15 Mar 2023 22:38 UTC

On 3/15/2023 6:06 PM, Weatherby,Gerard wrote:
> 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

I omitted the checks because they specific to the use, so I thought they
would just be a bit confusing.

Re: Implementing a plug-in mechanism

<mailman.2338.1678959366.20444.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=22459&group=comp.lang.python#22459

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.uzoreto.com!fu-berlin.de!uni-berlin.de!not-for-mail
From: simon+py...@bleah.co.uk (Simon Ward)
Newsgroups: comp.lang.python
Subject: Re: Implementing a plug-in mechanism
Date: Thu, 16 Mar 2023 09:35:59 +0000
Lines: 12
Message-ID: <mailman.2338.1678959366.20444.python-list@python.org>
References: <87wn3iqiz4.fsf@hornfels.zedat.fu-berlin.de>
<f7c8f51b-e371-7a6a-c025-3fc0b69cd8ab@DancesWithMice.info>
<20230316093559.GA5066@bleah.co.uk>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de NDFJAEd1Yrr8i1ny361Lsg/AOrX40mKeLWmQ2oJuU3RQ==
Return-Path: <simon@bleah.co.uk>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=none reason="no signature";
dkim-adsp=none (unprotected policy); dkim-atps=neutral
X-Spam-Status: OK 0.010
X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'pypi': 0.05; '2023': 0.07;
'mar': 0.07; 'separately': 0.16; 'simon': 0.16; 'wrote:': 0.16;
'16,': 0.19; 'thu,': 0.19; 'to:addr:python-list': 0.20; "i've":
0.22; 'interface': 0.26; 'library': 0.26; 'header:User-Agent:1':
0.30; 'python-list': 0.32; 'requiring': 0.32; 'header:In-Reply-
To:1': 0.34; 'complex': 0.35; 'using': 0.37; '(see': 0.40; 'here':
0.62; 'received:80': 0.70
Content-Disposition: inline
In-Reply-To: <f7c8f51b-e371-7a6a-c025-3fc0b69cd8ab@DancesWithMice.info>
User-Agent: Mutt/1.5.23 (2014-03-12)
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <20230316093559.GA5066@bleah.co.uk>
X-Mailman-Original-References: <87wn3iqiz4.fsf@hornfels.zedat.fu-berlin.de>
<f7c8f51b-e371-7a6a-c025-3fc0b69cd8ab@DancesWithMice.info>
 by: Simon Ward - Thu, 16 Mar 2023 09:35 UTC

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.

Simon
--
A complex system that works is invariably found to have evolved from a
simple system that works.—John Gall

Re: Implementing a plug-in mechanism

<878rfw4rc2.fsf@debian-BULLSEYE-live-builder-AMD64>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=22461&group=comp.lang.python#22461

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: loris.be...@fu-berlin.de (Loris Bennett)
Newsgroups: comp.lang.python
Subject: Re: Implementing a plug-in mechanism
Date: Thu, 16 Mar 2023 17:02:37 +0100
Organization: ZEDAT, Freie Universität Berlin
Lines: 85
Message-ID: <878rfw4rc2.fsf@debian-BULLSEYE-live-builder-AMD64>
References: <87wn3iqiz4.fsf@hornfels.zedat.fu-berlin.de>
<f7c8f51b-e371-7a6a-c025-3fc0b69cd8ab@DancesWithMice.info>
<20230316093559.GA5066@bleah.co.uk>
<mailman.2338.1678959366.20444.python-list@python.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de HPq25u7v3idMiehNhAsMFQp5e4fQ1NidBMcfh3esj4vLUd
Cancel-Lock: sha1:ydE+Ajl9DFkKMNZ/mDhU2/FVnHI=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
 by: Loris Bennett - Thu, 16 Mar 2023 16:02 UTC

Simon Ward <simon+python@bleah.co.uk> writes:

> 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.

Thanks to all for the helpful suggestions. I realise that I don't
actually need to be able to load a bunch of arbitrary plugins, but
merely to be able to override one (or, perhaps later, more) piece of
default behaviour.

Therefore I think the following very simple scheme will work for me:

$ tree -L 3
.
└── myproj
├── __init__.py
├── mailer.py
├── main.py
└── plugins
└── normanmailer.py

Where main.py is

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

if __name__ == "__main__":

try:
import plugin.mailer as mailer
print("Found plugin.mailer")
except ModuleNotFoundError:
import mailer
print("Found mailer")

m = mailer.Mailer('abc')
m.run()

mailer.py is

class Mailer():

def run(self):
print("This is a generic Mailer object!")

and plugins/normanmailer.py is

class Mailer():

def run(self):
print("This is a customized Mailer object!")

This then gives me

$ poetry run myproj\/main.py
Found mailer
This is a generic Mailer object!

$ mv myproj/plugins/{norman,}mailer.py

$ poetry run myproj\/main.py
Found plugins.mailer
This is a customized Mailer object!

I suspect I was using slightly incorrect/misleading terminology. I
don't want to be able to load arbitrary functionality via plugins,
e.g. sending an email, dumping to a database, uploading to a cloud.
That would, I far as I can tell, necessitate having some mechanism to
select the functionality.

Instead I just want to modify the behaviour of a piece of fixed
functionality. e.g. sending a mail. So am I really talking about
customisation here.

Cheers,

Loris

--
This signature is currently under constuction.

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor