From: Michael Fladischer <FladischerMichael@fladi.at>
Date: Sat, 1 Jul 2023 14:41:14 +0000
Subject: Use local objects.inv in intersphinx mapping.

---
 docs/source/conf.py | 25 +++++++++++++++++++++----
 1 file changed, 21 insertions(+), 4 deletions(-)

diff --git a/docs/source/conf.py b/docs/source/conf.py
index 7a71ac8..b23d01d 100644
--- a/docs/source/conf.py
+++ b/docs/source/conf.py
@@ -19,6 +19,7 @@
 #
 import os
 import sys
+import trio
 
 # So autodoc can import our package
 sys.path.insert(0, os.path.abspath("../.."))
@@ -71,10 +72,26 @@ extensions = [
     "sphinxcontrib_trio",
 ]
 
-intersphinx_mapping = {
-    "python": ("https://docs.python.org/3", None),
-    "trio": ("https://trio.readthedocs.io/en/stable", 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[:2])) + '/html/objects.inv'
+    )
+)
+intersphinx_mapping.update(
+    check_object_path(
+        'trio',
+        'https://trio.readthedocs.io/en/v{v}'.format(v=trio.__version__),
+        '/usr/share/doc/python-trio-doc/html/objects.inv'
+    )
+)
 
 autodoc_member_order = "bysource"
 
