From f560ce17549287dca61b206755fde3e201f4008c Mon Sep 17 00:00:00 2001 From: Erez Sh Date: Thu, 22 Oct 2020 15:31:30 +0300 Subject: [PATCH] cache=True now uses a temp directory instead of working directory --- lark/lark.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lark/lark.py b/lark/lark.py index bc34eb4..e84befc 100644 --- a/lark/lark.py +++ b/lark/lark.py @@ -3,6 +3,7 @@ from lark.exceptions import UnexpectedCharacters, UnexpectedInput, UnexpectedTok import sys, os, pickle, hashlib from io import open +import tempfile from .utils import STRING_TYPE, Serialize, SerializeMemoizer, FS, isascii, logger @@ -244,7 +245,7 @@ class Lark(Serialize): options_str = ''.join(k+str(v) for k, v in options.items() if k not in unhashable) s = grammar + options_str + __version__ md5 = hashlib.md5(s.encode()).hexdigest() - cache_fn = '.lark_cache_%s.tmp' % md5 + cache_fn = tempfile.gettempdir() + '/.lark_cache_%s.tmp' % md5 if FS.exists(cache_fn): logger.debug('Loading grammar from cache: %s', cache_fn)