Skip to content

Commit

Permalink
Trac #33064: sage_docbuild: fails when cache cannot be saved
Browse files Browse the repository at this point in the history
When doctesting `src/sage_docbuild/__init__.py` on a read-only location
we get a failure which ultimately boils down to:

{{{
┌────────────────────────────────────────────────────────────────────┐
│ SageMath version 9.5.beta8, Release Date: 2021-12-12               │
│ Using Python 3.10.1. Type "help()" for help.                       │
└────────────────────────────────────────────────────────────────────┘
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Warning: this is a prerelease version, and it may be unstable.     ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
sage: from sage_docbuild import DocBuilder, setup_parser,
ReferenceSubBuilder
sage: DocBuilder._options = setup_parser().parse_args([])
sage: import sage_docbuild.sphinxbuild
sage: def raiseBaseException():
....:     raise BaseException("abort pool operation")
....:
sage: original_runsphinx, sage_docbuild.sphinxbuild.runsphinx =
sage_docbuild.sphinxbuild.runsphinx, raiseBaseException
sage: ReferenceSubBuilder("docname", "en")._wrapper("html")
------------------------------------------------------------------------
---
PermissionError                           Traceback (most recent call
last)
<ipython-input-11-7faec88fcc76> in <module>
----> 1 ReferenceSubBuilder("docname", "en")._wrapper("html")

/usr/lib/sage-9.5.beta8/local/var/lib/sage/venv-
python3.10/lib/python3.10/site-packages/sage_docbuild/__init__.py in
_wrapper(self, build_type, *args, **kwds)
    797         cache['option_inherited'] = self._options.inherited
    798         cache['option_underscore'] = self._options.underscore
--> 799         self.save_cache()
    800
    801         # After "sage -clone", refresh the reST file mtimes in

/usr/lib/sage-9.5.beta8/local/var/lib/sage/venv-
python3.10/lib/python3.10/site-packages/sage_docbuild/__init__.py in
save_cache(self)
    857         """
    858         cache = self.get_cache()
--> 859         with open(self.cache_filename(), 'wb') as file:
    860             pickle.dump(cache, file)
    861         logger.debug("Saved the reference cache: %s",
self.cache_filename())

PermissionError: [Errno 13] Permission denied: '/usr/lib/sage-9.5.beta8/
local/share/doc/sage/doctrees/en/docname/reference.pickle'
}}}

This is due to a `save_cache()` method trying to save into that file; I
believe it would be harmless to ignore this permission error (if the
cache is not saved, it will have to be regenerated, so what).

URL: https://trac.sagemath.org/33064
Reported by: tornaria
Ticket author(s): Gonzalo Tornaría
Reviewer(s): John Palmieri
  • Loading branch information
Release Manager committed Feb 12, 2022
2 parents 467c32c + e89193f commit 18ba1d8
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/sage_docbuild/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -810,9 +810,12 @@ def save_cache(self):
Pickle the current reference cache for later retrieval.
"""
cache = self.get_cache()
with open(self.cache_filename(), 'wb') as file:
pickle.dump(cache, file)
logger.debug("Saved the reference cache: %s", self.cache_filename())
try:
with open(self.cache_filename(), 'wb') as file:
pickle.dump(cache, file)
logger.debug("Saved the reference cache: %s", self.cache_filename())
except PermissionError:
logger.debug("Permission denied for the reference cache: %s", self.cache_filename())

def get_sphinx_environment(self):
"""
Expand Down

0 comments on commit 18ba1d8

Please sign in to comment.