Skip to content

Commit

Permalink
Fix psf#192: cache grammer pickles via appdirs
Browse files Browse the repository at this point in the history
Uses `appdirs.user_cache_dir("black") / "blib2to3"`
  • Loading branch information
amyreese committed May 17, 2018
1 parent e94bda1 commit ab61ec2
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion blib2to3/pgen2/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
import pkgutil
import sys

from appdirs import user_cache_dir
from pathlib import Path

# Pgen imports
from . import grammar, parse, token, tokenize, pgen

Expand Down Expand Up @@ -150,10 +153,15 @@ def _partially_consume_prefix(self, prefix, column):


def _generate_pickle_name(gt):
cache_dir = Path(user_cache_dir("black")) / "blib2to3"
if not cache_dir.exists():
cache_dir.mkdir(parents=True)
head, tail = os.path.splitext(gt)
head = os.path.basename(head)
if tail == ".txt":
tail = ""
return head + tail + ".".join(map(str, sys.version_info)) + ".pickle"
filename = head + tail + ".".join(map(str, sys.version_info)) + ".pickle"
return cache_dir / filename


def load_grammar(gt="Grammar.txt", gp=None,
Expand Down

0 comments on commit ab61ec2

Please sign in to comment.