Skip to content
This repository has been archived by the owner on Dec 3, 2020. It is now read-only.

skip standard java build artifacts #3

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
build/
dist/
grin.egg-info/
__pycache__/
*.pyc
14 changes: 14 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
language: python

python:
- 2.7
- 3.5
- 3.6
- 3.7
- 3.8

install:
- pip install -e .

script:
- nosetests .
16 changes: 4 additions & 12 deletions ANNOUNCE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,10 @@ grin is a grep-like tool for recursively searching through text
files, primarily source code.

Download: http://pypi.python.org/pypi/grin
SVN: https://svn.enthought.com/svn/sandbox/grin/trunk
Git: https://github.com/matthew-brett/grin
License: BSD

grin 1.2.1 is a bug-fix release.
grin 1.30.0 is a feature release

* Windows defaults to not coloring the output. (Paul Pelzl)
report.

* Fix the reading of gzip files. (Brandon Craig Rhodes)

* Quit gracefully when piping to a program that exits prematurely.
(Brandon Craig Rhodes)

* Sort the basenames of files during traversal in order to maintain
a repeatable ordering. (Brandon Craig Rhodes)
* Python 3 compatibility.
* Bugfix: Handle empty lists of skip-dirs and skip-exts.
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
This software is OSI Certified Open Source Software.
OSI Certified is a certification mark of the Open Source Initiative.

Copyright (c) 2007, Enthought, Inc.
Copyright (c) 2007-2020, Enthought, Inc.
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include LICENSE.txt
6 changes: 3 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ Running the unittests requires the nose_ framework::

The development sources are hosted on Github:

https://github.com/rkern/grin
https://github.com/matthew-brett/grin

There is one little tweak to the installation that you may want to consider. By
default, setuptools installs scripts indirectly; the scripts installed to
$prefix/bin or Python2x\Scripts use setuptools' pkg_resources module to load
$prefix/bin or Python\Scripts use setuptools' pkg_resources module to load
the exact version of grin egg that installed the script, then runs the script's
main() function. This is not usually a bad feature, but it can add substantial
startup overhead for a small command-line utility like grin. If you want the
Expand Down Expand Up @@ -241,4 +241,4 @@ Bugs and Such

Please make a new issue at the Github issue tracker.

https://github.com/rkern/grin
https://github.com/matthew-brett/grin
49 changes: 49 additions & 0 deletions RELEASING.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Release process

Check log since last release, build `ChangeLog`.

```
git clean -fxd
```

## Do pre-release

Change `tag_build` to `rc` in `setup.cfg`.

Check travis-ci.

```
git clean -fxd
python setup.py sdist
twine upload sdist/grin*.tar.gz
```

As for feedback.

Change `tag_build` to empty in `setup.cfg`.

Check travis-ci.

```
git clean -fxd
python setup.py sdist
twine upload sdist/grin*.tar.gz
```

```
git tag -s <version-no>
git push --tags
```

## Prepare for next release

Change `__version__` in `grin.py`.

Change `__version__` in `setup.py`.

Change `tag_build` to `.dev` in `setup.cfg`.

```
git commit
git push
```
5 changes: 2 additions & 3 deletions examples/grinimports.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
# -*- coding: UTF-8 -*-
""" Transform Python files into normalized import statements for grepping.
"""

import compiler
from compiler.visitor import ASTVisitor, walk
from cStringIO import StringIO
from io import StringIO
import os
import shlex
import sys
Expand Down Expand Up @@ -70,7 +69,7 @@ def normalize_file(filename, *args):
"""
try:
ast = compiler.parseFile(filename)
except Exception, e:
except Exception as e:
return StringIO('')
ip = ImportPuller()
walk(ast, ip)
Expand Down
4 changes: 2 additions & 2 deletions examples/grinpython.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
""" Transform Python code by omitting strings, comments, and/or code.
"""

from cStringIO import StringIO
from io import BytesIO
import os
import shlex
import string
Expand Down Expand Up @@ -55,7 +55,7 @@ def __call__(self, filename, mode='rb'):
""" Open a file and convert it to a filelike object with transformed
contents.
"""
g = StringIO()
g = BytesIO()
f = open(filename, mode)
try:
gen = tokenize.generate_tokens(f.readline)
Expand Down
68 changes: 40 additions & 28 deletions grin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python
""" grin searches text files.
"""
from __future__ import print_function

import bisect
import fnmatch
Expand All @@ -11,21 +12,28 @@
import shlex
import stat
import sys
from io import UnsupportedOperation

import argparse

if sys.version_info[0] > 2:
to_str = lambda s : s.decode('latin1')
ints2bytes = bytes
else:
to_str = str
ints2bytes = lambda ints : ''.join(map(chr, ints))

#### Constants ####
__version__ = '1.2.1'
__version__ = '1.3.1'

# Maintain the numerical order of these constants. We use them for sorting.
PRE = -1
MATCH = 0
POST = 1

# Use file(1)'s choices for what's text and what's not.
TEXTCHARS = ''.join(map(chr, [7,8,9,10,12,13,27] + range(0x20, 0x100)))
ALLBYTES = ''.join(map(chr, range(256)))
TEXTCHARS = ints2bytes([7,8,9,10,12,13,27] + list(range(0x20, 0x100)))
ALLBYTES = ints2bytes(range(256))

COLOR_TABLE = ['black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan',
'white', 'default']
Expand All @@ -35,12 +43,11 @@
}

# gzip magic header bytes.
GZIP_MAGIC = '\037\213'
GZIP_MAGIC = b'\037\213'

# Target amount of data to read into memory at a time.
READ_BLOCKSIZE = 16 * 1024 * 1024


def is_binary_string(bytes):
""" Determine if a string is classified as binary rather than text.

Expand All @@ -54,7 +61,8 @@ def is_binary_string(bytes):
"""
nontext = bytes.translate(ALLBYTES, TEXTCHARS)
return bool(nontext)



def get_line_offsets(block):
""" Compute the list of offsets in DataBlock 'block' which correspond to
the beginnings of new lines.
Expand All @@ -80,7 +88,8 @@ def get_line_offsets(block):
# Keep track of the count of lines within the "current block"
if next_newline >= block.start and next_newline < block.end:
line_count += 1



def colorize(s, fg=None, bg=None, bold=False, underline=False, reverse=False):
""" Wraps a string with ANSI color escape sequences corresponding to the
style parameters given.
Expand Down Expand Up @@ -207,7 +216,7 @@ def __init__(self, regex, options=None):
def read_block_with_context(self, prev, fp, fp_size):
""" Read a block of data from the file, along with some surrounding
context.

Parameters
----------
prev : DataBlock, or None
Expand All @@ -216,23 +225,23 @@ def read_block_with_context(self, prev, fp, fp_size):

fp : filelike object
The source of block data.

fp_size : int or None
Size of the file in bytes, or None if the size could not be
determined.

