17
17
from pathlib import Path
18
18
import sys
19
19
from typing import AbstractSet
20
- from typing import Any
21
20
from typing import Callable
22
21
from typing import final
23
22
from typing import Literal
@@ -372,7 +371,7 @@ def pytest_runtestloop(session: Session) -> bool:
372
371
return True
373
372
374
373
375
- def _decode_toml_file (toml : Path ) -> dict [ str , Any ] | None :
374
+ def _is_setuptools_in_pyproject_toml (toml : Path ) -> bool :
376
375
"""Attempt to decode a toml file into a dict, returning None if fails."""
377
376
if sys .version_info >= (3 , 11 ):
378
377
import tomllib
@@ -381,9 +380,14 @@ def _decode_toml_file(toml: Path) -> dict[str, Any] | None:
381
380
382
381
try :
383
382
toml_text = toml .read_text (encoding = "utf-8" )
384
- return tomllib .loads (toml_text )
385
- except tomllib .TOMLDecodeError :
386
- return None
383
+ parsed_toml = tomllib .loads (toml_text )
384
+ build_system = parsed_toml .get ("build-system" , {}).get ("requires" )
385
+ if "setuptools" in build_system :
386
+ return True
387
+ except Exception :
388
+ pass
389
+
390
+ return False
387
391
388
392
389
393
def _in_build (path : Path ) -> bool :
@@ -401,15 +405,9 @@ def _in_build(path: Path) -> bool:
401
405
if setup_py .is_file ():
402
406
return True
403
407
404
- pyproject_toml = path .parent / "pyproject.toml"
405
- if pyproject_toml .is_file ():
406
- config = _decode_toml_file (pyproject_toml )
407
- if config :
408
- if any (
409
- "setuptools" in cfg
410
- for cfg in config .get ("build-system" , {}).get ("requires" , {})
411
- ):
412
- return True
408
+ toml = path .parent / "pyproject.toml"
409
+ if toml .is_file () and _is_setuptools_in_pyproject_toml (toml ):
410
+ return True
413
411
414
412
return False
415
413
0 commit comments