aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/modules/python.py
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2021-07-12 15:27:29 -0700
committerDylan Baker <dylan@pnwbakers.com>2021-07-13 16:43:14 -0700
commita881e849b5789c7d47d36c09fcd4cc7bdd2ee3c9 (patch)
tree3930fe7cce117e153a4be65a88c428b71b562e1a /mesonbuild/modules/python.py
parent9eec2a131bee59e1cd7a54f395aadc4eb26ad01d (diff)
downloadmeson-a881e849b5789c7d47d36c09fcd4cc7bdd2ee3c9.zip
meson-a881e849b5789c7d47d36c09fcd4cc7bdd2ee3c9.tar.gz
meson-a881e849b5789c7d47d36c09fcd4cc7bdd2ee3c9.tar.bz2
modules/python: simplify a number of interfaces
Including not calling back into `Interpreter.func_*`, which is not a good idea both from a type saftey and perforamance point of view. Instead there's now a shared _impl method
Diffstat (limited to 'mesonbuild/modules/python.py')
-rw-r--r--mesonbuild/modules/python.py60
1 files changed, 27 insertions, 33 deletions
diff --git a/mesonbuild/modules/python.py b/mesonbuild/modules/python.py
index 077505e..a8e55bd 100644
--- a/mesonbuild/modules/python.py
+++ b/mesonbuild/modules/python.py
@@ -12,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-from os import name
from pathlib import Path
import os
import json
@@ -28,7 +27,7 @@ from ..environment import detect_cpu_family
from ..interpreter import ExternalProgramHolder, extract_required_kwarg, permitted_dependency_kwargs
from ..interpreterbase import (
noPosargs, noKwargs, permittedKwargs,
- InvalidArguments, typed_pos_args,
+ InvalidArguments, typed_pos_args, typed_kwargs, KwargInfo,
FeatureNew, FeatureNewKwargs, disablerIfNotFound
)
from ..mesonlib import MachineChoice, MesonException
@@ -331,6 +330,17 @@ class PythonExternalProgram(ExternalProgram):
}
+_PURE_KW = KwargInfo('pure', bool, default=True)
+_SUBDIR_KW = KwargInfo('subdir', str, default='')
+
+if T.TYPE_CHECKING:
+
+ class PyInstallKw(TypedDict):
+
+ pure: bool
+ subdir: str
+
+
class PythonInstallation(ExternalProgramHolder):
def __init__(self, python: 'PythonExternalProgram', interpreter: 'Interpreter'):
ExternalProgramHolder.__init__(self, python, interpreter)
@@ -409,40 +419,24 @@ class PythonInstallation(ExternalProgramHolder):
raise mesonlib.MesonException('Python dependency not found')
return dep
- @permittedKwargs(['pure', 'subdir'])
- def install_sources_method(self, args: T.List['TYPE_var'], kwargs: 'TYPE_kwargs') -> 'Data':
- pure = kwargs.pop('pure', True)
- if not isinstance(pure, bool):
- raise InvalidArguments('"pure" argument must be a boolean.')
-
- subdir = kwargs.pop('subdir', '')
- if not isinstance(subdir, str):
- raise InvalidArguments('"subdir" argument must be a string.')
-
- if pure:
- kwargs['install_dir'] = os.path.join(self.purelib_install_path, subdir)
- else:
- kwargs['install_dir'] = os.path.join(self.platlib_install_path, subdir)
-
- return self.interpreter.func_install_data(None, args, kwargs)
+ @typed_pos_args('install_data', varargs=(str, mesonlib.File))
+ @typed_kwargs('python_installation.install_sources', _PURE_KW, _SUBDIR_KW)
+ def install_sources_method(self, args: T.Tuple[T.List[T.Union[str, mesonlib.File]]],
+ kwargs: 'PyInstallKw') -> 'Data':
+ return self.interpreter.install_data_impl(
+ self.interpreter.source_strings_to_files(args[0]),
+ self._get_install_dir_impl(kwargs['pure'], kwargs['subdir']),
+ mesonlib.FileMode(),
+ None)
@noPosargs
- @permittedKwargs(['pure', 'subdir'])
- def get_install_dir_method(self, args: T.List['TYPE_var'], kwargs: 'TYPE_kwargs') -> str:
- pure = kwargs.pop('pure', True)
- if not isinstance(pure, bool):
- raise InvalidArguments('"pure" argument must be a boolean.')
-
- subdir = kwargs.pop('subdir', '')
- if not isinstance(subdir, str):
- raise InvalidArguments('"subdir" argument must be a string.')
-
- if pure:
- res = os.path.join(self.purelib_install_path, subdir)
- else:
- res = os.path.join(self.platlib_install_path, subdir)
+ @typed_kwargs('python_installation.install_dir', _PURE_KW, _SUBDIR_KW)
+ def get_install_dir_method(self, args: T.List['TYPE_var'], kwargs: 'PyInstallKw') -> str:
+ return self._get_install_dir_impl(kwargs['pure'], kwargs['subdir'])
- return res
+ def _get_install_dir_impl(self, pure: bool, subdir: str) -> str:
+ return os.path.join(
+ self.purelib_install_path if pure else self.platlib_install_path, subdir)
@noPosargs
@noKwargs