cpp-pd-code-simplify-interface 0.1.14__py3-none-any.whl → 0.1.16__py3-none-any.whl

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.
@@ -1,4 +1,10 @@
1
+ import json
2
+
1
3
  from .main import main
2
4
 
3
5
  if __name__ == "__main__":
4
- raise SystemExit(main())
6
+ try:
7
+ raise SystemExit(main())
8
+ except KeyboardInterrupt:
9
+ print(json.dumps({"error": "interrupted by Ctrl+C"}, indent=2))
10
+ raise SystemExit(130)
@@ -2598,8 +2598,7 @@ ReductionResult reduce_pd_code(
2598
2598
  emit_progress(run_options, message.str());
2599
2599
  }
2600
2600
 
2601
- if (!search.found && reduction_round < 0 &&
2602
- run_options.max_paths == -1 && !run_options.ban_heuristic) {
2601
+ if (!search.found && run_options.max_paths == -1 && !run_options.ban_heuristic) {
2603
2602
  SimplifierOptions brute_options = run_options;
2604
2603
  brute_options.max_paths = -1;
2605
2604
  brute_options.ban_heuristic = true;
@@ -90,10 +90,7 @@ def normalize_pd_codes(pd_codes: PdManyInput) -> list[str]:
90
90
  return [normalize_pd_code(pd_code) for pd_code in pd_codes]
91
91
 
92
92
 
93
- def _label_for_block(text: str, block_start: int, label_prefix: str, index: int) -> str:
94
- line_start = text.rfind("\n", 0, block_start)
95
- line_start = 0 if line_start == -1 else line_start + 1
96
- before_block = text[line_start:block_start]
93
+ def _label_for_line_prefix(before_block: str, label_prefix: str, index: int) -> str:
97
94
  if ":" in before_block:
98
95
  line_label = before_block.split(":", 1)[0].strip()
99
96
  if line_label:
@@ -104,56 +101,62 @@ def _label_for_block(text: str, block_start: int, label_prefix: str, index: int)
104
101
 
105
102
 
106
103
  def _pd_file_jobs(path: str) -> list[tuple[str, str]]:
107
- text = pathlib.Path(path).read_text(encoding="utf-8")
108
104
  jobs: list[tuple[str, str]] = []
109
- position = 0
110
- index = 0
111
-
112
- while True:
113
- start = text.find("PD[", position)
114
- if start == -1:
115
- break
116
- depth = 0
117
- end = -1
118
- for cursor in range(start + 2, len(text)):
119
- if text[cursor] == "[":
120
- depth += 1
121
- elif text[cursor] == "]":
122
- depth -= 1
123
- if depth == 0:
124
- end = cursor
105
+ fallback_jobs: list[tuple[str, str]] = []
106
+ current_label: Optional[str] = None
107
+ current_block: list[str] = []
108
+ bracket_depth = 0
109
+
110
+ with pathlib.Path(path).open("r", encoding="utf-8") as input_file:
111
+ for line in input_file:
112
+ cleaned = line.strip()
113
+ if not jobs and not current_block and cleaned and not cleaned.startswith("#"):
114
+ label = path
115
+ payload = cleaned
116
+ if ":" in cleaned:
117
+ line_label, payload = cleaned.split(":", 1)
118
+ line_label = line_label.strip()
119
+ payload = payload.strip()
120
+ if line_label:
121
+ label = f"{path}:{line_label}"
122
+ elif fallback_jobs:
123
+ label = f"{path}#{len(fallback_jobs) + 1}"
124
+ fallback_jobs.append((label, payload))
125
+
126
+ cursor = 0
127
+ while cursor < len(line):
128
+ if current_block:
129
+ char = line[cursor]
130
+ current_block.append(char)
131
+ if char == "[":
132
+ bracket_depth += 1
133
+ elif char == "]":
134
+ bracket_depth -= 1
135
+ if bracket_depth == 0:
136
+ jobs.append((current_label or f"{path}#{len(jobs) + 1}", "".join(current_block)))
137
+ current_label = None
138
+ current_block = []
139
+ cursor += 1
140
+ continue
141
+
142
+ start = line.find("PD[", cursor)
143
+ if start == -1:
125
144
  break
126
- if end == -1:
127
- jobs.append((f"{path}#{index + 1}", text[start:].strip()))
128
- break
129
- jobs.append((
130
- _label_for_block(text, start, path, index),
131
- text[start : end + 1],
132
- ))
133
- index += 1
134
- position = end + 1
145
+ current_label = _label_for_line_prefix(line[:start], path, len(jobs))
146
+ current_block = ["PD["]
147
+ bracket_depth = 1
148
+ cursor = start + 3
135
149
 
136
150
  if jobs:
151
+ if current_block:
152
+ jobs.append((f"{path}#{len(jobs) + 1}", "".join(current_block).strip()))
137
153
  if len(jobs) == 1:
138
154
  jobs[0] = (path, jobs[0][1])
139
155
  return jobs
140
156
 
141
- for line in text.splitlines():
142
- cleaned = line.strip()
143
- if not cleaned or cleaned.startswith("#"):
144
- continue
145
- label = path
146
- payload = cleaned
147
- if ":" in cleaned:
148
- line_label, payload = cleaned.split(":", 1)
149
- line_label = line_label.strip()
150
- payload = payload.strip()
151
- if line_label:
152
- label = f"{path}:{line_label}"
153
- elif jobs:
154
- label = f"{path}#{len(jobs) + 1}"
155
- jobs.append((label, payload))
156
- return jobs
157
+ if current_block:
158
+ fallback_jobs.append((f"{path}#{len(fallback_jobs) + 1}", "".join(current_block).strip()))
159
+ return fallback_jobs
157
160
 
158
161
 
159
162
  @contextlib.contextmanager
@@ -1033,7 +1036,14 @@ def main(argv: Optional[Sequence[str]] = None) -> int:
1033
1036
 
1034
1037
  exit_code = 0
1035
1038
  if args.pd_file:
1036
- jobs = _pd_file_jobs(args.pd_file)
1039
+ try:
1040
+ jobs = _pd_file_jobs(args.pd_file)
1041
+ except KeyboardInterrupt:
1042
+ print(json.dumps({"error": "interrupted by Ctrl+C"}, indent=2))
1043
+ return 130
1044
+ except Exception as exc:
1045
+ print(json.dumps({"error": str(exc)}, indent=2))
1046
+ return 2
1037
1047
  batch_payload = []
1038
1048
  show_labels = len(jobs) > 1
1039
1049
  for label, line in jobs:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cpp-pd-code-simplify-interface
3
- Version: 0.1.14
3
+ Version: 0.1.16
4
4
  Summary: Python interface for cpp-pd-code-simplify with runtime C++ compilation.
5
5
  License-Expression: MIT
6
6
  Author: GGN_2015
@@ -1,12 +1,12 @@
1
1
  cpp_pd_code_simplify_interface/__init__.py,sha256=aaNwD--zgQX13xiU1hpuvgXy8vVTFGRk-r5zLm8zIRY,447
2
- cpp_pd_code_simplify_interface/__main__.py,sha256=fdA1QWBe5LNX0fbtaJXa1-dwEhrg_4sS_5UnjaajcMo,80
2
+ cpp_pd_code_simplify_interface/__main__.py,sha256=ldwc-YVQlsSH9RwXZHCW4r1pmfCBM0iAYPk5ebM-dUo,238
3
3
  cpp_pd_code_simplify_interface/_worker.py,sha256=RPLUE-4amjh78C1fmFolmSIM2_s8AXWk-2fWvASq7A0,2338
4
- cpp_pd_code_simplify_interface/main.py,sha256=yVWv0zmsJGT3pHhruwK4QaHl3Dn4rJ6spr_fqMMm1Dk,38307
4
+ cpp_pd_code_simplify_interface/main.py,sha256=CDylx7K0tiaNNtu4jYVZfpYMGuSo6tL0RRX5P_lA5bU,39185
5
5
  cpp_pd_code_simplify_interface/py.typed,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
6
- cpp_pd_code_simplify_interface-0.1.14.dist-info/entry_points.txt,sha256=ThorC4Enxp317TKITsXm9pE0gUp7pt-pP6Dl5mEPUR8,91
7
- cpp_pd_code_simplify_interface-0.1.14.dist-info/METADATA,sha256=InpkotMDzumP-fnGzGTHVcpk-LKV0-gvmf8w-wvFYIM,4762
8
- cpp_pd_code_simplify_interface-0.1.14.dist-info/WHEEL,sha256=eY7nduwzv-ldUxpzbRlxwvC693Hg6PX8bWDjEHjZ_dk,88
6
+ cpp_pd_code_simplify_interface-0.1.16.dist-info/entry_points.txt,sha256=ThorC4Enxp317TKITsXm9pE0gUp7pt-pP6Dl5mEPUR8,91
7
+ cpp_pd_code_simplify_interface-0.1.16.dist-info/METADATA,sha256=PqsV_wAaEO9K7FYhzTC5b_8J7m3yq785CrCHQhXxuFA,4762
8
+ cpp_pd_code_simplify_interface-0.1.16.dist-info/WHEEL,sha256=eY7nduwzv-ldUxpzbRlxwvC693Hg6PX8bWDjEHjZ_dk,88
9
9
  cpp_pd_code_simplify_interface/data/include/pdcode_simplify/pdcode_simplify.hpp,sha256=U49Urs6bMXwkygJsVTnXp-q7y_aWkfRfGimy8mxHoms,5195
10
10
  cpp_pd_code_simplify_interface/data/src/native_interface.cpp,sha256=YiYlbGyWTM_FA0V_XzjHtnb9sD4eqMGQmdom6ivm0f0,7094
11
- cpp_pd_code_simplify_interface/data/src/pdcode_simplify.cpp,sha256=A9ozSFzD_bkgrSl_9tIxH6PVAceUix76nRceEO6Ymho,96021
12
- cpp_pd_code_simplify_interface-0.1.14.dist-info/RECORD,,
11
+ cpp_pd_code_simplify_interface/data/src/pdcode_simplify.cpp,sha256=2XhK8pWM_IakPFXybm7k7y3YwvO2Jm73Nn4b5x3HETc,95982
12
+ cpp_pd_code_simplify_interface-0.1.16.dist-info/RECORD,,