Skip to content

Commit 84500be

Browse files
committed
[TO REVERT] store thing
1 parent 733a2c9 commit 84500be

3 files changed

Lines changed: 74 additions & 144 deletions

File tree

src/daqpytools/uml/split_diagram.py

Lines changed: 1 addition & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -24,81 +24,11 @@
2424
import argparse
2525
from pathlib import Path
2626
from collections import defaultdict
27+
from daqpytools.uml.utils import strip_typehints
2728

2829

2930
# ── Helpers ──────────────────────────────────────────────────────────────────
3031

31-
def _strip_param_types(params_str: str) -> str:
32-
"""Strip type hints from a parameter list (the content between parentheses).
33-
34-
Handles complex types like ``dict[str, IssueRecord]`` by counting
35-
bracket depth so inner commas are not treated as parameter separators.
36-
"""
37-
if not params_str.strip():
38-
return params_str
39-
40-
# Split on top-level commas only (not commas inside [] or {})
41-
params, current, depth = [], [], 0
42-
for ch in params_str:
43-
if ch in '[({':
44-
depth += 1
45-
current.append(ch)
46-
elif ch in '])}':
47-
depth -= 1
48-
current.append(ch)
49-
elif ch == ',' and depth == 0:
50-
params.append(''.join(current).strip())
51-
current = []
52-
else:
53-
current.append(ch)
54-
if current:
55-
params.append(''.join(current).strip())
56-
57-
# Keep only the name (everything before the first ':')
58-
stripped = []
59-
for param in params:
60-
colon = param.find(':')
61-
stripped.append(param[:colon].rstrip() if colon != -1 else param)
62-
return ', '.join(stripped)
63-
64-
65-
def strip_typehints(dot_src: str) -> str:
66-
"""Remove type annotations from class/attribute/method labels.
67-
68-
Three-pass approach applied only to lines that carry an HTML label:
69-
70-
1. Return types – strips ``: ReturnType`` that follows a closing ``)``.
71-
e.g. ``filter(record: logging.LogRecord): bool`` → ``filter(record: logging.LogRecord)``
72-
73-
2. Parameter types – strips ``: Type`` from each parameter inside ``()``.
74-
e.g. ``filter(record: logging.LogRecord)`` → ``filter(record)``
75-
Handles complex types such as ``dict[str, IssueRecord]`` correctly.
76-
77-
3. Attribute types – strips `` : Type`` from plain field entries.
78-
e.g. ``initial_threshold : int`` → ``initial_threshold``
79-
"""
80-
lines = dot_src.splitlines()
81-
out_lines = []
82-
83-
for line in lines:
84-
if 'label=<' not in line:
85-
out_lines.append(line)
86-
continue
87-
88-
# Pass 1 – return types: ): ReturnType<br → )<br
89-
line = re.sub(r'(?<=\)):\s*[^<}]+(?=<br|}>)', '', line)
90-
91-
# Pass 2 – parameter types inside ()
92-
def _replace_params(m):
93-
return '(' + _strip_param_types(m.group(1)) + ')'
94-
line = re.sub(r'\(([^)]*)\)', _replace_params, line)
95-
96-
# Pass 3 – attribute types: name : Type<br → name<br
97-
line = re.sub(r'\s*:\s*[^<}]+(?=<br|}>)', '', line)
98-
99-
out_lines.append(line)
100-
101-
return '\n'.join(out_lines)
10232

