Skip to content

Commit db9be29

Browse files
committed
simplify
1 parent c296f37 commit db9be29

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

src/_pytest/main.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
from pathlib import Path
1818
import sys
1919
from typing import AbstractSet
20-
from typing import Any
2120
from typing import Callable
2221
from typing import final
2322
from typing import Literal
@@ -372,7 +371,7 @@ def pytest_runtestloop(session: Session) -> bool:
372371
return True
373372

374373

375-
def _decode_toml_file(toml: Path) -> dict[str, Any] | None:
374+
def _is_setuptools_in_pyproject_toml(toml: Path) -> bool:
376375
"""Attempt to decode a toml file into a dict, returning None if fails."""
377376
if sys.version_info >= (3, 11):
378377
import tomllib
@@ -381,9 +380,14 @@ def _decode_toml_file(toml: Path) -> dict[str, Any] | None:
381380

382381
try:
383382
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
387391

388392

389393
def _in_build(path: Path) -> bool:
@@ -401,15 +405,9 @@ def _in_build(path: Path) -> bool:
401405
if setup_py.is_file():
402406
return True
403407

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
413411

414412
return False
415413

0 commit comments

Comments
 (0)