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