mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Make BuildEnvironment picklable directly
This commit is contained in:
parent
0e2cb4793e
commit
8e2225b4fc
@ -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.',
|
||||
|
Loading…
Reference in New Issue
Block a user