summaryrefslogtreecommitdiff
path: root/mesonbuild/dependencies/python.py
diff options
context:
space:
mode:
authorEli Schwartz <eschwartz93@gmail.com>2023-12-25 02:32:14 -0500
committerEli Schwartz <eschwartz93@gmail.com>2024-02-12 18:52:43 -0500
commit6e1556028c15ba92fff32ad68c88edf143d42c16 (patch)
treed78ccb07c4f490e626af0fc0745f66d3c9316847 /mesonbuild/dependencies/python.py
parent546fe0f92b8e3e85f85ee6bdf07f8cc6156f0850 (diff)
downloadmeson-6e1556028c15ba92fff32ad68c88edf143d42c16.tar.gz
python dependency: use exceptions to pass failure state around
Instead of returning Optional, a state that is only possible during `__init__` and which prevents mypy from knowing what it is safe to assume it will get.
Diffstat (limited to 'mesonbuild/dependencies/python.py')
-rw-r--r--mesonbuild/dependencies/python.py16
1 files changed, 8 insertions, 8 deletions
diff --git a/mesonbuild/dependencies/python.py b/mesonbuild/dependencies/python.py
index 6620eff20..b9b17f854 100644
--- a/mesonbuild/dependencies/python.py
+++ b/mesonbuild/dependencies/python.py
@@ -8,7 +8,7 @@ from pathlib import Path
import typing as T
from .. import mesonlib, mlog
-from .base import process_method_kw, DependencyMethods, DependencyTypeName, ExternalDependency, SystemDependency
+from .base import process_method_kw, DependencyException, DependencyMethods, DependencyTypeName, ExternalDependency, SystemDependency
from .configtool import ConfigToolDependency
from .detect import packages
from .factory import DependencyFactory
@@ -245,7 +245,7 @@ class PythonSystemDependency(SystemDependency, _PythonDependencyBase):
self.link_args = largs
self.is_found = True
- def get_windows_python_arch(self) -> T.Optional[str]:
+ def get_windows_python_arch(self) -> str:
if self.platform.startswith('mingw'):
if 'x86_64' in self.platform:
return 'x86_64'
@@ -254,16 +254,14 @@ class PythonSystemDependency(SystemDependency, _PythonDependencyBase):
elif 'aarch64' in self.platform:
return 'aarch64'
else:
- mlog.log(f'MinGW Python built with unknown platform {self.platform!r}, please file a bug')
- return None
+ raise DependencyException(f'MinGW Python built with unknown platform {self.platform!r}, please file a bug')
elif self.platform == 'win32':
return 'x86'
elif self.platform in {'win64', 'win-amd64'}:
return 'x86_64'
elif self.platform in {'win-arm64'}:
return 'aarch64'
- mlog.log(f'Unknown Windows Python platform {self.platform!r}')
- return None
+ raise DependencyException('Unknown Windows Python platform {self.platform!r}')
def get_windows_link_args(self, limited_api: bool) -> T.Optional[T.List[str]]:
if self.platform.startswith('win'):
@@ -330,8 +328,10 @@ class PythonSystemDependency(SystemDependency, _PythonDependencyBase):
Find python3 libraries on Windows and also verify that the arch matches
what we are building for.
'''
- pyarch = self.get_windows_python_arch()
- if pyarch is None:
+ try:
+ pyarch = self.get_windows_python_arch()
+ except DependencyException as e:
+ mlog.log(str(e))
self.is_found = False
return
arch = detect_cpu_family(env.coredata.compilers.host)