12
12
from pathlib import Path
13
13
import sys
14
14
from typing import AbstractSet
15
- from typing import Any
16
15
from typing import Callable
17
16
from typing import Dict
18
17
from typing import final
@@ -366,7 +365,7 @@ def pytest_runtestloop(session: Session) -> bool:
366
365
return True
367
366
368
367
369
- def _decode_toml_file (toml : Path ) -> dict [ str , Any ] | None :
368
+ def _is_setuptools_in_pyproject_toml (toml : Path ) -> bool :
370
369
"""Attempt to decode a toml file into a dict, returning None if fails."""
371
370
if sys .version_info >= (3 , 11 ):
372
371
import tomllib
@@ -375,9 +374,14 @@ def _decode_toml_file(toml: Path) -> dict[str, Any] | None:
375
374
376
375
try :
377
376
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
381
385
382
386
383
387
def _in_build (path : Path ) -> bool :
@@ -395,15 +399,9 @@ def _in_build(path: Path) -> bool:
395
399
if setup_py .is_file ():
396
400
return True
397
401
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
407
405
408
406
return False
409
407
0 commit comments