Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Trac #33793: move spyx_tmp() to sage.misc.temporary_file.
Browse files Browse the repository at this point in the history
  • Loading branch information
orlitzky committed May 4, 2022
1 parent 202485f commit 827c527
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 22 deletions.
3 changes: 1 addition & 2 deletions src/sage/misc/cython.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 3 additions & 18 deletions src/sage/misc/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
"""
Expand Down
4 changes: 2 additions & 2 deletions src/sage/misc/sageinspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]),
Expand Down Expand Up @@ -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:
Expand Down
18 changes: 18 additions & 0 deletions src/sage/misc/temporary_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import io
import os
import tempfile
from sage.misc.cachefunc import cached_function

import atexit


Expand Down Expand Up @@ -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

0 comments on commit 827c527

Please sign in to comment.