1212from pathlib import Path
1313import sys
1414from typing import AbstractSet
15- from typing import Any
1615from typing import Callable
1716from typing import Dict
1817from typing import final
@@ -366,7 +365,7 @@ def pytest_runtestloop(session: Session) -> bool:
366365 return True
367366
368367
369- def _decode_toml_file (toml : Path ) -> dict [ str , Any ] | None :
368+ def _is_setuptools_in_pyproject_toml (toml : Path ) -> bool :
370369 """Attempt to decode a toml file into a dict, returning None if fails."""
371370 if sys .version_info >= (3 , 11 ):
372371 import tomllib
@@ -375,9 +374,14 @@ def _decode_toml_file(toml: Path) -> dict[str, Any] | None:
375374
376375 try :
377376 toml_text = toml .read_text (encoding = "utf-8" )
378- return tomllib .loads (toml_text )
379- except tomllib .TOMLDecodeError :
380- return None
377+ parsed_toml = tomllib .loads (toml_text )
378+ build_system = parsed_toml .get ("build-system" , {}).get ("requires" )
379+ if "setuptools" in build_system :
380+ return True
381+ except Exception :
382+ pass
383+
384+ return False
381385
382386
383387def _in_build (path : Path ) -> bool :
@@ -395,15 +399,9 @@ def _in_build(path: Path) -> bool:
395399 if setup_py .is_file ():
396400 return True
397401
398- pyproject_toml = path .parent / "pyproject.toml"
399- if pyproject_toml .is_file ():
400- config = _decode_toml_file (pyproject_toml )
401- if config :
402- if any (
403- "setuptools" in cfg
404- for cfg in config .get ("build-system" , {}).get ("requires" , {})
405- ):
406- return True
402+ toml = path .parent / "pyproject.toml"
403+ if toml .is_file () and _is_setuptools_in_pyproject_toml (toml ):
404+ return True
407405
408406 return False
409407
0 commit comments