@@ -229,6 +229,28 @@ def split_commas(value: str) -> list[str]:
229
229
)
230
230
231
231
232
+ def _find_pyproject () -> list [str ]:
233
+ """Search for file pyproject.toml in the parent directories recursively.
234
+
235
+ It resolves symlinks, so if there is any symlink up in the tree, it does not respect them
236
+ """
237
+ # We start from the parent dir, since 'pyproject.toml' is already parsed
238
+ current_dir = os .path .abspath (os .path .join (os .path .curdir , os .path .pardir ))
239
+ is_root = False
240
+ while not is_root :
241
+ for pyproject_name in defaults .PYPROJECT_CONFIG_FILES :
242
+ config_file = os .path .join (current_dir , pyproject_name )
243
+ if os .path .isfile (config_file ):
244
+ return [os .path .abspath (config_file )]
245
+ parent = os .path .abspath (os .path .join (current_dir , os .path .pardir ))
246
+ is_root = current_dir == parent or any (
247
+ os .path .isdir (os .path .join (current_dir , cvs_root )) for cvs_root in (".git" , ".hg" )
248
+ )
249
+ current_dir = parent
250
+
251
+ return []
252
+
253
+
232
254
def parse_config_file (
233
255
options : Options ,
234
256
set_strict_flags : Callable [[], None ],
@@ -248,7 +270,9 @@ def parse_config_file(
248
270
if filename is not None :
249
271
config_files : tuple [str , ...] = (filename ,)
250
272
else :
251
- config_files_iter : Iterable [str ] = map (os .path .expanduser , defaults .CONFIG_FILES )
273
+ config_files_iter : Iterable [str ] = map (
274
+ os .path .expanduser , defaults .CONFIG_FILES + _find_pyproject ()
275
+ )
252
276
config_files = tuple (config_files_iter )
253
277
254
278
config_parser = configparser .RawConfigParser ()
0 commit comments