diff options
author | MinRK <benjaminrk@gmail.com> | 2012-05-30 21:24:19 -0700 |
---|---|---|
committer | MinRK <benjaminrk@gmail.com> | 2012-05-30 21:32:40 -0700 |
commit | 82b1c99beb0f06bdd24acb733cac2c0f69aa69e3 (patch) | |
tree | b714323391ecb68e732245ef2d45c6e4d887231c /Cython | |
parent | 684ecc9341cc96c2a94e83575d9a9e59d00b1149 (diff) | |
download | cython-82b1c99beb0f06bdd24acb733cac2c0f69aa69e3.tar.gz |
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
Diffstat (limited to 'Cython')
-rw-r--r-- | Cython/Build/Inline.py | 3 | ||||
-rw-r--r-- | Cython/Utils.py | 29 |
2 files changed, 31 insertions, 1 deletions
diff --git a/Cython/Build/Inline.py b/Cython/Build/Inline.py index c589ff391..ef9cf5c4f 100644 --- a/Cython/Build/Inline.py +++ b/Cython/Build/Inline.py @@ -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, diff --git a/Cython/Utils.py b/Cython/Utils.py index ae92eec8f..3d8ed8eec 100644 --- a/Cython/Utils.py +++ b/Cython/Utils.py @@ -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')) |