@@ -143,6 +143,23 @@ def get_min_scipy_version(min_python, min_numpy):
143143 return df .SciPy_version
144144
145145
146+ def match_pkg_version (line , pkg_name ):
147+ """
148+ Regular expression to match package versions
149+ """
150+ matches = re .search (
151+ rf"""
152+ { pkg_name } # Package name
153+ [\s=><:"\'\[\]]* # Zero or more spaces or special characters
154+ (\d+\.\d+[\.0-9]*) # Capture "version" in `matches`
155+ """ ,
156+ line ,
157+ re .VERBOSE | re .IGNORECASE , # Ignores all whitespace and case in pattern
158+ )
159+
160+ return matches
161+
162+
146163def find_pkg_mismatches (pkg_name , pkg_version , fnames ):
147164 """
148165 Determine if any package version has mismatches
@@ -153,15 +170,7 @@ def find_pkg_mismatches(pkg_name, pkg_version, fnames):
153170 with open (fname , "r" ) as file :
154171 for line_num , line in enumerate (file , start = 1 ):
155172 l = line .strip ().replace (" " , "" ).lower ()
156- matches = re .search (
157- rf"""
158- { pkg_name } # Package name
159- [=><:"\'\[\]]+ # Zero or more special characters
160- (\d+\.\d+[\.0-9]*) # Capture "version" in `matches`
161- """ ,
162- l ,
163- re .VERBOSE , # Ignores all whitespace in pattern
164- )
173+ matches = match_pkg_version (l , pkg_name )
165174 if matches is not None :
166175 version = matches .groups ()[0 ]
167176 if version != pkg_version :
@@ -170,6 +179,39 @@ def find_pkg_mismatches(pkg_name, pkg_version, fnames):
170179 return pkg_mismatches
171180
172181
182+ def test_pkg_mismatch_regex ():
183+ """
184+ Validation function for the package mismatch regex
185+ """
186+ pkgs = {
187+ "numpy" : "0.0" ,
188+ "scipy" : "0.0" ,
189+ "python" : "2.7" ,
190+ "python-version" : "2.7" ,
191+ "numba" : "0.0" ,
192+ }
193+
194+ lines = [
195+ "Programming Language :: Python :: 3.8" ,
196+ "STUMPY supports Python 3.8" ,
197+ "python-version: ['3.8']" ,
198+ 'requires-python = ">=3.8"' ,
199+ "numba>=0.55.2" ,
200+ ]
201+
202+ for line in lines :
203+ match_found = False
204+ for pkg_name , pkg_version in pkgs .items ():
205+ matches = match_pkg_version (line , pkg_name )
206+
207+ if matches :
208+ match_found = True
209+ break
210+
211+ if not match_found :
212+ raise ValueError (f'Package mismatch regex fails to cover/match "{ line } "' )
213+
214+
173215if __name__ == "__main__" :
174216 parser = argparse .ArgumentParser ()
175217 parser .add_argument ("min_python" , nargs = "?" , default = None )
@@ -205,6 +247,8 @@ def find_pkg_mismatches(pkg_name, pkg_version, fnames):
205247 "README.rst" ,
206248 ]
207249
250+ test_pkg_mismatch_regex ()
251+
208252 for pkg_name , pkg_version in pkgs .items ():
209253 for name , version , fname , line_num in find_pkg_mismatches (
210254 pkg_name , pkg_version , fnames
0 commit comments