patautoedit 1.17.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Jerry
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,10 @@
1
+ include LICENSE
2
+ include README.md
3
+ prune Sample
4
+ prune Output
5
+ prune test
6
+ prune doc
7
+ prune .streamlit
8
+ prune .idea
9
+ prune patautoedit/__pycache__
10
+ global-exclude *.py[cod] .DS_Store
@@ -0,0 +1,178 @@
1
+ Metadata-Version: 2.4
2
+ Name: patautoedit
3
+ Version: 1.17.0
4
+ Summary: Edit ATP pattern files for Teradyne IG-XL testers.
5
+ Author: Jerry Zhou
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/showjim/PatAutoEdit
8
+ Project-URL: Repository, https://github.com/showjim/PatAutoEdit
9
+ Keywords: ATP,IG-XL,Teradyne,pattern
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Environment :: Console
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Programming Language :: Python :: 3.14
19
+ Requires-Python: >=3.10
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Provides-Extra: dev
23
+ Requires-Dist: build; extra == "dev"
24
+ Requires-Dist: twine; extra == "dev"
25
+ Dynamic: license-file
26
+
27
+ # PatAutoEdit
28
+
29
+ **An ATP Pattern Auto-Edit Tool for DSSC/CMEM/HRAM**
30
+
31
+ [![PyPI Version](https://img.shields.io/pypi/v/patautoedit.svg)](https://pypi.org/project/patautoedit/)
32
+ [![Python Versions](https://img.shields.io/pypi/pyversions/patautoedit.svg)](https://pypi.org/project/patautoedit/)
33
+ [![License](https://img.shields.io/pypi/l/patautoedit.svg)](https://github.com/showjim/PatAutoEdit/blob/master/LICENSE)
34
+ [![PyPI Downloads](https://img.shields.io/pypi/dm/patautoedit.svg)](https://pypi.org/project/patautoedit/)
35
+
36
+ ---
37
+
38
+ This repository contains a desktop app, a web app, and a command-line tool.
39
+ The PyPI package ships the command-line tool only; see [Command line](#command-line).
40
+
41
+ How to use the desktop or web app:
42
+ 1. Prepare the config CSV file — see [Config file format](#config-file-format) below;
43
+ 2. Choose the ATP file, config file, Pin Name (single pin support only), edit method and time mode.
44
+ ![PAT_UI](https://raw.githubusercontent.com/showjim/PatAutoEdit/master/img/PAT_UI.png "PAT_UI")
45
+ 3. Supported edits:
46
+ * DigCap/DigSrc;
47
+ * HRAM/CMEM;
48
+ * Expand Repeat (remove "repeat N" and "repeat cX"); "Expand Pattern" is the old name of the same mode and will be dropped in a future version;
49
+ * Expand Loop (flatten "loop"/"end_loop" in srm_vector modules, which then become vm_vector);
50
+ * Counters loaded by the test program: give their values in User String — see [Counters loaded by the test program](#counters-loaded-by-the-test-program);
51
+ * Compress Pattern (add "repeat");
52
+
53
+ ## Command line
54
+
55
+ Install it with Python 3.10 or newer:
56
+
57
+ ```bash
58
+ pip install patautoedit
59
+ ```
60
+
61
+ From a repo checkout, `pip install -e .` gives the same command, and
62
+ `python -m patautoedit` works without installing.
63
+
64
+ ```bash
65
+ patautoedit run config.csv --atp-dir path/to/atps
66
+ patautoedit run config.csv --atp-dir path/to/atps --output-dir out/run1 --json
67
+ patautoedit check config.csv --atp-dir path/to/atps
68
+ patautoedit modes
69
+ ```
70
+
71
+ In a repo checkout, `Sample/` holds example ATPs. The counter examples are in
72
+ `Sample/expand_loop/`.
73
+
74
+ - `run` applies the config. Edited files go to `Output/` under the current
75
+ directory unless `--output-dir` is given.
76
+ - `check` validates the config and prints what would run. It writes nothing.
77
+ - `modes` lists the Process Types and the fields each one needs.
78
+ - `--json` prints one JSON object on stdout; log lines go to stderr.
79
+ - Exit codes: `0` success, `1` a rejected config, a failed file, or no matched
80
+ file, `2` usage error.
81
+ - `run --json` returns `ok`, `version`, `config`, `output_dir`, `outputs`,
82
+ `failed`, `skipped`, `warnings`, `problems`, and `counts`. Each `outputs`
83
+ item has `source`, `output`, and `operations`; each `failed` item has
84
+ `source` and `errors`.
85
+ - `check --json` returns the same top-level keys, but `plan` replaces
86
+ `output_dir`, `outputs`, and `failed`; each plan item has `source` and
87
+ `operations`.
88
+ - `modes --json` returns a list of `{"process_type", "requires"}`.
89
+ - `--atp-dir` defaults to the config file's folder. It scans that folder only,
90
+ not subfolders. `--atp FILE` (repeatable) names candidate files explicitly
91
+ and overrides `--atp-dir`.
92
+ - A `Pattern` that matches no candidate file is a warning and a skip, not an
93
+ error. If nothing matches at all, the run exits 1.
94
+ - The CLI uses the config CSV path: Single time mode and Cycle index. Dual-mode
95
+ or vector-index files need the desktop app's Classical tab.
96
+
97
+ The desktop and web apps run from a repo checkout: `python PAE.py` or
98
+ `streamlit run PAE_webapp.py`.
99
+
100
+ ## Config file format
101
+
102
+ **One row is one operation.** Rows that share the same `Pattern` form a chain and
103
+ are applied top to bottom — each step reads the output of the step above it, so a
104
+ file can be edited as many times as you need.
105
+
106
+ ```csv
107
+ Instance,Pattern,Status,Process Type,Pin or Method,Cycle,User String
108
+ ,Sample_ATP.atp,Done,DSSC Capture,TDO,[7-7];[12-12],
109
+ ,Sample_ATP.atp,Done,DSSC Capture,PORN,[13-14],
110
+ ,Sample_ATP.atp,Done,DSSC Source,TDI,[9-9],
111
+ ,Sample_ATP.atp,Done,WFLAG,,[8-8],
112
+ ,Sample_ATP - 1.atp,Done,DSSC Source,TDI,[7-7];[9-9],
113
+ ,Sample_ATP - 1.atp,Done,DSSC Capture,TDO,[7-7];[12-12],
114
+ ```
115
+
116
+ `Sample_ATP.atp` above gets four chained operations; `Sample_ATP - 1.atp` gets two.
117
+
118
+ | Column | Notes |
119
+ | --- | --- |
120
+ | `Pattern` | ATP filename. Required. |
121
+ | `Process Type` | One of: DSSC Capture, DSSC Source, CMEM/HRAM Capture, Expand Pattern, Expand Repeat, Expand Loop, Compress Pattern, WFLAG, Add Opcode, Remove Opcode. Required. |
122
+ | `Pin or Method` | Used only by DSSC Capture, DSSC Source, and CMEM/HRAM Capture. |
123
+ | `Cycle` | `[a-b];[c-d]` form. Used by DSSC Capture, DSSC Source, CMEM/HRAM Capture, WFLAG, and Add Opcode. |
124
+ | `User String` | The opcode text for `Add Opcode` / `Remove Opcode`. For `Expand Repeat`, `Expand Loop` and `Expand Pattern`: optional counter run counts, e.g. `c0=<count>; c7=<count>` — see [Counters loaded by the test program](#counters-loaded-by-the-test-program). Other modes ignore it. |
125
+ | `Instance`, `Status` | Ignored. Kept for your own bookkeeping. |
126
+
127
+ Column names are matched case-insensitively and column order does not matter.
128
+ Your whole config is checked before anything runs, so a mistake is reported up
129
+ front rather than half-way through a batch.
130
+
131
+ Note: the older 9-column format, where one row held two operations, is no longer
132
+ supported. Such a file is rejected with a message showing the rows to use
133
+ instead.
134
+
135
+ `Expand Pattern`, `Expand Repeat`, and `Compress Pattern` always use single
136
+ time mode; use the Classical tab for dual-mode files. `Expand Loop` supports
137
+ single mode only.
138
+
139
+ ## Counters loaded by the test program
140
+
141
+ Some patterns run `loop cX` or `repeat cX` on a counter that the test program
142
+ (VBT) loads before the pattern starts, so the ATP has no `set cX` to read.
143
+ Give those values in `User String` on the `Expand Loop` and `Expand Repeat`
144
+ rows:
145
+
146
+ ```csv
147
+ Pattern,Process Type,Pin or Method,Cycle,User String
148
+ march_full.atp,Expand Loop,,,c0=<count>; c7=<count>; c8=<count>
149
+ march_full.atp,Expand Repeat,,,c0=<count>; c7=<count>; c8=<count>
150
+ ```
151
+
152
+ Sample configs for both are in `Sample/Sample_ATP - simple.csv`:
153
+ `Sample/expand_loop/counters_preloaded_mto.atp` takes its values from
154
+ User String, and `Sample/expand_loop/counters_set_in_atp.atp` sets its own
155
+ counters, so it needs none.
156
+
157
+ - Write `cN=run count` pairs separated by `;`: counters `c0` to `c15`,
158
+ decimal values from 1 to 268,435,455, each counter once.
159
+ - A run count is how many times the loop or repeat runs: the `N` in
160
+ `set cX N`. A VBT line `TheHdw.Digital.Patgen.Counter(tlPgCounterN) = X`
161
+ loads the counter register directly, so its run count is `X + 1`.
162
+ - The values act as if the VBT loaded them just before the pattern starts:
163
+ - A `set cX` in the ATP wins from that vector on. It still needs its own
164
+ `set_msb` first.
165
+ - A counter the mode needs, with no value and no `set`, fails the file.
166
+ - Values the mode does not need are ignored, with one info line in the log,
167
+ so the same string can go on every Expand row.
168
+ - The tool never reads the test program
169
+ ([why](https://github.com/showjim/PatAutoEdit/blob/master/doc/adr/0001-counter-values-from-the-user.md)). When one pattern runs
170
+ with different values, for example under two test instances, make one
171
+ renamed copy of the ATP for each set of values; each copy gets its own rows.
172
+
173
+ The words used here are defined in
174
+ [GLOSSARY.md](https://github.com/showjim/PatAutoEdit/blob/master/GLOSSARY.md).
175
+
176
+ ## License
177
+
178
+ MIT. See [LICENSE](https://github.com/showjim/PatAutoEdit/blob/master/LICENSE).
@@ -0,0 +1,152 @@
1
+ # PatAutoEdit
2
+
3
+ **An ATP Pattern Auto-Edit Tool for DSSC/CMEM/HRAM**
4
+
5
+ [![PyPI Version](https://img.shields.io/pypi/v/patautoedit.svg)](https://pypi.org/project/patautoedit/)
6
+ [![Python Versions](https://img.shields.io/pypi/pyversions/patautoedit.svg)](https://pypi.org/project/patautoedit/)
7
+ [![License](https://img.shields.io/pypi/l/patautoedit.svg)](https://github.com/showjim/PatAutoEdit/blob/master/LICENSE)
8
+ [![PyPI Downloads](https://img.shields.io/pypi/dm/patautoedit.svg)](https://pypi.org/project/patautoedit/)
9
+
10
+ ---
11
+
12
+ This repository contains a desktop app, a web app, and a command-line tool.
13
+ The PyPI package ships the command-line tool only; see [Command line](#command-line).
14
+
15
+ How to use the desktop or web app:
16
+ 1. Prepare the config CSV file — see [Config file format](#config-file-format) below;
17
+ 2. Choose the ATP file, config file, Pin Name (single pin support only), edit method and time mode.
18
+ ![PAT_UI](https://raw.githubusercontent.com/showjim/PatAutoEdit/master/img/PAT_UI.png "PAT_UI")
19
+ 3. Supported edits:
20
+ * DigCap/DigSrc;
21
+ * HRAM/CMEM;
22
+ * Expand Repeat (remove "repeat N" and "repeat cX"); "Expand Pattern" is the old name of the same mode and will be dropped in a future version;
23
+ * Expand Loop (flatten "loop"/"end_loop" in srm_vector modules, which then become vm_vector);
24
+ * Counters loaded by the test program: give their values in User String — see [Counters loaded by the test program](#counters-loaded-by-the-test-program);
25
+ * Compress Pattern (add "repeat");
26
+
27
+ ## Command line
28
+
29
+ Install it with Python 3.10 or newer:
30
+
31
+ ```bash
32
+ pip install patautoedit
33
+ ```
34
+
35
+ From a repo checkout, `pip install -e .` gives the same command, and
36
+ `python -m patautoedit` works without installing.
37
+
38
+ ```bash
39
+ patautoedit run config.csv --atp-dir path/to/atps
40
+ patautoedit run config.csv --atp-dir path/to/atps --output-dir out/run1 --json
41
+ patautoedit check config.csv --atp-dir path/to/atps
42
+ patautoedit modes
43
+ ```
44
+
45
+ In a repo checkout, `Sample/` holds example ATPs. The counter examples are in
46
+ `Sample/expand_loop/`.
47
+
48
+ - `run` applies the config. Edited files go to `Output/` under the current
49
+ directory unless `--output-dir` is given.
50
+ - `check` validates the config and prints what would run. It writes nothing.
51
+ - `modes` lists the Process Types and the fields each one needs.
52
+ - `--json` prints one JSON object on stdout; log lines go to stderr.
53
+ - Exit codes: `0` success, `1` a rejected config, a failed file, or no matched
54
+ file, `2` usage error.
55
+ - `run --json` returns `ok`, `version`, `config`, `output_dir`, `outputs`,
56
+ `failed`, `skipped`, `warnings`, `problems`, and `counts`. Each `outputs`
57
+ item has `source`, `output`, and `operations`; each `failed` item has
58
+ `source` and `errors`.
59
+ - `check --json` returns the same top-level keys, but `plan` replaces
60
+ `output_dir`, `outputs`, and `failed`; each plan item has `source` and
61
+ `operations`.
62
+ - `modes --json` returns a list of `{"process_type", "requires"}`.
63
+ - `--atp-dir` defaults to the config file's folder. It scans that folder only,
64
+ not subfolders. `--atp FILE` (repeatable) names candidate files explicitly
65
+ and overrides `--atp-dir`.
66
+ - A `Pattern` that matches no candidate file is a warning and a skip, not an
67
+ error. If nothing matches at all, the run exits 1.
68
+ - The CLI uses the config CSV path: Single time mode and Cycle index. Dual-mode
69
+ or vector-index files need the desktop app's Classical tab.
70
+
71
+ The desktop and web apps run from a repo checkout: `python PAE.py` or
72
+ `streamlit run PAE_webapp.py`.
73
+
74
+ ## Config file format
75
+
76
+ **One row is one operation.** Rows that share the same `Pattern` form a chain and
77
+ are applied top to bottom — each step reads the output of the step above it, so a
78
+ file can be edited as many times as you need.
79
+
80
+ ```csv
81
+ Instance,Pattern,Status,Process Type,Pin or Method,Cycle,User String
82
+ ,Sample_ATP.atp,Done,DSSC Capture,TDO,[7-7];[12-12],
83
+ ,Sample_ATP.atp,Done,DSSC Capture,PORN,[13-14],
84
+ ,Sample_ATP.atp,Done,DSSC Source,TDI,[9-9],
85
+ ,Sample_ATP.atp,Done,WFLAG,,[8-8],
86
+ ,Sample_ATP - 1.atp,Done,DSSC Source,TDI,[7-7];[9-9],
87
+ ,Sample_ATP - 1.atp,Done,DSSC Capture,TDO,[7-7];[12-12],
88
+ ```
89
+
90
+ `Sample_ATP.atp` above gets four chained operations; `Sample_ATP - 1.atp` gets two.
91
+
92
+ | Column | Notes |
93
+ | --- | --- |
94
+ | `Pattern` | ATP filename. Required. |
95
+ | `Process Type` | One of: DSSC Capture, DSSC Source, CMEM/HRAM Capture, Expand Pattern, Expand Repeat, Expand Loop, Compress Pattern, WFLAG, Add Opcode, Remove Opcode. Required. |
96
+ | `Pin or Method` | Used only by DSSC Capture, DSSC Source, and CMEM/HRAM Capture. |
97
+ | `Cycle` | `[a-b];[c-d]` form. Used by DSSC Capture, DSSC Source, CMEM/HRAM Capture, WFLAG, and Add Opcode. |
98
+ | `User String` | The opcode text for `Add Opcode` / `Remove Opcode`. For `Expand Repeat`, `Expand Loop` and `Expand Pattern`: optional counter run counts, e.g. `c0=<count>; c7=<count>` — see [Counters loaded by the test program](#counters-loaded-by-the-test-program). Other modes ignore it. |
99
+ | `Instance`, `Status` | Ignored. Kept for your own bookkeeping. |
100
+
101
+ Column names are matched case-insensitively and column order does not matter.
102
+ Your whole config is checked before anything runs, so a mistake is reported up
103
+ front rather than half-way through a batch.
104
+
105
+ Note: the older 9-column format, where one row held two operations, is no longer
106
+ supported. Such a file is rejected with a message showing the rows to use
107
+ instead.
108
+
109
+ `Expand Pattern`, `Expand Repeat`, and `Compress Pattern` always use single
110
+ time mode; use the Classical tab for dual-mode files. `Expand Loop` supports
111
+ single mode only.
112
+
113
+ ## Counters loaded by the test program
114
+
115
+ Some patterns run `loop cX` or `repeat cX` on a counter that the test program
116
+ (VBT) loads before the pattern starts, so the ATP has no `set cX` to read.
117
+ Give those values in `User String` on the `Expand Loop` and `Expand Repeat`
118
+ rows:
119
+
120
+ ```csv
121
+ Pattern,Process Type,Pin or Method,Cycle,User String
122
+ march_full.atp,Expand Loop,,,c0=<count>; c7=<count>; c8=<count>
123
+ march_full.atp,Expand Repeat,,,c0=<count>; c7=<count>; c8=<count>
124
+ ```
125
+
126
+ Sample configs for both are in `Sample/Sample_ATP - simple.csv`:
127
+ `Sample/expand_loop/counters_preloaded_mto.atp` takes its values from
128
+ User String, and `Sample/expand_loop/counters_set_in_atp.atp` sets its own
129
+ counters, so it needs none.
130
+
131
+ - Write `cN=run count` pairs separated by `;`: counters `c0` to `c15`,
132
+ decimal values from 1 to 268,435,455, each counter once.
133
+ - A run count is how many times the loop or repeat runs: the `N` in
134
+ `set cX N`. A VBT line `TheHdw.Digital.Patgen.Counter(tlPgCounterN) = X`
135
+ loads the counter register directly, so its run count is `X + 1`.
136
+ - The values act as if the VBT loaded them just before the pattern starts:
137
+ - A `set cX` in the ATP wins from that vector on. It still needs its own
138
+ `set_msb` first.
139
+ - A counter the mode needs, with no value and no `set`, fails the file.
140
+ - Values the mode does not need are ignored, with one info line in the log,
141
+ so the same string can go on every Expand row.
142
+ - The tool never reads the test program
143
+ ([why](https://github.com/showjim/PatAutoEdit/blob/master/doc/adr/0001-counter-values-from-the-user.md)). When one pattern runs
144
+ with different values, for example under two test instances, make one
145
+ renamed copy of the ATP for each set of values; each copy gets its own rows.
146
+
147
+ The words used here are defined in
148
+ [GLOSSARY.md](https://github.com/showjim/PatAutoEdit/blob/master/GLOSSARY.md).
149
+
150
+ ## License
151
+
152
+ MIT. See [LICENSE](https://github.com/showjim/PatAutoEdit/blob/master/LICENSE).
@@ -0,0 +1,5 @@
1
+ # PatAutoEdit source package
2
+
3
+ __version__ = "1.17.0"
4
+ #: Version shown in the UIs and the CLI.
5
+ version = "V" + __version__
@@ -0,0 +1,6 @@
1
+ import sys
2
+
3
+ from patautoedit.cli import main
4
+
5
+ if __name__ == "__main__":
6
+ sys.exit(main())
@@ -0,0 +1,219 @@
1
+ '''
2
+ ATP file handling module
3
+ '''
4
+ import csv
5
+ import re
6
+ from typing import Dict, List
7
+ from patautoedit.file_ops import openfile
8
+ from patautoedit.utils import process_input_cycles
9
+ from patautoedit.logger import Logger
10
+ csv.field_size_limit(100000000)
11
+
12
+ #: Processing modes the tool understands. Single source of truth for the
13
+ #: configuration parser, the validators and every mode picker in the UIs.
14
+ MODE_LIST = ['DSSC Capture', 'DSSC Source', 'CMEM/HRAM Capture',
15
+ 'Expand Pattern', 'Expand Repeat', 'Expand Loop', 'Compress Pattern', 'WFLAG',
16
+ 'Add Opcode', 'Remove Opcode']
17
+
18
+ #: Modes that need a pin name, a cycle range, or an opcode string to do anything.
19
+ _PIN_MODES = ('DSSC Capture', 'DSSC Source', 'CMEM/HRAM Capture')
20
+ _CYCLE_MODES = _PIN_MODES + ('WFLAG', 'Add Opcode')
21
+ _USER_STRING_MODES = ('Add Opcode', 'Remove Opcode')
22
+ #: Modes whose optional User String holds preloaded counter run counts.
23
+ COUNTER_MODES = ('Expand Pattern', 'Expand Repeat', 'Expand Loop')
24
+
25
+ #: Columns a row-per-op config must carry, matched case-insensitively.
26
+ _REQUIRED_COLUMNS = ('pattern', 'process type', 'pin or method', 'cycle')
27
+ #: Columns that are read but optional (blank when absent).
28
+ _OPTIONAL_COLUMNS = ('user string',)
29
+ #: Columns that are accepted and ignored.
30
+ _IGNORED_COLUMNS = ('instance', 'status')
31
+
32
+
33
+ class ConfigError(Exception):
34
+ """Raised when a configuration file cannot be used, with a user-facing message."""
35
+
36
+
37
+ def missing_requirements(op: Dict) -> List[str]:
38
+ """Return the fields an operation is missing, given its mode.
39
+
40
+ An empty list means the operation has everything its mode needs.
41
+ """
42
+ mode = op.get("Mode", "")
43
+ if mode not in MODE_LIST:
44
+ return ["Process Type " + repr(mode) + " is not a known mode (valid: " +
45
+ ", ".join(MODE_LIST) + ")"]
46
+ missing = []
47
+ if mode in _PIN_MODES and not op.get("PinName"):
48
+ missing.append("Pin or Method")
49
+ if mode in _CYCLE_MODES and not op.get("CycleRange"):
50
+ missing.append("Cycle")
51
+ if mode in _USER_STRING_MODES and not op.get("UserString"):
52
+ missing.append("User String")
53
+ return missing
54
+
55
+ def read_csv(input_path: str) -> Dict:
56
+ """Read CSV file containing cycle ranges"""
57
+ cycle_range = {}
58
+ with openfile(input_path) as f:
59
+ f_csv = csv.reader(f)
60
+ for row in f_csv:
61
+ if len(row) > 0:
62
+ if len(row[0]) > 0 or len(row[1]) > 0:
63
+ cycle_range[row[0]] = process_input_cycles(row[1])
64
+ else:
65
+ break
66
+ else:
67
+ break
68
+ return cycle_range
69
+
70
+ def build_config_from_classical(csv_file: str, mode: str, pin_name: str,
71
+ time_mode: str, index_mode: str,
72
+ user_string: str = "") -> List[Dict]:
73
+ """Convert classical 2-column CSV + GUI settings into standard config list.
74
+
75
+ This adapter function allows the classical interface to use the same
76
+ processing code path as the simplified interface (process_atp_simple).
77
+
78
+ Args:
79
+ csv_file: Path to the 2-column CSV (filename, cycle_range)
80
+ mode: Processing mode from GUI (e.g., 'DSSC Capture')
81
+ pin_name: Pin name from GUI
82
+ time_mode: 'Single' or 'Dual' from GUI
83
+ index_mode: 'Cycle' or 'Vector' from GUI
84
+ user_string: Opcode text for 'Add Opcode' / 'Remove Opcode', or
85
+ counter run counts for the Expand modes (e.g. 'c0=<count>; c7=<count>')
86
+
87
+ Returns:
88
+ List of config dicts in the same format as analyse_merge_config output
89
+ """
90
+ cycle_ranges = read_csv(csv_file)
91
+ config_list = []
92
+ for filename, cycles in cycle_ranges.items():
93
+ config_list.append({
94
+ "ATPFile": filename,
95
+ "CycleRange": cycles,
96
+ "Mode": mode,
97
+ "PinName": pin_name,
98
+ "UserString": user_string,
99
+ "TimeMode": time_mode,
100
+ "IndexMode": index_mode
101
+ })
102
+ return config_list
103
+
104
+ def read_pinmap(pinmap_dir: str) -> Dict:
105
+ """Read pin mapping file"""
106
+ pin_dict = {}
107
+ line_cnt = 0
108
+ with open(pinmap_dir, mode='r') as f:
109
+ f_csv = csv.reader(f, delimiter="\t")
110
+ for row in f_csv:
111
+ if len(row) >= 2 and line_cnt >= 3:
112
+ if row[1] != "":
113
+ key = row[1]
114
+ if key in pin_dict.keys():
115
+ pin_dict[key].append(row[2])
116
+ else:
117
+ pin_dict[key] = [row[2]]
118
+ line_cnt += 1
119
+ return pin_dict
120
+
121
+ def analyse_merge_config(merge_config_file: str, logger: Logger) -> List[Dict]:
122
+ """Read a row-per-op configuration file into a config list.
123
+
124
+ One row is one operation. Rows sharing a `Pattern` form a single chain and
125
+ are applied in row order, each operation consuming the previous one's
126
+ output.
127
+
128
+ Columns are matched by name, case-insensitively and ignoring surrounding
129
+ whitespace, so column order does not matter. `_REQUIRED_COLUMNS` must all be
130
+ present; `_IGNORED_COLUMNS` are accepted and not read; anything else is
131
+ reported and ignored. Blank rows are skipped wherever they appear.
132
+
133
+ Raises:
134
+ ConfigError: if the file is not usable in this format.
135
+ """
136
+ def fail(message):
137
+ raise ConfigError(f"{merge_config_file}: {message}")
138
+
139
+ with openfile(merge_config_file) as f:
140
+ rows = [row for row in csv.reader(f) if any(cell.strip() for cell in row)]
141
+
142
+ if not rows:
143
+ fail("the file is empty")
144
+
145
+ header = [cell.strip().lower() for cell in rows[0]]
146
+
147
+ if len(header) >= 9:
148
+ sample = ','.join(rows[1] if len(rows) > 1 else rows[0])
149
+ fail(
150
+ "this looks like the old 9-column format, which is no longer supported. "
151
+ "Each operation now gets its own row, so a row like\n"
152
+ f" {sample}\n"
153
+ "becomes one row per operation:\n"
154
+ " Pattern,Process Type,Pin or Method,Cycle\n"
155
+ " sample.atp,DSSC Capture,TDO,[7-7];[12-12]\n"
156
+ " sample.atp,DSSC Capture,PORN,[13-14]"
157
+ )
158
+
159
+ missing = [c for c in _REQUIRED_COLUMNS if c not in header]
160
+ if missing:
161
+ fail("missing required column(s): " + ", ".join(missing) +
162
+ ". Required: " + ", ".join(_REQUIRED_COLUMNS) + " (case-insensitive)")
163
+
164
+ unknown = [c for c in header
165
+ if c and c not in _REQUIRED_COLUMNS + _OPTIONAL_COLUMNS + _IGNORED_COLUMNS]
166
+ if unknown:
167
+ logger.warning("Ignoring unrecognised column(s): " + ", ".join(unknown))
168
+
169
+ columns = {name: header.index(name) for name in header
170
+ if name in _REQUIRED_COLUMNS + _OPTIONAL_COLUMNS}
171
+
172
+ config_list = []
173
+ for line_no, row in enumerate(rows[1:], start=2):
174
+ def cell(name):
175
+ i = columns.get(name)
176
+ return row[i].strip() if i is not None and i < len(row) else ""
177
+
178
+ pattern, mode = cell('pattern'), cell('process type')
179
+ if not pattern or not mode:
180
+ fail(f"line {line_no}: Pattern and Process Type are both required")
181
+
182
+ cycle_text = cell('cycle')
183
+ try:
184
+ cycles = process_input_cycles(cycle_text) if cycle_text else []
185
+ except Exception:
186
+ fail(f"line {line_no}: cannot parse Cycle {cycle_text!r}; expected e.g. [7-7];[12-12]")
187
+
188
+ config_list.append({
189
+ "ATPFile": pattern,
190
+ "CycleRange": cycles,
191
+ "Mode": mode,
192
+ "PinName": cell('pin or method'),
193
+ "UserString": cell('user string'),
194
+ "TimeMode": "Single",
195
+ "IndexMode": "Cycle",
196
+ })
197
+
198
+ if not config_list:
199
+ fail("no operations found (the file has a header but no data rows)")
200
+
201
+ return config_list
202
+
203
+ def find_pin_index(mode:str, pin_names: str, str_line: str, logger: Logger) -> List[int]:
204
+ """Find pin indices in line"""
205
+ pin_name = pin_names.split(",")
206
+ str_line = str_line.replace(' ', '')
207
+ pattern = re.compile(r'(?<=\,)\s*([^\,^\s]+)(?=[\,\)])')
208
+ tmparray = re.findall(pattern, str_line)
209
+ index = []
210
+
211
+ for i in range(len(pin_name)):
212
+ for x in range(len(tmparray)):
213
+ if tmparray[x] == pin_name[i]:
214
+ index.append(x)
215
+
216
+ if (len(index) != len(pin_name)) and (mode not in ['WFLAG', 'Add Opcode']):
217
+ index = []
218
+ logger.error("Cannot find all given pins")
219
+ return index