@@ -223,18 +223,28 @@ def __init__(
223
223
self ._config_file_path = config_file_path
224
224
self ._load_external_modules = load_external_modules
225
225
paths = paths or []
226
+
227
+ # Expand paths with glob patterns.
226
228
glob_base_dir = os .path .dirname (os .path .abspath (config_file_path )) if config_file_path else "."
227
229
with chdir (glob_base_dir ):
228
230
resolved_globs = [glob .glob (path ) for path in paths ]
229
231
paths = [path for glob_list in resolved_globs for path in glob_list ]
232
+
233
+ # By default, add the directory of the config file to the search paths.
230
234
if not paths and config_file_path :
231
235
paths .append (os .path .dirname (config_file_path ))
232
- search_paths = [path for path in sys .path if path ] # eliminate empty path
236
+
237
+ # Initialize search paths from `sys.path`, eliminating empty paths.
238
+ search_paths = [path for path in sys .path if path ]
239
+
233
240
for path in reversed (paths ):
241
+ # If it's not absolute, make path relative to the config file path, then make it absolute.
234
242
if not os .path .isabs (path ) and config_file_path :
235
243
path = os .path .abspath (os .path .join (os .path .dirname (config_file_path ), path )) # noqa: PLW2901
244
+ # Don't add duplicates.
236
245
if path not in search_paths :
237
246
search_paths .insert (0 , path )
247
+
238
248
self ._paths = search_paths
239
249
self ._modules_collection : ModulesCollection = ModulesCollection ()
240
250
self ._lines_collection : LinesCollection = LinesCollection ()
0 commit comments