Skip to content

Commit

Permalink
intersphinx: Handle the case where intersphinx_cache_limit is negative
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
SilverRainZ committed Jul 7, 2024
1 parent 5ea16e7 commit 7d3dc64
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------
Expand Down
8 changes: 6 additions & 2 deletions sphinx/ext/intersphinx/_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,19 @@ 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:
if not inv:
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..."),
Expand Down

0 comments on commit 7d3dc64

Please sign in to comment.