From 152a48bd2fcb0212513f831fdc6197de2ea414b5 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 23 Nov 2026 16:53:41 +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 77fb01a..2560bae 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -193,6 +193,21 @@ extensions already does the job and only the conversion of the measurements or o - Do not use the old `pid_models` flag nor the word "preset" in new code: a model script that opens the Dashboard loads an experiment file. +## 6b. 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. + ## 7. Done checklist - [ ] Names (package, files, classes) match and the `template` placeholders are gone. From cbf7daa851a2333bcfec5e856bde2614a042edd7 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 23 Nov 2026 16:54:35 +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 2560bae..abc0283 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -202,8 +202,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 33346a3f93b007d76f7d4a64a071e3263bb5890d Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 23 Nov 2026 17:00:26 +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 abc0283..0b32e5d 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -201,7 +201,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;