From: Daniele Varrazzo Date: Mon, 18 Jul 2022 13:39:55 +0000 (+0100) Subject: docs: allow to read the libpq definitions from a local file X-Git-Tag: 3.1~45^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2b5764860b848b2d82d4016c1b195462918dfe13;p=thirdparty%2Fpsycopg.git docs: allow to read the libpq definitions from a local file For the poor souls which don't have external access building the docs. See #337. --- diff --git a/docs/lib/libpq_docs.py b/docs/lib/libpq_docs.py index e8c82caa5..b8e01f0d0 100644 --- a/docs/lib/libpq_docs.py +++ b/docs/lib/libpq_docs.py @@ -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)