]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
docs: add skip-list to avoid importing external module
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Mon, 18 Jul 2022 07:23:55 +0000 (08:23 +0100)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Mon, 18 Jul 2022 07:26:02 +0000 (08:26 +0100)
In sandboxed environments dnspython doesn't work because it cannot read
`/etc/resolv.conf`/

See #337 for details.

docs/lib/pg3_docs.py
psycopg/setup.py

index 4352afbcf070ca4d41f8c79cb7e8faa52ef757ed..e2609a3ab9000a26a447ff9dcc27ee04b0b98a39 100644 (file)
@@ -35,7 +35,9 @@ def setup(app):
 
     import psycopg  # type: ignore
 
-    recover_defined_module(psycopg)
+    recover_defined_module(
+        psycopg, skip_modules=["psycopg._dns", "psycopg.types.shapely"]
+    )
     monkeypatch_autodoc()
 
     # Disable warnings in sphinx_autodoc_typehints because it doesn't seem that
@@ -49,7 +51,7 @@ def setup(app):
 recovered_classes: Dict[type, str] = {}
 
 
-def recover_defined_module(m):
+def recover_defined_module(m, skip_modules=()):
     """
     Find the module where classes with __module__ attribute hacked were defined.
 
@@ -65,6 +67,8 @@ def recover_defined_module(m):
         assert fn.startswith(mdir)
         modname = os.path.splitext(fn[len(mdir) + 1 :])[0].replace("/", ".")
         modname = f"{m.__name__}.{modname}"
+        if modname in skip_modules:
+            continue
         with open(fn) as f:
             classnames = re.findall(r"^class\s+([^(:]+)", f.read(), re.M)
             for cls in classnames:
index 34fa87b6ece4805056f58c92a174d7f2de0ba2c8..435d51f77fd8a3a7ef4bef40562698ccb345a880 100644 (file)
@@ -59,9 +59,6 @@ extras_require = {
         "furo == 2021.11.23",
         "sphinx-autobuild >= 2021.3.14",
         "sphinx-autodoc-typehints >= 1.12",
-        # to document optional modules
-        "dnspython >= 2.1",
-        "shapely >= 1.7",
     ],
 }