Disable fixup_module_metadata when running Sphinx
This commit is contained in:
@@ -11,8 +11,12 @@ import sys
|
|||||||
|
|
||||||
sys.path.insert(0, os.path.abspath(".."))
|
sys.path.insert(0, os.path.abspath(".."))
|
||||||
|
|
||||||
|
os.environ["_FBCHAT_DISABLE_FIX_MODULE_METADATA"] = "1"
|
||||||
|
|
||||||
import fbchat
|
import fbchat
|
||||||
|
|
||||||
|
del os.environ["_FBCHAT_DISABLE_FIX_MODULE_METADATA"]
|
||||||
|
|
||||||
# -- Project information -----------------------------------------------------
|
# -- Project information -----------------------------------------------------
|
||||||
|
|
||||||
project = fbchat.__name__
|
project = fbchat.__name__
|
||||||
|
@@ -92,35 +92,8 @@ __version__ = "1.9.6"
|
|||||||
|
|
||||||
__all__ = ("Session", "Listener", "Client")
|
__all__ = ("Session", "Listener", "Client")
|
||||||
|
|
||||||
# Everything below is taken from the excellent trio project:
|
|
||||||
|
|
||||||
|
from . import _fix_module_metadata
|
||||||
|
|
||||||
def fixup_module_metadata(namespace):
|
_fix_module_metadata.fixup_module_metadata(globals())
|
||||||
def fix_one(qualname, name, obj):
|
del _fix_module_metadata
|
||||||
mod = getattr(obj, "__module__", None)
|
|
||||||
if mod is not None and mod.startswith("fbchat."):
|
|
||||||
obj.__module__ = "fbchat"
|
|
||||||
# Modules, unlike everything else in Python, put fully-qualitied
|
|
||||||
# names into their __name__ attribute. We check for "." to avoid
|
|
||||||
# rewriting these.
|
|
||||||
if hasattr(obj, "__name__") and "." not in obj.__name__:
|
|
||||||
obj.__name__ = name
|
|
||||||
obj.__qualname__ = qualname
|
|
||||||
if isinstance(obj, type):
|
|
||||||
# Fix methods
|
|
||||||
for attr_name, attr_value in obj.__dict__.items():
|
|
||||||
fix_one(objname + "." + attr_name, attr_name, attr_value)
|
|
||||||
|
|
||||||
for objname, obj in namespace.items():
|
|
||||||
if not objname.startswith("_"): # ignore private attributes
|
|
||||||
fix_one(objname, objname, obj)
|
|
||||||
|
|
||||||
|
|
||||||
# Having the public path in .__module__ attributes is important for:
|
|
||||||
# - exception names in printed tracebacks
|
|
||||||
# - sphinx :show-inheritance:
|
|
||||||
# - deprecation warnings
|
|
||||||
# - pickle
|
|
||||||
# - probably other stuff
|
|
||||||
fixup_module_metadata(globals())
|
|
||||||
del fixup_module_metadata
|
|
||||||
|
39
fbchat/_fix_module_metadata.py
Normal file
39
fbchat/_fix_module_metadata.py
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
"""Everything in this module is taken from the excellent trio project.
|
||||||
|
|
||||||
|
Having the public path in .__module__ attributes is important for:
|
||||||
|
- exception names in printed tracebacks
|
||||||
|
- ~sphinx :show-inheritance:~
|
||||||
|
- deprecation warnings
|
||||||
|
- pickle
|
||||||
|
- probably other stuff
|
||||||
|
"""
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
|
def fixup_module_metadata(namespace):
|
||||||
|
def fix_one(qualname, name, obj):
|
||||||
|
mod = getattr(obj, "__module__", None)
|
||||||
|
if mod is not None and mod.startswith("fbchat."):
|
||||||
|
obj.__module__ = "fbchat"
|
||||||
|
# Modules, unlike everything else in Python, put fully-qualitied
|
||||||
|
# names into their __name__ attribute. We check for "." to avoid
|
||||||
|
# rewriting these.
|
||||||
|
if hasattr(obj, "__name__") and "." not in obj.__name__:
|
||||||
|
obj.__name__ = name
|
||||||
|
obj.__qualname__ = qualname
|
||||||
|
if isinstance(obj, type):
|
||||||
|
# Fix methods
|
||||||
|
for attr_name, attr_value in obj.__dict__.items():
|
||||||
|
fix_one(objname + "." + attr_name, attr_name, attr_value)
|
||||||
|
|
||||||
|
for objname, obj in namespace.items():
|
||||||
|
if not objname.startswith("_"): # ignore private attributes
|
||||||
|
fix_one(objname, objname, obj)
|
||||||
|
|
||||||
|
|
||||||
|
# Allow disabling this when running Sphinx
|
||||||
|
# This is done so that Sphinx autodoc can detect the file's source
|
||||||
|
# TODO: Find a better way to detect when we're running Sphinx!
|
||||||
|
if os.environ.get("_FBCHAT_DISABLE_FIX_MODULE_METADATA") == "1":
|
||||||
|
fixup_module_metadata = lambda namespace: None
|
Reference in New Issue
Block a user