Commit 82b1c99b authored by MinRK's avatar MinRK

add CYTHON_CACHE_DIR env

resolution for the Cython cache dir:

1. CYTHON_CACHE_DIR env if defined
2. platform cache dir
   - (OS X): ~/Library/Caches/Cython if ~/Library/Caches exists
   - (posix not OS X): XDG_CACHE_HOME/cython if XDG_CACHE_HOME defined
3. ~/.cython/inline
parent 684ecc93
......@@ -16,6 +16,7 @@ from Cython.Compiler.ParseTreeTransforms import CythonTransform, SkipDeclaration
from Cython.Compiler.TreeFragment import parse_from_strings
from Cython.Build.Dependencies import strip_string_literals, cythonize, cached_function
from Cython.Compiler import Pipeline
from Cython.Utils import get_cython_cache_dir
import cython as cython_module
# A utility function to convert user-supplied ASCII strings to unicode.
......@@ -95,7 +96,7 @@ def safe_type(arg, context=None):
def cython_inline(code,
get_type=unsafe_type,
lib_dir=os.path.expanduser('~/.cython/inline'),
lib_dir=get_cython_cache_dir(),
cython_include_dirs=['.'],
force=False,
quiet=False,
......
......@@ -364,3 +364,32 @@ except NameError:
if item:
return True
return False
@cached_function
def get_cython_cache_dir():
"""get the cython cache dir
Priority:
1. CYTHON_CACHE_DIR
2. (OS X): ~/Library/Caches/Cython
(posix not OS X): XDG_CACHE_HOME/cython if XDG_CACHE_HOME defined
3. ~/.cython/inline
"""
if 'CYTHON_CACHE_DIR' in os.environ:
return os.environ['CYTHON_CACHE_DIR']
parent = None
if os.name == 'posix':
if sys.platform == 'darwin':
parent = os.path.expanduser('~/Library/Caches')
else:
# this could fallback on ~/.cache
parent = os.environ.get('XDG_CACHE_HOME')
if parent and os.path.isdir(parent):
return os.path.join(parent, 'cython')
# last fallback: ~/.cython/inline
return os.path.expanduser(os.path.join('~', '.cython', 'inline'))
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment