]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
docs: allow to read the libpq definitions from a local file
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Mon, 18 Jul 2022 13:39:55 +0000 (14:39 +0100)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Mon, 18 Jul 2022 23:41:34 +0000 (00:41 +0100)
For the poor souls which don't have external access building the docs.
See #337.

docs/lib/libpq_docs.py

index e8c82caa536732eca8a66c3f82d49382d19b57ee..b8e01f0d0cd6b665294b956075fe91c8671d4308 100644 (file)
@@ -13,6 +13,7 @@ will link to::
 
 # Copyright (C) 2020 The Psycopg Team
 
+import os
 import logging
 import urllib.request
 from pathlib import Path
@@ -111,8 +112,15 @@ class LibpqReader:
             parser.feed(f.read())
 
     def download(self):
-        logger.info("downloading postgres libpq docs from %s", self.sgml_url)
-        data = urllib.request.urlopen(self.sgml_url).read()
+        filename = os.environ.get("LIBPQ_DOCS_FILE")
+        if filename:
+            logger.info("reading postgres libpq docs from %s", filename)
+            with open(filename, "rb") as f:
+                data = f.read()
+        else:
+            logger.info("downloading postgres libpq docs from %s", self.sgml_url)
+            data = urllib.request.urlopen(self.sgml_url).read()
+
         with self.local_file.open("wb") as f:
             f.write(data)