From 7d3dc64a8bc136086f7c2c67294823bb664b89d7 Mon Sep 17 00:00:00 2001 From: Shengyu Zhang Date: Sun, 7 Jul 2024 21:40:19 +0800 Subject: [PATCH] intersphinx: Handle the case where intersphinx_cache_limit is negative The documentation said: Set this (intersphinx_cache_limit) to a negative value to cache inventories for unlimited time. In the current implementation, a negative intersphinx_cache_limit causes inventories always expire, this patch ensures that it behaves as documented. --- CHANGES.rst | 3 +++ sphinx/ext/intersphinx/_load.py | 8 ++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index c36233573a3..43c8a432847 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -89,6 +89,9 @@ Bugs fixed * #12494: Fix invalid genindex.html file produced with translated docs (regression in 7.1.0). Patch by Nicolas Peugnet. +* #12514: intersphinx: Handle the case where ``intersphinx_cache_limit`` is + negative, ensure that it behaves as documented + Patch by Shengyu Zhang. Testing ------- diff --git a/sphinx/ext/intersphinx/_load.py b/sphinx/ext/intersphinx/_load.py index b458d6a7e18..01caee77895 100644 --- a/sphinx/ext/intersphinx/_load.py +++ b/sphinx/ext/intersphinx/_load.py @@ -107,7 +107,10 @@ def fetch_inventory_group( app: Sphinx, now: int, ) -> bool: - cache_time = now - app.config.intersphinx_cache_limit * 86400 + if app.config.intersphinx_cache_limit != -1: + cache_time = now - app.config.intersphinx_cache_limit * 86400 + else: + cache_time = None failures = [] try: for inv in invs: @@ -115,7 +118,8 @@ def fetch_inventory_group( inv = posixpath.join(uri, INVENTORY_FILENAME) # decide whether the inventory must be read: always read local # files; remote ones only if the cache time is expired - if '://' not in inv or uri not in cache or cache[uri][1] < cache_time: + if '://' not in inv or uri not in cache or \ + (cache_time and cache[uri][1] < cache_time): safe_inv_url = _get_safe_url(inv) inv_descriptor = name or 'main_inventory' LOGGER.info(__("loading intersphinx inventory '%s' from %s..."),