diff options
author | Dylan Baker <dylan@pnwbakers.com> | 2021-08-31 11:07:46 -0700 |
---|---|---|
committer | Dylan Baker <dylan@pnwbakers.com> | 2021-08-31 16:59:37 -0700 |
commit | bd691b847c2cb6cbea3450a8749bcc1a67c295e7 (patch) | |
tree | 6a2b19d2f8489e57b209116951b54b9fc602aa4a | |
parent | 042016a5556010b94364fc90280287cf9355c13b (diff) | |
download | meson-bd691b847c2cb6cbea3450a8749bcc1a67c295e7.zip meson-bd691b847c2cb6cbea3450a8749bcc1a67c295e7.tar.gz meson-bd691b847c2cb6cbea3450a8749bcc1a67c295e7.tar.bz2 |
interpreter: use python dunders instead of lock for unpicklability
This simplifies things for us, as we don't have to have threading
imported for no other reason, and we can remove the
`an_unpicklable_object` from the Interpreter and mesonlib, since there
was only one user of this.
-rw-r--r-- | mesonbuild/interpreter/interpreter.py | 6 | ||||
-rw-r--r-- | mesonbuild/mesonlib/universal.py | 7 | ||||
-rw-r--r-- | unittests/internaltests.py | 2 |
3 files changed, 5 insertions, 10 deletions
diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py index db4f9e9..c3e9b48 100644 --- a/mesonbuild/interpreter/interpreter.py +++ b/mesonbuild/interpreter/interpreter.py @@ -21,7 +21,7 @@ from .. import optinterpreter from .. import compilers from ..wrap import wrap, WrapMode from .. import mesonlib -from ..mesonlib import HoldableObject, FileMode, MachineChoice, OptionKey, listify, extract_as_list, has_path_sep +from ..mesonlib import MesonBugException, HoldableObject, FileMode, MachineChoice, OptionKey, listify, extract_as_list, has_path_sep from ..programs import ExternalProgram, NonExistingExternalProgram from ..dependencies import Dependency from ..depfile import DepFile @@ -231,7 +231,6 @@ class Interpreter(InterpreterBase, HoldableObject): is_translated: bool = False, ) -> None: super().__init__(_build.environment.get_source_dir(), subdir, subproject) - self.an_unpicklable_object = mesonlib.an_unpicklable_object self.build = _build self.environment = self.build.environment self.coredata = self.environment.get_coredata() @@ -279,6 +278,9 @@ class Interpreter(InterpreterBase, HoldableObject): self.parse_project() self._redetect_machines() + def __getnewargs_ex__(self) -> T.Tuple[T.Tuple[object], T.Dict[str, object]]: + raise MesonBugException('This class is unpicklable') + def _redetect_machines(self): # Re-initialize machine descriptions. We can do a better job now because we # have the compilers needed to gain more knowledge, so wipe out old diff --git a/mesonbuild/mesonlib/universal.py b/mesonbuild/mesonlib/universal.py index 63e754b..06b8adf 100644 --- a/mesonbuild/mesonlib/universal.py +++ b/mesonbuild/mesonlib/universal.py @@ -44,7 +44,6 @@ _U = T.TypeVar('_U') __all__ = [ 'GIT', - 'an_unpicklable_object', 'python_command', 'project_meson_versions', 'HoldableObject', @@ -265,12 +264,6 @@ def check_direntry_issues(direntry_array: T.Union[T.List[T.Union[str, bytes]], s not pure ASCII. This may cause problems. '''), file=sys.stderr) - -# Put this in objects that should not get dumped to pickle files -# by accident. -import threading -an_unpicklable_object = threading.Lock() - class HoldableObject(metaclass=abc.ABCMeta): ''' Dummy base class for all objects that can be held by an interpreter.baseobjects.ObjectHolder ''' diff --git a/unittests/internaltests.py b/unittests/internaltests.py index 0f2af18..8cebeb8 100644 --- a/unittests/internaltests.py +++ b/unittests/internaltests.py @@ -1524,6 +1524,6 @@ class InternalTests(unittest.TestCase): build.environment = mock.Mock() build.environment.get_source_dir = mock.Mock(return_value='') with mock.patch('mesonbuild.interpreter.Interpreter._redetect_machines', mock.Mock()), \ - self.assertRaises(Exception): + self.assertRaises(mesonbuild.mesonlib.MesonBugException): i = mesonbuild.interpreter.Interpreter(build, mock=True) pickle.dumps(i) |