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.
pull/9174/head
Dylan Baker 3 years ago
parent 042016a555
commit bd691b847c
  1. 6
      mesonbuild/interpreter/interpreter.py
  2. 7
      mesonbuild/mesonlib/universal.py
  3. 2
      unittests/internaltests.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

@ -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 '''

@ -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)

Loading…
Cancel
Save