32
32
import warnings
33
33
34
34
from typing import (
35
- Any , ClassVar , DefaultDict , Dict , List , Optional , Sequence , Set , TextIO ,
36
- Tuple , Type , Union
35
+ Any , Callable , ClassVar , DefaultDict , Dict , List , Optional , Sequence , Set ,
36
+ TextIO , Tuple , Type , TypeVar , Union
37
37
)
38
38
39
39
49
49
import mesonpy ._wheelfile
50
50
51
51
from mesonpy ._compat import (
52
- Collection , Iterator , Literal , Mapping , Path , typing_get_args
52
+ Collection , Iterator , Literal , Mapping , ParamSpec , Path , typing_get_args
53
53
)
54
54
55
55
67
67
68
68
69
69
_COLORS = {
70
+ 'red' : '\33 [31m' ,
70
71
'cyan' : '\33 [36m' ,
71
72
'yellow' : '\33 [93m' ,
72
73
'light_blue' : '\33 [94m' ,
@@ -137,11 +138,16 @@ def _setup_cli() -> None:
137
138
colorama .init () # fix colors on windows
138
139
139
140
140
- class ConfigError (Exception ):
141
+ class Error (RuntimeError ):
142
+ def __str__ (self ) -> str :
143
+ return str (self .args [0 ])
144
+
145
+
146
+ class ConfigError (Error ):
141
147
"""Error in the backend configuration."""
142
148
143
149
144
- class MesonBuilderError (Exception ):
150
+ class MesonBuilderError (Error ):
145
151
"""Error when building the Meson package."""
146
152
147
153
@@ -1047,12 +1053,29 @@ def _env_ninja_command(*, version: str = _NINJA_REQUIRED_VERSION) -> Optional[pa
1047
1053
return None
1048
1054
1049
1055
1056
+ P = ParamSpec ('P' )
1057
+ T = TypeVar ('T' )
1058
+
1059
+
1060
+ def _pyproject_hook (func : Callable [P , T ]) -> Callable [P , T ]:
1061
+ @functools .wraps (func )
1062
+ def wrapper (* args : P .args , ** kwargs : P .kwargs ) -> T :
1063
+ try :
1064
+ return func (* args , ** kwargs )
1065
+ except Error as exc :
1066
+ print ('{red}meson-python: error:{reset} {msg}' .format (msg = str (exc ), ** _STYLES ))
1067
+ raise SystemExit (1 )
1068
+ return wrapper
1069
+
1070
+
1071
+ @_pyproject_hook
1050
1072
def get_requires_for_build_sdist (
1051
1073
config_settings : Optional [Dict [str , str ]] = None ,
1052
1074
) -> List [str ]:
1053
1075
return [_depstr .ninja ] if _env_ninja_command () is None else []
1054
1076
1055
1077
1078
+ @_pyproject_hook
1056
1079
def build_sdist (
1057
1080
sdist_directory : str ,
1058
1081
config_settings : Optional [Dict [Any , Any ]] = None ,
@@ -1064,6 +1087,7 @@ def build_sdist(
1064
1087
return project .sdist (out ).name
1065
1088
1066
1089
1090
+ @_pyproject_hook
1067
1091
def get_requires_for_build_wheel (
1068
1092
config_settings : Optional [Dict [str , str ]] = None ,
1069
1093
) -> List [str ]:
@@ -1089,6 +1113,7 @@ def get_requires_for_build_wheel(
1089
1113
return dependencies
1090
1114
1091
1115
1116
+ @_pyproject_hook
1092
1117
def build_wheel (
1093
1118
wheel_directory : str ,
1094
1119
config_settings : Optional [Dict [Any , Any ]] = None ,
0 commit comments