jisaacstone / sfzlint

parser and linter for sfz files written in python using Lark
MIT License
17 stars 4 forks source link

fix: use user-writable cache dir for opcodes pickle file #6

Closed SpotlightKid closed 2 years ago

SpotlightKid commented 2 years ago

Also fixes a typo in the name of the pickle file ("opcides" -> "opcodes").

Without this fix, if you install sfzlint into the system-wide site-packages directory, you'll get an permission error when sfzlint tries to write the cache pickle file:

PermissionError: [Errno 13] Permission denied: '/usr/lib/python3.10/site-packages/sfzlint/opcides.pickle'

This fix adds the appdirs package as a dependency and uses it to determine the appropriate user-writable cache dir and write the cache pickle file there.

Full traceback:

Traceback (most recent call last):
  File "/usr/bin/sfzlint", line 33, in <module>
    sys.exit(load_entry_point('sfzlint==0.1.2', 'console_scripts', 'sfzlint')())
  File "/usr/bin/sfzlint", line 25, in importlib_load_entry_point
    return next(matches).load()
  File "/usr/lib/python3.10/importlib/metadata/__init__.py", line 162, in load
    module = import_module(match.group('module'))
  File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/usr/lib/python3.10/site-packages/sfzlint/cli.py", line 5, in <module>
    from . import spec, parser, lint, opcodes
  File "/usr/lib/python3.10/site-packages/sfzlint/spec.py", line 213, in <module>
    opcodes = _pickled('opcides', lambda: _override(_extract()))
  File "/usr/lib/python3.10/site-packages/sfzlint/spec.py", line 204, in _pickled
    with p_file.open('wb') as fob:
  File "/usr/lib/python3.10/pathlib.py", line 1117, in open
    return self._accessor.open(self, mode, buffering, encoding, errors,
PermissionError: [Errno 13] Permission denied: '/usr/lib/python3.10/site-packages/sfzlint/opcides.pickle'
redtide commented 2 years ago

small parenthesis: thank you for the AUR package, I hadn't thought about creating one :P

SpotlightKid commented 2 years ago

Ping?

jisaacstone commented 2 years ago

Hobby time is very limited these days. Thanks for the fix and for your patience!