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

Commit

Permalink
src/sage/misc/temporary_file.py: Remove use of functools.cache
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Koeppe committed Dec 7, 2021
1 parent 81d0fff commit 7e78f59
Showing 1 changed file with 28 additions and 18 deletions.
46 changes: 28 additions & 18 deletions src/sage/misc/temporary_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@
import os
import tempfile
import atexit
import functools

# We do not use sage.misc.cachefunc here so that this module does not depend on
# Cython modules.

@functools.cache
_sage_tmp = None


def sage_tmp():
"""
EXAMPLES::
Expand All @@ -41,17 +42,21 @@ def sage_tmp():
sage: sage_tmp()
'.../temp/...'
"""
# This duplicates code that is run when sage.misc.misc is loaded;
# but modularized distributions may not have sage.misc.misc.
from sage.env import DOT_SAGE, HOSTNAME
os.makedirs(DOT_SAGE, mode=0o700, exist_ok=True)
global _sage_tmp
if _sage_tmp is None:
# This duplicates code that is run when sage.misc.misc is loaded;
# but modularized distributions may not have sage.misc.misc.
from sage.env import DOT_SAGE, HOSTNAME
os.makedirs(DOT_SAGE, mode=0o700, exist_ok=True)

_sage_tmp = os.path.join(DOT_SAGE, 'temp', HOSTNAME, str(os.getpid()))
os.makedirs(_sage_tmp, exist_ok=True)
return _sage_tmp

d = os.path.join(DOT_SAGE, 'temp', HOSTNAME, str(os.getpid()))
os.makedirs(d, exist_ok=True)
return d

_ecl_tmp = None


@functools.cache
def ecl_tmp():
"""
Temporary directory that should be used by ECL interfaces launched from
Expand All @@ -63,12 +68,13 @@ def ecl_tmp():
sage: ecl_tmp()
'.../temp/.../ecl'
"""
d = os.path.join(sage_tmp(), 'ecl')
os.makedirs(d, exist_ok=True)
return d
global _ecl_tmp
if _ecl_tmp is None:
_ecl_tmp = os.path.join(sage_tmp(), 'ecl')
os.makedirs(_ecl_tmp, exist_ok=True)
return _ecl_tmp


@functools.cache
def spyx_tmp():
"""
EXAMPLES::
Expand All @@ -80,7 +86,9 @@ def spyx_tmp():
return os.path.join(sage_tmp(), 'spyx')


@functools.cache
_sage_tmp_interface = None


def sage_tmp_interface():
"""
EXAMPLES::
Expand All @@ -89,9 +97,11 @@ def sage_tmp_interface():
sage: sage_tmp_interface()
'.../temp/.../interface'
"""
d = os.path.join(sage_tmp(), 'interface')
os.makedirs(d, exist_ok=True)
return d
global _sage_tmp_interface
if _sage_tmp_interface is None:
_sage_tmp_interface = os.path.join(sage_tmp(), 'interface')
os.makedirs(_sage_tmp_interface, exist_ok=True)
return _sage_tmp_interface


def delete_tmpfiles():
Expand Down

0 comments on commit 7e78f59

Please sign in to comment.