diff --git a/.gitignore b/.gitignore index 46aec8a..8205caa 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,6 @@ pycscope.files pycscope.out dist pycscope.egg-info +.ropeproject/ +*.pyc +.ropeproject/ diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..5fb6213 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,16 @@ +language: python +python: + - "2.6" + - "2.7" + - "pypy" + - "pypy3" + - "3.2" + - "3.3" + - "3.4" + - "3.5" + - "3.5-dev" # 3.5 development branch + - "nightly" # currently points to 3.6-dev +# command to install dependencies +install: "pip install -r requirements-test.txt" +# command to run tests +script: ./runtests diff --git a/README.md b/README.md index e919a9f..d6cdc7a 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,12 @@ +``` ======== PyCscope ======== :Copyright: Copyright 2013 Peter Portante. See LICENSE for details. :Author: Peter Portante -:Release: 1.2.1 -:Date: 2013/03/16 +:Release: 1.2.2 +:Date: 2017/03/30 Purpose ------- @@ -96,11 +97,13 @@ by the `CscopeFinder` plugin for jEdit. Other editors are not tested. Release Notes ------------- -This is PyCscope release 1.2.1 +This is PyCscope release 1.2.2 ========== ========= ====== ==================================================== Date Release Trac Changes ========== ========= ====== ==================================================== +2017/03/30 1.2.2 N/A Fix Travis tests for 2.6 other testing issues. +---------- --------- ------ ---------------------------------------------------- 2013/03/16 1.2.1 N/A Fix strings-as-symbols support (really). ---------- --------- ------ ---------------------------------------------------- 2013/03/16 1.2 N/A Fix strings-as-symbols support; fix end of function @@ -192,3 +195,4 @@ Date Release Trac Changes #6 Create project space. ========== ========= ====== ==================================================== +``` diff --git a/pycscope/__init__.py b/pycscope/__init__.py index e0adc90..39835c8 100755 --- a/pycscope/__init__.py +++ b/pycscope/__init__.py @@ -20,8 +20,9 @@ -f reffile Use 'reffile' as cross-ref file name instead of 'cscope.out' -i srclistfile Use the contents of 'srclistfile' as the list of source files to scan""" -import getopt, sys, os, string, re +import getopt, sys, os, re import keyword, parser, symbol, token +import tokenize class Mark(object): @@ -117,7 +118,8 @@ def main(argv=None): if o == "-f": indexfn = a if o == "-i": - args.extend(list(map(string.rstrip, open(a, 'r').readlines()))) + with open(a) as f: + args.extend(x.rstrip() for x in f) # Search current dir by default if len(args) == 0: @@ -148,7 +150,7 @@ def writeIndex(basepath, fout, indexbuff, fnamesbuff): """ # Write the header and index index = ''.join(indexbuff) - index_len = len(index) + index_len = len(index.encode() if isinstance(u'' , str) else index) hdr_len = len(basepath) + 25 fout.write("cscope 15 %s -c %010d" % (basepath, hdr_len + index_len)) fout.write(index) @@ -175,7 +177,8 @@ def work(basepath, gen, debug): indexbuff_len = parseFile(basepath, fname, indexbuff, indexbuff_len, fnamesbuff, dump=debug) except (SyntaxError, AssertionError) as e: print("pycscope.py: %s: Line %s: %s" % (e.filename, e.lineno, e)) - pass + except Exception as e: + print("pycscope.py: %s: %s" % (fname, e)) return indexbuff, fnamesbuff @@ -221,15 +224,9 @@ def parseFile(basepath, relpath, indexbuff, indexbuff_len, fnamesbuff, dump=Fals """ # Open the file and get the contents fullpath = os.path.join(basepath, relpath) - try: - f = open(fullpath, 'rU') - except IOError as e: - # Can't open a file, emit message and ignore - print("pycscope.py: %s" % e) - return indexbuff_len - filecontents = f.read() - f.close() - + bestopen = getattr(tokenize, 'open', open) + with bestopen(fullpath) as f: + filecontents = f.read() # Add the file mark to the index fnamesbuff.append(relpath) indexbuff.append("\n%s%s\n\n" % (Mark(Mark.FILE), relpath)) diff --git a/requirements-test.txt b/requirements-test.txt new file mode 100644 index 0000000..cccbe2f --- /dev/null +++ b/requirements-test.txt @@ -0,0 +1,2 @@ +coverage==4.0 +nose==1.3.7 diff --git a/test/testgenfiles.py b/test/testgenfiles.py index c8a06f9..39861dd 100644 --- a/test/testgenfiles.py +++ b/test/testgenfiles.py @@ -35,6 +35,6 @@ def testgenfiles(self,): # Actual test fs = list(pycscope.genFiles(tmpd, ['a.py', 'b', "s"], True)) - self.assertEquals(fs, ['a.py', 's/t/f.py', 's/t/e.py', 's/d.py', 's/c.py']) + self.assertEquals(sorted(fs), sorted(['a.py', 's/t/f.py', 's/t/e.py', 's/d.py', 's/c.py'])) finally: shutil.rmtree(tmpd) diff --git a/test/testimports.py b/test/testimports.py index 8ce7a2d..0a876ba 100644 --- a/test/testimports.py +++ b/test/testimports.py @@ -21,7 +21,7 @@ def setUp(self,): self.maxDiff = None def testimports(self,): - cwd = os.getcwd() + cwd = os.path.dirname(__file__) fn = "imports.py" l = pycscope.parseFile(cwd, fn, self.buf, 0, self.fnbuf) self.assertEqual(l, len(self.buf)) diff --git a/test/testissues.py b/test/testissues.py index ddc0bad..a91343b 100644 --- a/test/testissues.py +++ b/test/testissues.py @@ -18,7 +18,7 @@ def test0018(self,): """ Make sure two newlines occur after a file mark when the source file starts with non-symbol text. """ - cwd = os.getcwd() + cwd = os.path.dirname(__file__) fn = "issue0018.py" l = pycscope.parseFile(cwd, fn, self.buf, 0, self.fnbuf) self.assertEqual(l, len(self.buf)) diff --git a/test/testparsefile.py b/test/testparsefile.py index b3f119e..b368649 100644 --- a/test/testparsefile.py +++ b/test/testparsefile.py @@ -21,13 +21,13 @@ def setUp(self,): self.maxDiff = None def testioerrors(self,): - cwd = os.getcwd() + cwd = os.path.dirname(__file__) fn = "_does_not_exist_.py" - l = pycscope.parseFile(cwd, fn, self.buf, 0, self.fnbuf) - self.assertEqual(l, 0) + with self.assertRaises(IOError): + pycscope.parseFile(cwd, fn, self.buf, 0, self.fnbuf) def testbadsyntax(self,): - cwd = os.getcwd() + cwd = os.path.dirname(__file__) fn = "badsyntax.py" try: l = pycscope.parseFile(cwd, fn, self.buf, 0, self.fnbuf)