5
5
from pathlib import Path
6
6
from typing import TYPE_CHECKING
7
7
8
+ from tox .config .types import MissingRequiredConfigKeyError
8
9
from tox .report import HandledError
9
10
10
11
from .legacy_toml import LegacyToml
@@ -59,21 +60,32 @@ def _locate_source() -> Source | None:
59
60
for base in chain ([folder ], folder .parents ):
60
61
for src_type in SOURCE_TYPES :
61
62
candidate : Path = base / src_type .FILENAME
62
- try :
63
- return src_type (candidate )
64
- except ValueError :
65
- pass
63
+ if candidate .exists ():
64
+ try :
65
+ return src_type (candidate )
66
+ except MissingRequiredConfigKeyError as exc :
67
+ msg = f"{ src_type .__name__ } skipped loading { candidate .resolve ()} due to { exc } "
68
+ logging .info (msg )
69
+ except ValueError as exc :
70
+ msg = f"{ src_type .__name__ } failed loading { candidate .resolve ()} due to { exc } "
71
+ raise HandledError (msg ) from exc
66
72
return None
67
73
68
74
69
75
def _load_exact_source (config_file : Path ) -> Source :
70
76
# if the filename matches to the letter some config file name do not fallback to other source types
77
+ if not config_file .exists ():
78
+ msg = f"config file { config_file } does not exist"
79
+ raise HandledError (msg )
71
80
exact_match = [s for s in SOURCE_TYPES if config_file .name == s .FILENAME ] # pragma: no cover
72
81
for src_type in exact_match or SOURCE_TYPES : # pragma: no branch
73
82
try :
74
83
return src_type (config_file )
75
- except ValueError : # noqa: PERF203
84
+ except MissingRequiredConfigKeyError : # noqa: PERF203
76
85
pass
86
+ except ValueError as exc :
87
+ msg = f"{ src_type .__name__ } failed loading { config_file .resolve ()} due to { exc } "
88
+ raise HandledError (msg ) from exc
77
89
msg = f"could not recognize config file { config_file } "
78
90
raise HandledError (msg )
79
91
@@ -88,7 +100,7 @@ def _create_default_source(root_dir: Path | None) -> Source:
88
100
else : # if not set use where we find pyproject.toml in the tree or cwd
89
101
empty = root_dir
90
102
names = " or " .join ({i .FILENAME : None for i in SOURCE_TYPES })
91
- logging .warning ("No %s found, assuming empty tox.ini at %s" , names , empty )
103
+ logging .warning ("No loadable %s found, assuming empty tox.ini at %s" , names , empty )
92
104
return ToxIni (empty / "tox.ini" , content = "" )
93
105
94
106
0 commit comments