File tree 1 file changed +39
-0
lines changed
1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change
1
+ import re
2
+
3
+
4
+ def _force_regex_list (regs ):
5
+ '''
6
+ Convert a string or list of strings into a list of regexes.
7
+ '''
8
+ if type (regs ) != list :
9
+ regs = [regs ]
10
+
11
+ return list (map (lambda r : re .compile (r ), regs ))
12
+
13
+
14
+ def _match_regs (regs , name ):
15
+ '''
16
+ Return true if the name fully matches one of the regexes on the list.
17
+ '''
18
+ for reg in regs :
19
+ if reg .fullmatch (name ) is not None :
20
+ return True
21
+ return False
22
+
23
+
24
+ class NameFilter :
25
+ '''
26
+ Holds the name filter configuration and performs the filtering.
27
+ '''
28
+ def __init__ (self , config ) -> None :
29
+ self ._include = _force_regex_list (config .get ('include_files' , '.*' ) or '.*' )
30
+ self ._exclude = _force_regex_list (config .get ('exclude_files' , []) or [])
31
+
32
+ def _is_included (self , name ):
33
+ return _match_regs (self ._include , name )
34
+
35
+ def _is_excluded (self , name ):
36
+ return _match_regs (self ._exclude , name )
37
+
38
+ def valid_name (self , name ):
39
+ return self ._is_included (name ) and not self ._is_excluded (name )
You can’t perform that action at this time.
0 commit comments