Returns
-------
A DataBlock representing the "current" block along with context.
"""
if fp_size is None:
target_io_size = READ_BLOCKSIZE
block_main = fp.read(target_io_size)
block_main = to_str(fp.read(target_io_size))
is_last_block = len(block_main) < target_io_size
else:
remaining = max(fp_size - fp.tell(), 0)
target_io_size = min(READ_BLOCKSIZE, remaining)
block_main = fp.read(target_io_size)
block_main = to_str(fp.read(target_io_size))
is_last_block = target_io_size == remaining

if prev is None:
Expand Down Expand Up @@ -271,12 +280,13 @@ def read_block_with_context(self, prev, fp, fp_size):
before_lines = prev.data[before_start:prev.end]
# Using readline() to force this block out to a newline boundary...
curr_block = (prev.data[prev.end:] + block_main +
('' if is_last_block else fp.readline()))
('' if is_last_block else to_str(fp.readline())))
# Read in some lines of 'after' context.
if is_last_block:
after_lines = ''
else:
after_lines_list = [fp.readline() for i in range(self.options.after_context)]
after_lines_list = [to_str(fp.readline())
for i in range(self.options.after_context)]
after_lines = ''.join(after_lines_list)

result = DataBlock(
Expand Down Expand Up @@ -308,13 +318,15 @@ def do_grep(self, fp):
fp_size = None # gzipped data is usually longer than the file
else:
try:
status = os.fstat(fp.fileno())
file_no = fp.fileno()
except (AttributeError, UnsupportedOperation): # doesn't support fileno()
fp_size = None
else:
status = os.fstat(file_no)
if stat.S_ISREG(status.st_mode):
fp_size = status.st_size
else:
fp_size = None
except AttributeError: # doesn't support fileno()
fp_size = None

block = self.read_block_with_context(None, fp, fp_size)
while block.end > block.start:
Expand Down Expand Up @@ -457,7 +469,7 @@ def report(self, context_lines, filename=None):
color_substring = colorize(old_substring, **style)
line = line[:start] + color_substring + line[end:]
total_offset += len(color_substring) - len(old_substring)

ns = dict(
lineno = i+1,
sep = {PRE: '-', POST: '+', MATCH: ':'}[kind],
Expand Down Expand Up @@ -495,8 +507,8 @@ def grep_a_file(self, filename, opener=open):
f = sys.stdin
filename = '<STDIN>'
else:
# 'r' does the right thing for both open ('rt') and gzip.open ('rb')
f = opener(filename, 'r')
# Always open in binary mode
f = opener(filename, 'rb')
try:
unique_context = self.do_grep(f)
finally:
Expand Down Expand Up @@ -587,7 +599,7 @@ def _is_binary_file(self, f):
"""
try:
bytes = f.read(self.binary_bytes)
except Exception, e:
except Exception as e:
# When trying to read from something that looks like a gzipped file,
# it may be corrupt. If we do get an error, assume that the file is binary.
return True
Expand Down Expand Up @@ -816,13 +828,13 @@ def get_grin_arg_parser(parser=None):
default=True, action='store_true',
help="do skip .hidden directories [default]")
parser.add_argument('-d', '--skip-dirs',
default='CVS,RCS,.svn,.hg,.bzr,build,dist',
default='CVS,RCS,.svn,.hg,.bzr,build,dist,target,node_modules',
help="comma-separated list of directory names to skip [default=%(default)r]")
parser.add_argument('-D', '--no-skip-dirs', dest='skip_dirs',
action='store_const', const='',
help="do not skip any directories")
parser.add_argument('-e', '--skip-exts',
default='.pyc,.pyo,.so,.o,.a,.tgz,.tar.gz,.rar,.zip,~,#,.bak,.png,.jpg,.gif,.bmp,.tif,.tiff,.pyd,.dll,.exe,.obj,.lib',
default='.pyc,.pyo,.so,.o,.a,.tgz,.tar.gz,.rar,.zip,~,#,.bak,.png,.jpg,.gif,.bmp,.tif,.tiff,.pyd,.dll,.exe,.obj,.lib,.class',
help="comma-separated list of file extensions to skip [default=%(default)r]")
parser.add_argument('-E', '--no-skip-exts', dest='skip_exts',
action='store_const', const='',
Expand Down Expand Up @@ -874,13 +886,13 @@ def get_grind_arg_parser(parser=None):
default=True, action='store_true',
help="do skip .hidden directories")
parser.add_argument('-d', '--skip-dirs',
default='CVS,RCS,.svn,.hg,.bzr,build,dist',
default='CVS,RCS,.svn,.hg,.bzr,build,dist,target,node_modules',
help="comma-separated list of directory names to skip [default=%(default)r]")
parser.add_argument('-D', '--no-skip-dirs', dest='skip_dirs',
action='store_const', const='',
help="do not skip any directories")
parser.add_argument('-e', '--skip-exts',
default='.pyc,.pyo,.so,.o,.a,.tgz,.tar.gz,.rar,.zip,~,#,.bak,.png,.jpg,.gif,.bmp,.tif,.tiff,.pyd,.dll,.exe,.obj,.lib',
default='.pyc,.pyo,.so,.o,.a,.tgz,.tar.gz,.rar,.zip,~,#,.bak,.png,.jpg,.gif,.bmp,.tif,.tiff,.pyd,.dll,.exe,.obj,.lib,.class',
help="comma-separated list of file extensions to skip [default=%(default)r]")
parser.add_argument('-E', '--no-skip-exts', dest='skip_exts',
action='store_const', const='',
Expand Down Expand Up @@ -1032,15 +1044,15 @@ def grin_main(argv=None):
sys.stdout.write(report)
except KeyboardInterrupt:
raise SystemExit(0)
except IOError, e:
except IOError as e:
if 'Broken pipe' in str(e):
# The user is probably piping to a pager like less(1) and has exited
# it. Just exit.
raise SystemExit(0)
raise

def print_line(filename):
print filename
print(filename)

def print_null(filename):
# Note that the final filename will have a trailing NUL, just like
Expand Down Expand Up @@ -1073,7 +1085,7 @@ def grind_main(argv=None):
output(filename)
except KeyboardInterrupt:
raise SystemExit(0)
except IOError, e:
except IOError as e:
if 'Broken pipe' in str(e):
# The user is probably piping to a pager like less(1) and has exited
# it. Just exit.
Expand Down
Loading