Make BuildEnvironment picklable directly

This commit is contained in:
Takeshi KOMIYA 2018-05-10 00:59:53 +09:00
parent 0e2cb4793e
commit 8e2225b4fc

View File

@ -122,15 +122,7 @@ class BuildEnvironment(object):
@staticmethod
def dump(env, f):
# type: (BuildEnvironment, IO) -> None
# remove unpicklable attributes
app = env.app
del env.app
domains = env.domains
del env.domains
pickle.dump(env, f, pickle.HIGHEST_PROTOCOL)
# reset attributes
env.domains = domains
env.app = app
@classmethod
def dumps(cls, env):
@ -246,6 +238,17 @@ class BuildEnvironment(object):
# attributes of "any" cross references
self.ref_context = {} # type: Dict[unicode, Any]
def __getstate__(self):
# type: () -> Dict
"""Obtains serializable data for pickling."""
__dict__ = self.__dict__.copy()
__dict__.update(app=None, domains={}) # clear unpickable attributes
return __dict__
def __setstate__(self, state):
# type: (Dict) -> None
self.__dict__.update(state)
def set_warnfunc(self, func):
# type: (Callable) -> None
warnings.warn('env.set_warnfunc() is now deprecated. Use sphinx.util.logging instead.',