From 30f61f869a76440aa553ffffd2ba3e3f9fdecfbb Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 23 Nov 2026 16:53:48 +0000 Subject: [PATCH 1/3] AGENTS.md: structure of the families of classes (factory module next to a folder of classes) Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01RKuN81tBxMB6iaf8J6KLJL --- AGENTS.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/AGENTS.md b/AGENTS.md index db4e469..1ab8e67 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -167,6 +167,21 @@ and the deprecated `CustomApp` / `CustomExt` hooks `setup_docks` and `setup_menu Only when no instrument is needed. Same (non-deprecated) lifecycle as above, `parent` is a `DockArea` or `QMainWindow`, and `main()` creates the app with `mkQApp`. If instruments become necessary, move the logic to a `CustomExt`. +## 5b. Families of interchangeable classes (factories) + +Before designing the structure of a new piece of code, look at how PyMoDAQ already does the same thing and copy it +(do not reinvent it): for instance the sequencer elements (`pymodaq/extensions/sequencer/utilities/`), the scanners +(`ScannerFactory`) or the data processors. For a family of classes chosen by name (waveforms, scan types, exporters...): + +- the base class and the factory live in one module, `_factory.py`, **not** in the folder of the classes; +- the classes live in a sibling folder (`s/`), **one module per class**, each registering itself with a + decorator of the factory (`@WaveformFactory.register('sine')`); +- the `__init__.py` of that folder imports all its submodules (`pkgutil`), so adding a class is adding a file and + nothing else, and a plugin package can register its own classes the same way; +- the factory is a plain class that encapsulates its own registry (a class level dictionary, with `register`, + `names`, `get_class`, `create`). Do not inherit from `pymodaq_utils.factory.ObjectFactory`: it complicates the + management of the registry. + ## 6. Done checklist - [ ] Names (package, files, classes) match and the `template` placeholders are gone. From 3ba9e6bb3dd6178634d1f1e934fde32839c9f63c Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 23 Nov 2026 16:54:38 +0000 Subject: [PATCH 2/3] AGENTS.md: say how the sequencer imports its element modules Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01RKuN81tBxMB6iaf8J6KLJL --- AGENTS.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 1ab8e67..969b013 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -176,8 +176,9 @@ Before designing the structure of a new piece of code, look at how PyMoDAQ alrea - the base class and the factory live in one module, `_factory.py`, **not** in the folder of the classes; - the classes live in a sibling folder (`s/`), **one module per class**, each registering itself with a decorator of the factory (`@WaveformFactory.register('sine')`); -- the `__init__.py` of that folder imports all its submodules (`pkgutil`), so adding a class is adding a file and - nothing else, and a plugin package can register its own classes the same way; +- all the submodules of that folder are imported, by its `__init__.py` (`pkgutil`) or by a function of the factory + module as `register_elements` of the sequencer does, so adding a class is adding a file and nothing else, and a + plugin package can register its own classes the same way; - the factory is a plain class that encapsulates its own registry (a class level dictionary, with `register`, `names`, `get_class`, `create`). Do not inherit from `pymodaq_utils.factory.ObjectFactory`: it complicates the management of the registry. From 37cb571d9eaebef4d3d472e63fdde9fbc4e01bdc Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 23 Nov 2026 17:00:32 +0000 Subject: [PATCH 3/3] AGENTS.md: the name of a registered class is written once (class attribute) Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01RKuN81tBxMB6iaf8J6KLJL --- AGENTS.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/AGENTS.md b/AGENTS.md index 969b013..9712745 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -175,7 +175,8 @@ Before designing the structure of a new piece of code, look at how PyMoDAQ alrea - the base class and the factory live in one module, `_factory.py`, **not** in the folder of the classes; - the classes live in a sibling folder (`s/`), **one module per class**, each registering itself with a - decorator of the factory (`@WaveformFactory.register('sine')`); + decorator of the factory (`@WaveformFactory.register()`); the name is written once, as a class attribute + (like `elt_name` of the sequencer elements), not repeated in the decorator, in a title and in the class name; - all the submodules of that folder are imported, by its `__init__.py` (`pkgutil`) or by a function of the factory module as `register_elements` of the sequencer does, so adding a class is adding a file and nothing else, and a plugin package can register its own classes the same way;