@@ -111,10 +111,25 @@ def _strip(line: str):
111
111
comments [:] = map (_strip , comments )
112
112
113
113
114
- def default_directory_filter (dirpath : str | os .PathLike [str ]) -> bool :
115
- subdir = os .path .basename (dirpath )
116
- # Legacy default behavior: ignore dot and underscore directories
117
- return not (subdir .startswith ('.' ) or subdir .startswith ('_' ))
114
+ def make_default_directory_filter (
115
+ method_map : Iterable [tuple [str , str ]],
116
+ root_dir : str | os .PathLike [str ],
117
+ ):
118
+ def directory_filter (dirpath : str | os .PathLike [str ]) -> bool :
119
+ subdir = os .path .basename (dirpath )
120
+ # Legacy default behavior: ignore dot and underscore directories
121
+ if subdir .startswith ('.' ) or subdir .startswith ('_' ):
122
+ return False
123
+
124
+ dir_rel = os .path .relpath (dirpath , root_dir ).replace (os .sep , '/' )
125
+
126
+ for pattern , method in method_map :
127
+ if method == "ignore" and pathmatch (pattern , dir_rel ):
128
+ return False
129
+
130
+ return True
131
+
132
+ return directory_filter
118
133
119
134
120
135
def extract_from_dir (
@@ -198,13 +213,19 @@ def extract_from_dir(
198
213
"""
199
214
if dirname is None :
200
215
dirname = os .getcwd ()
216
+
201
217
if options_map is None :
202
218
options_map = {}
219
+
220
+ dirname = os .path .abspath (dirname )
221
+
203
222
if directory_filter is None :
204
- directory_filter = default_directory_filter
223
+ directory_filter = make_default_directory_filter (
224
+ method_map = method_map ,
225
+ root_dir = dirname ,
226
+ )
205
227
206
- absname = os .path .abspath (dirname )
207
- for root , dirnames , filenames in os .walk (absname ):
228
+ for root , dirnames , filenames in os .walk (dirname ):
208
229
dirnames [:] = [
209
230
subdir for subdir in dirnames
210
231
if directory_filter (os .path .join (root , subdir ))
@@ -222,7 +243,7 @@ def extract_from_dir(
222
243
keywords ,
223
244
comment_tags ,
224
245
strip_comment_tags ,
225
- dirpath = absname ,
246
+ dirpath = dirname ,
226
247
)
227
248
228
249
0 commit comments