10
10
import pathlib
11
11
import sys
12
12
from collections import defaultdict
13
+ from typing import List , Optional , Tuple
13
14
14
15
from .. import linter , parser
15
16
from ..pragmas import find_pytmc_symbols , record_packages_from_symbol
16
- from ..record import generate_archive_settings
17
+ from ..record import RecordPackage , generate_archive_settings
17
18
18
19
logger = logging .getLogger (__name__ )
19
20
DESCRIPTION = __doc__
@@ -74,21 +75,45 @@ def validate_with_dbd(packages, dbd_file, remove_invalid_fields=True,
74
75
return results , db_text
75
76
76
77
77
- def process (tmc , * , dbd_file = None , allow_errors = False , show_error_context = True ,
78
- allow_no_pragma = False , debug = False ):
78
+ def process (
79
+ tmc : parser .TcModuleClass ,
80
+ * ,
81
+ dbd_file : Optional [parser .AnyPath ] = None ,
82
+ allow_errors : bool = False ,
83
+ show_error_context : bool = True ,
84
+ allow_no_pragma : bool = False ,
85
+ debug : bool = False
86
+ ) -> Tuple [List [RecordPackage ], List [Exception ]]:
79
87
'''
80
88
Process a TMC
81
89
82
90
Parameters
83
91
----------
84
92
tmc : TcModuleClass
93
+ The parsed TMC file instance.
94
+ dbd_file : str or DbdFile, optional
95
+ The dbd file with which to validate
96
+ allow_errors : bool, optional
97
+ Allow processing to continue even with errors.
98
+ show_error_context : bool, optional
99
+ Show context from the database file around the error.
100
+ allow_no_pragma : bool, optional
101
+ Allow intermediate objects to not have a pytmc pragma and still regard
102
+ it as valid, assuming at least the first and last item have pragmas.
103
+ debug : bool, optional
104
+ Debug mode.
85
105
86
106
Returns
87
107
-------
88
108
records : list
89
109
List of RecordPackage
90
110
exceptions : list
91
111
List of exceptions raised during parsing
112
+
113
+ Raises
114
+ ------
115
+ LinterError
116
+ If ``allow_errors`` is unset and an error is found.
92
117
'''
93
118
def _show_context_from_line (rendered , from_line ):
94
119
lines = list (enumerate (rendered .splitlines ()[:from_line + 1 ], 1 ))
@@ -107,8 +132,8 @@ def _show_context_from_line(rendered, from_line):
107
132
record
108
133
for symbol in find_pytmc_symbols (tmc , allow_no_pragma = allow_no_pragma )
109
134
for record in record_packages_from_symbol (
110
- symbol , yield_exceptions = not debug ,
111
- allow_no_pragma = allow_no_pragma )
135
+ symbol , yield_exceptions = not debug , allow_no_pragma = allow_no_pragma
136
+ )
112
137
]
113
138
114
139
exceptions = [ex for ex in records
@@ -121,10 +146,20 @@ def _show_context_from_line(rendered, from_line):
121
146
if exceptions and not allow_errors :
122
147
raise LinterError ('Failed to create database' )
123
148
124
- record_names = [single_record .pvname
125
- for record_package in records if record_package .valid
126
- for single_record in record_package .records
127
- ]
149
+ # We removed exceptions from the record list above:
150
+ records : List [RecordPackage ]
151
+
152
+ def by_tcname (record : RecordPackage ):
153
+ return record .tcname
154
+
155
+ records .sort (key = by_tcname )
156
+
157
+ record_names = [
158
+ single_record .pvname
159
+ for record_package in records
160
+ if record_package .valid
161
+ for single_record in record_package .records
162
+ ]
128
163
129
164
if len (record_names ) != len (set (record_names )):
130
165
dupes = {name : record_names .count (name )
0 commit comments