Browse Source

cache=True now uses a temp directory instead of working directory

tags/gm/2021-09-23T00Z/github.com--lark-parser-lark/0.11.0
Erez Sh 3 years ago
parent
commit
f560ce1754
1 changed files with 2 additions and 1 deletions
  1. +2
    -1
      lark/lark.py

+ 2
- 1
lark/lark.py View File

@@ -3,6 +3,7 @@ from lark.exceptions import UnexpectedCharacters, UnexpectedInput, UnexpectedTok


import sys, os, pickle, hashlib import sys, os, pickle, hashlib
from io import open from io import open
import tempfile




from .utils import STRING_TYPE, Serialize, SerializeMemoizer, FS, isascii, logger 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) options_str = ''.join(k+str(v) for k, v in options.items() if k not in unhashable)
s = grammar + options_str + __version__ s = grammar + options_str + __version__
md5 = hashlib.md5(s.encode()).hexdigest() 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): if FS.exists(cache_fn):
logger.debug('Loading grammar from cache: %s', cache_fn) logger.debug('Loading grammar from cache: %s', cache_fn)


Loading…
Cancel
Save