@@ -46,8 +46,9 @@ class WaiveParseError(SyntaxError):
46
46
Easy waiver file syntax error reporting, with line numbers derived
47
47
from _PushbackIterator style counter.
48
48
"""
49
- def __init__ (self , meta , msg ):
50
- super ().__init__ (f"waiver line { meta .counter } : { msg } " )
49
+ def __init__ (self , filedesc , msg ):
50
+ file , line = filedesc
51
+ super ().__init__ (f"waiver { file } :{ line } : { msg } " )
51
52
52
53
53
54
def _compile_eval (meta , code ):
@@ -59,7 +60,7 @@ def _compile_eval(meta, code):
59
60
raise WaiveParseError (meta , "compiling waiver python code failed" )
60
61
61
62
62
- def _parse_waiver_file (stream ):
63
+ def _parse_waiver_file (stream , filename ):
63
64
sections = []
64
65
regexes = set ()
65
66
python_code = ''
@@ -70,6 +71,7 @@ def _parse_waiver_file(stream):
70
71
if line .startswith ('#' ):
71
72
continue
72
73
line = line .rstrip ('\n ' )
74
+ filedesc = (filename , lines .counter )
73
75
74
76
# between regex+python blocks
75
77
if state == 'skipping_empty_lines' :
@@ -82,19 +84,19 @@ def _parse_waiver_file(stream):
82
84
# collecting adjacent/subsequent regex lines
83
85
elif state == 'reading_regex' :
84
86
if not line :
85
- raise WaiveParseError (lines , "unexpected empty line between regexes" )
87
+ raise WaiveParseError (filedesc , "unexpected empty line between regexes" )
86
88
87
89
# until we see an indented line (beginning with space), just collect
88
90
# regex lines into a buffer
89
91
if not line .startswith ((' ' , '\t ' )):
90
92
try :
91
93
regexes .add (re .compile (line ))
92
94
except re .error as e :
93
- raise WaiveParseError (lines , f"regex failed: { e } " )
95
+ raise WaiveParseError (filedesc , f"regex failed: { e } " )
94
96
else :
95
97
# indented line found, which means it's a python code - parse it
96
98
if not regexes :
97
- raise WaiveParseError (lines , "python block without a preceding regexp" )
99
+ raise WaiveParseError (filedesc , "python block without a preceding regexp" )
98
100
state = 'reading_python'
99
101
lines .pushback ()
100
102
@@ -114,7 +116,7 @@ def _parse_waiver_file(stream):
114
116
lines .pushback ()
115
117
116
118
if regexes and not python_code :
117
- raise WaiveParseError (lines , "no python block follows the regexp" )
119
+ raise WaiveParseError (filedesc , "no python block follows the regexp" )
118
120
119
121
# still inside last python block - the append & cleanup section did not
120
122
# get to run because the iterator stopped because there was nothing left
@@ -126,7 +128,7 @@ def _parse_waiver_file(stream):
126
128
return sections
127
129
128
130
129
- def _collect_waivers ():
131
+ def collect_waivers ():
130
132
"""
131
133
Recursively walk a directory of waiver files/directories,
132
134
yielding waiver sections.
@@ -148,8 +150,9 @@ def _collect_files(in_dir):
148
150
yield item
149
151
150
152
for file in _collect_files (dir_path ):
153
+ relative = file .relative_to (dir_path )
151
154
with open (file ) as f :
152
- yield from _parse_waiver_file (f )
155
+ yield from _parse_waiver_file (f , str ( relative ) )
153
156
154
157
155
158
class Match :
@@ -168,7 +171,7 @@ def __bool__(self):
168
171
def match_result (status , name , note ):
169
172
global _sections_cache
170
173
if _sections_cache is None :
171
- _sections_cache = list (_collect_waivers ())
174
+ _sections_cache = list (collect_waivers ())
172
175
173
176
# make sure "'someting' in name" always works
174
177
if name is None :
0 commit comments