diff --git a/.travis.yml b/.travis.yml index 3958285..0e42e11 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,11 @@ language: python python: 2.7 +sudo: false + +cache: + directories: + - $HOME/.cache/pip + env: - TOX_ENV=py26 - TOX_ENV=py27 @@ -18,4 +24,3 @@ script: - ./.travis/run.sh notifications: email: false - diff --git a/.travis/run.sh b/.travis/run.sh index 491f870..8aad5de 100755 --- a/.travis/run.sh +++ b/.travis/run.sh @@ -3,17 +3,20 @@ set -e set -x +export PYPY_LOCATION case "${TOX_ENV}" in + py26) + PYPY_LOCATION="" + ;; py33) - export PYPY_LOCATION="" + PYPY_LOCATION="" ;; py34) - export PYPY_LOCATION="" + PYPY_LOCATION="" ;; *) - export PYPY_LOCATION=`python -c "import glob; import os; print os.path.abspath(glob.glob('../pypy-pypy*')[0])"` + PYPY_LOCATION=`python -c "import glob; import os; print os.path.abspath(glob.glob('../pypy-pypy*')[0])"` ;; esac tox -e $TOX_ENV - diff --git a/README.rst b/README.rst index 35445b7..01a9833 100644 --- a/README.rst +++ b/README.rst @@ -2,7 +2,7 @@ RPLY ==== .. image:: https://secure.travis-ci.org/alex/rply.png - :target: http://travis-ci.org/alex/rply + :target: https://travis-ci.org/alex/rply Welcome to RPLY! A pure python parser generator, that also works with RPython. It is a more-or-less direct port of David Beazley's awesome PLY, with a new diff --git a/docs/conf.py b/docs/conf.py index 3b0a145..102e966 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -99,7 +99,7 @@ # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. -html_theme = 'default' +html_theme = 'alabaster' # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the @@ -259,4 +259,4 @@ # Example configuration for intersphinx: refer to the Python standard library. -intersphinx_mapping = {'http://docs.python.org/': None} +intersphinx_mapping = {'https://docs.python.org/': None} diff --git a/docs/users-guide/parsers.rst b/docs/users-guide/parsers.rst index ab5936e..79537ac 100644 --- a/docs/users-guide/parsers.rst +++ b/docs/users-guide/parsers.rst @@ -12,7 +12,7 @@ expressions as defined by the following BNF_ grammar:: | "(" ")" -.. _BNF: http://en.wikipedia.org/wiki/Backus-Naur_Form +.. _BNF: https://en.wikipedia.org/wiki/Backus-Naur_Form Furthermore we use the following lexer: diff --git a/rply/parsergenerator.py b/rply/parsergenerator.py index f2ed8ee..44daae7 100644 --- a/rply/parsergenerator.py +++ b/rply/parsergenerator.py @@ -2,12 +2,12 @@ import json import os import random -import stat import string import sys -import tempfile import warnings +from appdirs import AppDirs + from rply.errors import ParserGeneratorError, ParserGeneratorWarning from rply.grammar import Grammar from rply.parser import LRParser @@ -175,44 +175,28 @@ def build(self): g.compute_first() g.compute_follow() - # win32 temp directories are already per-user - if os.name == "nt": - cache_file = os.path.join( - tempfile.gettempdir(), - "rply-%s-%s-%s.json" % ( - self.VERSION, self.cache_id, self.compute_grammar_hash(g) - ) - ) - else: - cache_file = os.path.join( - tempfile.gettempdir(), - "rply-%s-%s-%s-%s.json" % ( - self.VERSION, - os.getuid(), - self.cache_id, - self.compute_grammar_hash(g) - ) + cache_dir = AppDirs("rply").user_cache_dir + cache_file = os.path.join( + cache_dir, + "%s-%s-%s.json" % ( + self.cache_id, self.VERSION, self.compute_grammar_hash(g) ) + ) + table = None if os.path.exists(cache_file): with open(cache_file) as f: data = json.load(f) - stat_result = os.fstat(f.fileno()) - if ( - os.name == "nt" or ( - stat_result.st_uid == os.getuid() and - stat.S_IMODE(stat_result.st_mode) == 0o0600 - ) - ): - if self.data_is_valid(g, data): - table = LRTable.from_cache(g, data) + if self.data_is_valid(g, data): + table = LRTable.from_cache(g, data) if table is None: table = LRTable.from_grammar(g) - fd = os.open( - cache_file, os.O_RDWR | os.O_CREAT | os.O_EXCL, 0o0600 - ) - with os.fdopen(fd, "w") as f: + if not os.path.exists(cache_dir): + os.makedirs(cache_dir, mode=0o0700) + + with open(cache_file, "w") as f: json.dump(self.serialize_table(table), f) + if table.sr_conflicts: warnings.warn( "%d shift/reduce conflict%s" % ( diff --git a/setup.py b/setup.py index df6af7e..1072f5e 100644 --- a/setup.py +++ b/setup.py @@ -13,4 +13,5 @@ author="Alex Gaynor", author_email="alex.gaynor@gmail.com", packages=["rply"], + install_requires=["appdirs"], )