diff --git a/src/sage/misc/cython.py b/src/sage/misc/cython.py index 4d93b943427..7eadbd39cc0 100644 --- a/src/sage/misc/cython.py +++ b/src/sage/misc/cython.py @@ -25,8 +25,7 @@ from sage.env import (SAGE_LOCAL, cython_aliases, sage_include_directories) -from sage.misc.misc import spyx_tmp -from .temporary_file import tmp_filename +from .temporary_file import spyx_tmp, tmp_filename from sage.repl.user_globals import get_globals from sage.misc.sage_ostools import restore_cwd, redirection from sage.cpython.string import str_to_bytes diff --git a/src/sage/misc/misc.py b/src/sage/misc/misc.py index 76307760aa0..93f2bebdb55 100644 --- a/src/sage/misc/misc.py +++ b/src/sage/misc/misc.py @@ -255,32 +255,17 @@ def SPYX_TMP(): sage: SPYX_TMP doctest:warning... DeprecationWarning: SPYX_TMP is deprecated; - use sage.misc.misc.spyx_tmp instead + use sage.misc.temporary_file.spyx_tmp instead See https://trac.sagemath.org/33213 for details. ... """ + from sage.misc.temporary_file import spyx_tmp from sage.misc.superseded import deprecation - deprecation(33213, "SPYX_TMP is deprecated; use sage.misc.misc.spyx_tmp instead") + deprecation(33213, "SPYX_TMP is deprecated; use sage.misc.temporary_file.spyx_tmp instead") return spyx_tmp() -@cached_function -def spyx_tmp(): - r""" - The temporary directory used to store pyx files. - - We use a cached function for this so that the same temporary - directory will always be returned (unless the user shoots himself - in the foot). Each temporary directory created is removed when - sage terminates using an atexit hook. - """ - import atexit, tempfile - d = tempfile.TemporaryDirectory() - result = os.path.join(d.name, 'spyx') - atexit.register(lambda: d.cleanup()) - return result - @lazy_string def SAGE_TMP_INTERFACE(): """ diff --git a/src/sage/misc/sageinspect.py b/src/sage/misc/sageinspect.py index f27fb5721f4..87df80ef514 100644 --- a/src/sage/misc/sageinspect.py +++ b/src/sage/misc/sageinspect.py @@ -294,7 +294,7 @@ def _extract_embedded_position(docstring): # Try some common path prefixes for Cython modules built by/for Sage # 1) Module in the sage src tree # 2) Module compiled by Sage's inline cython() compiler - from sage.misc.misc import spyx_tmp + from sage.misc.temporary_file import spyx_tmp try_filenames = [ os.path.join(SAGE_LIB, raw_filename), os.path.join(spyx_tmp(), '_'.join(raw_filename.split('_')[:-1]), @@ -2431,7 +2431,7 @@ class Element(object): source_lines = f.readlines() except IOError: try: - from sage.misc.misc import spyx_tmp + from sage.misc.temporary_file import spyx_tmp raw_name = filename.split('/')[-1] newname = os.path.join(spyx_tmp(), '_'.join(raw_name.split('_')[:-1]), raw_name) with open(newname) as f: diff --git a/src/sage/misc/temporary_file.py b/src/sage/misc/temporary_file.py index f2f0cd17db0..d4857a712ec 100644 --- a/src/sage/misc/temporary_file.py +++ b/src/sage/misc/temporary_file.py @@ -26,6 +26,8 @@ import io import os import tempfile +from sage.misc.cachefunc import cached_function + import atexit @@ -543,3 +545,19 @@ def __exit__(self, exc_type, exc_val, exc_tb): else: # Failure: delete temporary file shutil.rmtree(self.tempname) + + +@cached_function +def spyx_tmp(): + r""" + The temporary directory used to store pyx files. + + We use a cached function for this so that the same temporary + directory will always be returned (unless the user shoots himself + in the foot). Each temporary directory created is removed when + sage terminates using an atexit hook. + """ + d = tempfile.TemporaryDirectory() + result = os.path.join(d.name, 'spyx') + atexit.register(lambda: d.cleanup()) + return result