From: Michael Fladischer <FladischerMichael@fladi.at>
Date: Tue, 21 Dec 2021 09:01:07 +0000
Subject: Make intersphinx use local copies of objects.inv files.

---
 docs/conf.py | 28 +++++++++++++++++++++++-----
 1 file changed, 23 insertions(+), 5 deletions(-)

diff --git a/docs/conf.py b/docs/conf.py
index bad6f8c..7001b96 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -1,6 +1,9 @@
 # cssselect2 documentation build configuration file.
 
+import os
+import sys
 import cssselect2
+import tinycss2
 
 # Add any Sphinx extension module names here, as strings. They can be
 # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
@@ -80,8 +83,23 @@ texinfo_documents = [
 ]
 
 # Example configuration for intersphinx: refer to the Python standard library.
-intersphinx_mapping = {
-    'python': ('https://docs.python.org/3/', None),
-    'webencodings': ('https://pythonhosted.org/webencodings/', None),
-    'tinycss2': ('https://doc.courtbouillon.org/tinycss2/latest/', None),
-}
+def check_object_path(key, url, path):
+    if os.path.isfile(path):
+        return {key: (url, path)}
+    return {}
+
+intersphinx_mapping = {}
+intersphinx_mapping.update(
+    check_object_path(
+        'python',
+        'https://docs.python.org/',
+        '/usr/share/doc/python' + '.'.join([str(x) for x in sys.version_info[0:2]]) + '/html/objects.inv'
+    )
+)
+intersphinx_mapping.update(
+    check_object_path(
+        'tinycss2',
+        'https://doc.courtbouillon.org/tinycss2/v' + tinycss2.VERSION + '/',
+        '/usr/share/doc/python-tinycss2-doc/html/objects.inv'
+    )
+)
