-
Notifications
You must be signed in to change notification settings - Fork 54
/
Copy patherrors.py
101 lines (74 loc) · 2.1 KB
/
errors.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
from __future__ import annotations
import textwrap
from typing import TYPE_CHECKING
if TYPE_CHECKING:
import subprocess
__all__ = [
"CMakeAccessError",
"CMakeConfigError",
"CMakeNotFoundError",
"CMakeVersionError",
"NinjaVersionError",
"FailedLiveProcessError",
"FailedProcessError",
"NinjaNotFoundError",
"NotFoundError",
"ScikitBuildError",
]
def __dir__() -> list[str]:
return __all__
class ScikitBuildError(Exception):
"""
Base class for all ScikitBuildError errors.
"""
class NotFoundError(ScikitBuildError):
"""
Raised when a program is not found.
"""
class CMakeNotFoundError(NotFoundError):
"""
Raised when cmake is not found.
"""
class NinjaNotFoundError(NotFoundError):
"""
Raised when ninja is not found.
"""
class FailedProcessError(Exception):
"""
Exception raised when an call fails.
"""
def __init__(
self, exception: subprocess.CalledProcessError, description: str
) -> None:
super().__init__()
self.exception = exception
self._description = description
def __str__(self) -> str:
cmd = " ".join(self.exception.cmd)
description = f"{self._description}\n Command {cmd!r} failed with return code {self.exception.returncode}"
for stream_name in ("stdout", "stderr"):
stream = getattr(self.exception, stream_name)
if stream:
description += f"\n {stream_name}:\n"
description += textwrap.indent(stream.decode(), " ")
return description
class FailedLiveProcessError(Exception):
"""
Exception for when output was not being redirected.
"""
class CMakeAccessError(FailedProcessError):
"""
Error raised when CMake access fails.
"""
class CMakeVersionError(ScikitBuildError):
"""
Error raised when CMake version is not supported.
"""
class NinjaVersionError(ScikitBuildError):
"""
Error raised when CMake version is not supported.
"""
class CMakeConfigError(ScikitBuildError):
"""
Something is misconfigured.
"""