Commit cae2bcf2 authored by Robert Bradshaw's avatar Robert Bradshaw

Merge pull request #128 from minrk/cythonenv

add CYTHON_CACHE_DIR env
parents 684ecc93 fac2617b
...@@ -16,6 +16,7 @@ from Cython.Compiler.ParseTreeTransforms import CythonTransform, SkipDeclaration ...@@ -16,6 +16,7 @@ from Cython.Compiler.ParseTreeTransforms import CythonTransform, SkipDeclaration
from Cython.Compiler.TreeFragment import parse_from_strings from Cython.Compiler.TreeFragment import parse_from_strings
from Cython.Build.Dependencies import strip_string_literals, cythonize, cached_function from Cython.Build.Dependencies import strip_string_literals, cythonize, cached_function
from Cython.Compiler import Pipeline from Cython.Compiler import Pipeline
from Cython.Utils import get_cython_cache_dir
import cython as cython_module import cython as cython_module
# A utility function to convert user-supplied ASCII strings to unicode. # A utility function to convert user-supplied ASCII strings to unicode.
...@@ -95,7 +96,7 @@ def safe_type(arg, context=None): ...@@ -95,7 +96,7 @@ def safe_type(arg, context=None):
def cython_inline(code, def cython_inline(code,
get_type=unsafe_type, get_type=unsafe_type,
lib_dir=os.path.expanduser('~/.cython/inline'), lib_dir=os.path.join(get_cython_cache_dir(), 'inline'),
cython_include_dirs=['.'], cython_include_dirs=['.'],
force=False, force=False,
quiet=False, quiet=False,
......
...@@ -364,3 +364,32 @@ except NameError: ...@@ -364,3 +364,32 @@ except NameError:
if item: if item:
return True return True
return False 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
"""
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'))
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