Skip to content

Commit

Permalink
Merge pull request #6 from SpotlightKid/fix/pickle-cache-dir
Browse files Browse the repository at this point in the history
fix: use user-writable cache dir for opcodes pickle file
  • Loading branch information
jisaacstone committed Mar 22, 2022
2 parents faaf295 + 8b6922c commit dc43f80
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
]
},
install_requires=[
'appdirs',
'lark-parser>=0.7.8',
'pyyaml>=6.0.0'
],
Expand Down
7 changes: 5 additions & 2 deletions sfzlint/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from functools import lru_cache
from pathlib import Path
from numbers import Real # int or float
import appdirs
import yaml
from . import validators

Expand Down Expand Up @@ -198,9 +199,11 @@ def _validator(data_value):


def _pickled(name, fn):
p_file = Path(__file__).parent / f'{name}.pickle'
user_cache_dir = Path(appdirs.user_cache_dir("sfzlint", "jisaacstone"))
p_file = user_cache_dir / f'{name}.pickle'
if not p_file.exists():
data = fn()
user_cache_dir.mkdir(parents=True, exist_ok=True)
with p_file.open('wb') as fob:
pickle.dump(data, fob)
else:
Expand All @@ -210,5 +213,5 @@ def _pickled(name, fn):


# pickling as cache cuts script time by ~400ms on my system
opcodes = _pickled('opcides', lambda: _override(_extract()))
opcodes = _pickled('opcodes', lambda: _override(_extract()))
cc_opcodes = {k for k in opcodes if 'cc' in k and 'curvecc' not in k}

0 comments on commit dc43f80

Please sign in to comment.