From 73c635b910965bec0eb38ea8d4f497d4d1792119 Mon Sep 17 00:00:00 2001 From: Martin Bauer <martin.bauer@fau.de> Date: Wed, 25 Oct 2017 14:49:20 +0200 Subject: [PATCH] Better default paths for config and cache using appdirs module --- cache.py | 3 ++- cpu/cpujit.py | 25 +++++++++---------------- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/cache.py b/cache.py index 4ba9122c4..4732fa39d 100644 --- a/cache.py +++ b/cache.py @@ -8,7 +8,8 @@ except ImportError: try: from joblib import Memory - diskcache = Memory(cachedir="/tmp/pystencils/joblib_memcache", verbose=False).cache + from appdirs import user_cache_dir + diskcache = Memory(cachedir=user_cache_dir('pystencils'), verbose=False).cache except ImportError: # fallback to in-memory caching if joblib is not available diskcache = memorycache(maxsize=64) diff --git a/cpu/cpujit.py b/cpu/cpujit.py index 3e1db4520..37229a976 100644 --- a/cpu/cpujit.py +++ b/cpu/cpujit.py @@ -69,6 +69,7 @@ import platform import glob import atexit import shutil +from appdirs import user_config_dir, user_cache_dir from ctypes import cdll from pystencils.backends.cbackend import generateC, getHeaders from collections import OrderedDict, Mapping @@ -142,10 +143,7 @@ def _recursiveDictUpdate(d, u): def getConfigurationFilePath(): - if platform.system().lower() == 'linux': - configPathInHome = os.path.expanduser(os.path.join("~", '.config', 'pystencils', 'config.json')) - else: - configPathInHome = os.path.expanduser(os.path.join("~", '.pystencils', 'config.json')) + configPathInHome = os.path.join(user_config_dir('pystencils'), 'config.json') # 1) Read path from environment variable if found if 'PYSTENCILS_CONFIG' in os.environ: @@ -177,12 +175,7 @@ def readConfig(): ('flags', '-Ofast -DNDEBUG -fPIC -march=native -fopenmp -std=c++11'), ('restrictQualifier', '__restrict__') ]) - defaultCacheConfig = OrderedDict([ - ('readFromSharedLibrary', False), - ('objectCache', '/tmp/pystencils/objectcache'), - ('clearCacheOnStart', False), - ('sharedLibrary', '/tmp/pystencils/cache.so'), - ]) + elif platform.system().lower() == 'windows': defaultCompilerConfig = OrderedDict([ ('os', 'windows'), @@ -191,12 +184,12 @@ def readConfig(): ('flags', '/Ox /fp:fast /openmp /arch:avx'), ('restrictQualifier', '__restrict') ]) - defaultCacheConfig = OrderedDict([ - ('readFromSharedLibrary', False), - ('objectCache', os.path.join('~', '.pystencils', 'objectcache')), - ('clearCacheOnStart', False), - ('sharedLibrary', os.path.join('~', '.pystencils', 'cache.dll')), - ]) + defaultCacheConfig = OrderedDict([ + ('readFromSharedLibrary', False), + ('objectCache', os.path.join(user_cache_dir('pystencils'), 'objectcache')), + ('clearCacheOnStart', False), + ('sharedLibrary', os.path.join(user_cache_dir('pystencils'), 'cache.so')), + ]) defaultConfig = OrderedDict([('compiler', defaultCompilerConfig), ('cache', defaultCacheConfig)]) -- GitLab