From: Michael Fladischer <FladischerMichael@fladi.at>
Date: Mon, 3 Jul 2023 07:18:42 +0000
Subject: Use local objects.inv in intersphinx mapping.

Forwarded: not-needed
---
 docs/conf.py | 63 +++++++++++++++++++++++++++++++++++++++++++++++++-----------
 1 file changed, 52 insertions(+), 11 deletions(-)

diff --git a/docs/conf.py b/docs/conf.py
index e9ed3f8..40e46ae 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -12,6 +12,11 @@ import sys
 import inspect
 import shutil
 
+import pandas
+import scipy
+
+from packaging.version import parse as version_parse
+
 # -- Path setup --------------------------------------------------------------
 
 __location__ = os.path.join(
@@ -290,14 +295,50 @@ latex_documents = [
 # latex_domain_indices = True
 
 # -- External mapping --------------------------------------------------------
-python_version = ".".join(map(str, sys.version_info[0:2]))
-intersphinx_mapping = {
-    "sphinx": ("http://www.sphinx-doc.org/en/stable", None),
-    "python": ("https://docs.python.org/" + python_version, None),
-    "matplotlib": ("https://matplotlib.org", None),
-    "numpy": ("https://docs.scipy.org/doc/numpy", None),
-    "sklearn": ("https://scikit-learn.org/stable", None),
-    "pandas": ("https://pandas.pydata.org/pandas-docs/stable", None),
-    "scipy": ("https://docs.scipy.org/doc/scipy/reference", None),
-    "pyscaffold": ("https://pyscaffold.org/en/stable", None),
-}
\ No newline at end of file
+#python_version = ".".join(map(str, sys.version_info[0:2]))
+#intersphinx_mapping = {
+#    "matplotlib": ("https://matplotlib.org", None),
+#    "numpy": ("https://docs.scipy.org/doc/numpy", None),
+#    "pyscaffold": ("https://pyscaffold.org/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(
+        'sphinx',
+        'https://www.sphinx-doc.org/en/master/',
+        '/usr/share/doc/sphinx-doc/html/objects.inv'
+    )
+)
+intersphinx_mapping.update(
+    check_object_path(
+        'sklearn',
+        'https://scikit-learn.org/stable',
+        '/usr/share/doc/python-sklearn-doc/html/objects.inv'
+    )
+)
+intersphinx_mapping.update(
+    check_object_path(
+        'pandas',
+        'https://pandas.pydata.org/pandas-docs/version/{v.major}.{v.minor}'.format(v=version_parse(pandas.__version__)),
+        '/usr/share/doc/python-pandas-doc/html/objects.inv'
+    )
+)
+intersphinx_mapping.update(
+    check_object_path(
+        'scipy',
+        'https://docs.scipy.org/doc/scipy-{v}'.format(v=scipy.__version__),
+        '/usr/share/doc/python-scipy-doc/html/objects.inv'
+    )
+)