10333
def parse_dot(dot_src: str):
10434
"""

src/daqpytools/uml/style_pyreverse.py

Lines changed: 2 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727
import sys
2828
import argparse
2929
from pathlib import Path
30+
from daqpytools.uml.utils import strip_typehints
3031

32+
# this is gonna go into its own little file to get saved in
3133

3234
# ── Colour palette (tweak these to your taste) ──────────────────────────────
3335
STYLE = {
@@ -58,79 +60,6 @@ def run_pyreverse(extra_args, output_dir):
5860
return dot_files
5961

6062

61-
def _strip_param_types(params_str: str) -> str:
62-
"""Strip type hints from a parameter list (the content between parentheses).
63-
64-
Handles complex types like ``dict[str, IssueRecord]`` by counting
65-
bracket depth so inner commas are not treated as parameter separators.
66-
"""
67-
if not params_str.strip():
68-
return params_str
69-
70-
# Split on top-level commas only (not commas inside [] or {})
71-
params, current, depth = [], [], 0
72-
for ch in params_str:
73-
if ch in '[({':
74-
depth += 1
75-
current.append(ch)
76-
elif ch in '])}':
77-
depth -= 1
78-
current.append(ch)
79-
elif ch == ',' and depth == 0:
80-
params.append(''.join(current).strip())
81-
current = []
82-
else:
83-
current.append(ch)
84-
if current:
85-
params.append(''.join(current).strip())
86-
87-
# Keep only the name (everything before the first ':')
88-
stripped = []
89-
for param in params:
90-
colon = param.find(':')
91-
stripped.append(param[:colon].rstrip() if colon != -1 else param)
92-
return ', '.join(stripped)
93-
94-
95-
def strip_typehints(dot_src):
96-
"""Remove type annotations from class/attribute/method labels.
97-
98-
Three-pass approach applied only to lines that carry an HTML label:
99-
100-
1. Return types – strips ``: ReturnType`` that follows a closing ``)``.
101-
e.g. ``filter(record: logging.LogRecord): bool`` → ``filter(record: logging.LogRecord)``
102-
103-
2. Parameter types – strips ``: Type`` from each parameter inside ``()``.
104-
e.g. ``filter(record: logging.LogRecord)`` → ``filter(record)``
105-
Handles complex types such as ``dict[str, IssueRecord]`` correctly.
106-
107-
3. Attribute types – strips `` : Type`` from plain field entries.
108-
e.g. ``initial_threshold : int`` → ``initial_threshold``
109-
"""
110-
lines = dot_src.splitlines()
111-
out_lines = []
112-
113-
for line in lines:
114-
if 'label=<' not in line:
115-
out_lines.append(line)
116-
continue
117-
118-
# Pass 1 – return types: ): ReturnType<br → )<br
119-
line = re.sub(r'(?<=\)):\s*[^<}]+(?=<br|}>)', '', line)
120-
121-
# Pass 2 – parameter types inside ()
122-
def _replace_params(m):
123-
return '(' + _strip_param_types(m.group(1)) + ')'
124-
line = re.sub(r'\(([^)]*)\)', _replace_params, line)
125-
126-
# Pass 3 – attribute types: name : Type<br → name<br
127-
line = re.sub(r'\s*:\s*[^<}]+(?=<br|}>)', '', line)
128-
129-
out_lines.append(line)
130-
131-
return '\n'.join(out_lines)
132-
133-
13463
def patch_dot(dot_src, concise=False):
13564
"""Rewrite .dot source to apply a clean UML style."""
13665
s = STYLE

src/daqpytools/uml/utils.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
def _strip_param_types(params_str: str) -> str:
2+
"""Strip type hints from a parameter list (the content between parentheses).
3+
4+
Handles complex types like ``dict[str, IssueRecord]`` by counting
5+
bracket depth so inner commas are not treated as parameter separators.
6+
"""
7+
if not params_str.strip():
8+
return params_str
9+
10+
# Split on top-level commas only (not commas inside [] or {})
11+
params, current, depth = [], [], 0
12+
for ch in params_str:
13+
if ch in '[({':
14+
depth += 1
15+
current.append(ch)
16+
elif ch in '])}':
17+
depth -= 1
18+
current.append(ch)
19+
elif ch == ',' and depth == 0:
20+
params.append(''.join(current).strip())
21+
current = []
22+
else:
23+
current.append(ch)
24+
if current:
25+
params.append(''.join(current).strip())
26+
27+
# Keep only the name (everything before the first ':')
28+
stripped = []
29+
for param in params:
30+
colon = param.find(':')
31+
stripped.append(param[:colon].rstrip() if colon != -1 else param)
32+
return ', '.join(stripped)
33+
34+
35+
def strip_typehints(dot_src):
36+
"""Remove type annotations from class/attribute/method labels.
37+
38+
Three-pass approach applied only to lines that carry an HTML label:
39+
40+
1. Return types – strips ``: ReturnType`` that follows a closing ``)``.
41+
e.g. ``filter(record: logging.LogRecord): bool`` → ``filter(record: logging.LogRecord)``
42+
43+
2. Parameter types – strips ``: Type`` from each parameter inside ``()``.
44+
e.g. ``filter(record: logging.LogRecord)`` → ``filter(record)``
45+
Handles complex types such as ``dict[str, IssueRecord]`` correctly.
46+
47+
3. Attribute types – strips `` : Type`` from plain field entries.
48+
e.g. ``initial_threshold : int`` → ``initial_threshold``
49+
"""
50+
lines = dot_src.splitlines()
51+
out_lines = []
52+
53+
for line in lines:
54+
if 'label=<' not in line:
55+
out_lines.append(line)
56+
continue
57+
58+
# Pass 1 – return types: ): ReturnType<br → )<br
59+
line = re.sub(r'(?<=\)):\s*[^<}]+(?=<br|}>)', '', line)
60+
61+
# Pass 2 – parameter types inside ()
62+
def _replace_params(m):
63+
return '(' + _strip_param_types(m.group(1)) + ')'
64+
line = re.sub(r'\(([^)]*)\)', _replace_params, line)
65+
66+
# Pass 3 – attribute types: name : Type<br → name<br
67+
line = re.sub(r'\s*:\s*[^<}]+(?=<br|}>)', '', line)
68+
69+
out_lines.append(line)
70+
71+
return '\n'.join(out_lines)

0 commit comments

Comments
 (0)