@@ -102,10 +102,25 @@ def _strip(line: str):
102
102
comments [:] = map (_strip , comments )
103
103
104
104
105
- def default_directory_filter (dirpath : str | os .PathLike [str ]) -> bool :
106
- subdir = os .path .basename (dirpath )
107
- # Legacy default behavior: ignore dot and underscore directories
108
- return not (subdir .startswith ('.' ) or subdir .startswith ('_' ))
105
+ def make_default_directory_filter (
106
+ method_map : Iterable [tuple [str , str ]],
107
+ root_dir : str | os .PathLike [str ],
108
+ ):
109
+ def directory_filter (dirpath : str | os .PathLike [str ]) -> bool :
110
+ subdir = os .path .basename (dirpath )
111
+ # Legacy default behavior: ignore dot and underscore directories
112
+ if subdir .startswith ('.' ) or subdir .startswith ('_' ):
113
+ return False
114
+
115
+ dir_rel = os .path .relpath (dirpath , root_dir ).replace (os .sep , '/' )
116
+
117
+ for pattern , method in method_map :
118
+ if method == "ignore" and pathmatch (pattern , dir_rel ):
119
+ return False
120
+
121
+ return True
122
+
123
+ return directory_filter
109
124
110
125
111
126
def extract_from_dir (
@@ -189,13 +204,19 @@ def extract_from_dir(
189
204
"""
190
205
if dirname is None :
191
206
dirname = os .getcwd ()
207
+
192
208
if options_map is None :
193
209
options_map = {}
210
+
211
+ dirname = os .path .abspath (dirname )
212
+
194
213
if directory_filter is None :
195
- directory_filter = default_directory_filter
214
+ directory_filter = make_default_directory_filter (
215
+ method_map = method_map ,
216
+ root_dir = dirname ,
217
+ )
196
218
197
- absname = os .path .abspath (dirname )
198
- for root , dirnames , filenames in os .walk (absname ):
219
+ for root , dirnames , filenames in os .walk (dirname ):
199
220
dirnames [:] = [
200
221
subdir for subdir in dirnames
201
222
if directory_filter (os .path .join (root , subdir ))
@@ -213,7 +234,7 @@ def extract_from_dir(
213
234
keywords ,
214
235
comment_tags ,
215
236
strip_comment_tags ,
216
- dirpath = absname ,
237
+ dirpath = dirname ,
217
238
)
218
239
219
240
0 commit comments