-
Notifications
You must be signed in to change notification settings - Fork 26
Python 3 #39
base: master
Are you sure you want to change the base?
Python 3 #39
Changes from all commits
9489ce1
073201f
b28cb48
699de2e
cb97803
cbbb4e7
b524804
92ab346
8bc4ec2
2c3b181
32db508
f0ccc14
9f4f49f
e9a7914
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
.tox/ | ||
*.clouseau | ||
*.swn | ||
*.egg-info | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
language: python | ||
python: | ||
- "2.7" | ||
- 2.7 | ||
- 3.6 | ||
install: | ||
- pip install -r requirements.txt | ||
- pip install -r requirements.txt | ||
script: | ||
- pip freeze | ||
- nosetests -d | ||
- nosetests |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
from abstract import AbstractClient | ||
from __future__ import absolute_import | ||
from .abstract import AbstractClient | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we're doing this, could we just use the full paths to the imports? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably? This came from the earlier Python 3 PR, so it's not code I wrote. I'll take a look, though |
||
from jinja2 import Template, Environment, PackageLoader | ||
from colors import * | ||
from .colors import * | ||
import codecs | ||
import re | ||
import subprocess | ||
import sys | ||
import os | ||
import tempfile | ||
|
||
class ConsoleClient(AbstractClient): | ||
""" | ||
|
@@ -62,20 +65,18 @@ def render(self, terms, data): | |
#m[1] = m[1].replace(term, orange_bg(term) ) | ||
|
||
|
||
|
||
|
||
data_to_render = template.render(data=data) | ||
scratchfile_handle, scratchfile_path = tempfile.mkstemp() | ||
rendered = template.render(data=data) | ||
|
||
with codecs.open(scratchfile_path, 'w', 'utf-8') as scratchfile: | ||
scratchfile.write(rendered) | ||
|
||
try: | ||
pager = subprocess.Popen(['less', '-F', '-R', '-S', '-X', '-K'], stdin=subprocess.PIPE, stdout=sys.stdout) | ||
lines = data_to_render.split('\n') | ||
for line in lines: | ||
pager.stdin.write( line.encode('utf-8') + '\n' ) | ||
pager.stdin.close() | ||
pager.wait() | ||
subprocess.call(['less', '-F', '-R', '-S', '-X', '-K'], stdin=scratchfile_handle) | ||
except KeyboardInterrupt: | ||
pass | ||
|
||
finally: | ||
os.remove(scratchfile_path) | ||
|
||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
from abstract import AbstractClient | ||
from __future__ import print_function | ||
from __future__ import absolute_import | ||
from .abstract import AbstractClient | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same with the import path |
||
from jinja2 import Template, Environment, PackageLoader | ||
|
||
class ConsoleThinClient(AbstractClient): | ||
|
@@ -19,4 +21,4 @@ def render(self, terms, data): | |
template = env.get_template('console_thin.html') | ||
|
||
data_to_render = template.render(data=data, has_matches=len(matches) > 0) | ||
print data_to_render | ||
print(data_to_render) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
from __future__ import print_function | ||
from __future__ import absolute_import | ||
from builtins import object | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does it work that these imports are above the |
||
#! /usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
# | ||
|
@@ -9,17 +12,17 @@ | |
import pprint | ||
import sys | ||
import subprocess | ||
from clients import * | ||
from clients.colors import * | ||
from parser import Parser | ||
from commit_parser import CommitParser | ||
from terms_collector import TermsCollector | ||
from clouseau_model import ClouseauModel | ||
from .clients import * | ||
from .clients.colors import * | ||
from .parser import Parser | ||
from .commit_parser import CommitParser | ||
from .terms_collector import TermsCollector | ||
from .clouseau_model import ClouseauModel | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above re: imports |
||
|
||
|
||
VERSION='0.2.0' | ||
|
||
class Clouseau: | ||
class Clouseau(object): | ||
""" | ||
Wrap and delegate | ||
""" | ||
|
@@ -41,7 +44,7 @@ def main(self , _args, client): | |
if(not args['skip']): | ||
self.clone_repo( args['url'], args['repo_dir'] ) | ||
else: | ||
print blue( 'Skipping git-clone or git-pull as --skip was found on the command line.' ) | ||
print(blue( 'Skipping git-clone or git-pull as --skip was found on the command line.' )) | ||
|
||
if args['revlist'] != None and args['revlist'] != 'all': | ||
parser = CommitParser() | ||
|
@@ -61,14 +64,14 @@ def clone_repo(self, url, destination): | |
_out = subprocess.check_output(['git', 'clone', url, destination]) | ||
|
||
except subprocess.CalledProcessError: | ||
print blue( "Directory, %s, exits. Trying git-pull instead of clone." % destination ) | ||
print(blue( "Directory, %s, exits. Trying git-pull instead of clone." % destination )) | ||
_out = subprocess.check_output(['git', '--git-dir=%s/.git' % destination, 'pull']) | ||
print smoke( "Git says: %s" % _out ) | ||
print(smoke( "Git says: %s" % _out )) | ||
return _out | ||
|
||
except : | ||
e = sys.exc_info()[0] | ||
print red( 'Problem writing to destination: %s' % destination ) | ||
print(red( 'Problem writing to destination: %s' % destination )) | ||
raise | ||
|
||
return _out | ||
|
@@ -83,7 +86,8 @@ def parse_args( self, arguments ): | |
_pattern_path = os.path.join( _dir, _default_pattern_file ) | ||
_temp = os.path.join( _dir, "../temp") | ||
|
||
p = arse.ArgumentParser (prog="clouseau", description=" Clouseau: A silly git inspector", version=VERSION) | ||
p = arse.ArgumentParser (prog="clouseau", description=" Clouseau: A silly git inspector") | ||
p.add_argument('--version', action='version', version=VERSION) | ||
p.add_argument('--url', '-u', required=True, action="store", dest="url", | ||
help="The fully qualified git URL (http://www.kernel.org/pub/software/scm/git/docs/git-clone.html)") | ||
p.add_argument('--term', '-t', required=False, action="store", dest="term", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
from builtins import object | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above re: placement above the |
||
#! /usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
# | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,17 @@ | ||
from __future__ import print_function | ||
from __future__ import absolute_import | ||
from builtins import object | ||
|
||
import os | ||
import sys | ||
import re | ||
import subprocess | ||
import pprint | ||
from clouseau_model import ClouseauModel | ||
from .clouseau_model import ClouseauModel | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same re: imports |
||
|
||
|
||
# ----------------------------------------------------------------------------------------------- | ||
class CommitParser: | ||
class CommitParser(object): | ||
""" | ||
Converts git-show's stdout to Python dictionary for any commit messages and file changes that match the terms in the patterns files | ||
""" | ||
|
@@ -25,7 +28,7 @@ def parse( self, terms, repo, revlist, clouseau_model, **kwargs ): | |
for rev in revlist.strip().split(' '): | ||
output = self.get_commit(git_dir, rev) | ||
if output.strip() == '': | ||
print "WARNING: No output was returned from git for commit [%s]. Ensure the commit exists" % rev | ||
print("WARNING: No output was returned from git for commit [%s]. Ensure the commit exists" % rev) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we use |
||
else: | ||
self.parse_commit( terms, output, clouseau_model ) | ||
|
||
|
@@ -38,7 +41,7 @@ def get_commit(self, git_dir, commit): | |
git_show = subprocess.Popen(git_show_cmd, stderr=subprocess.PIPE, stdout=subprocess.PIPE) # , cwd=git_dir | ||
(out,err) = git_show.communicate() | ||
if err: | ||
print "ERROR running git command [%s]: %s" % (git_show_cmd, err) | ||
print("ERROR running git command [%s]: %s" % (git_show_cmd, err)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above re: string formatting. |
||
|
||
return out | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
from builtins import str | ||
from builtins import object | ||
|
||
import os | ||
import sys | ||
import re | ||
import subprocess | ||
|
||
# ----------------------------------------------------------------------------------------------- | ||
class Parser: | ||
class Parser(object): | ||
""" | ||
Converts git-grep's stdout to Python dictionary | ||
""" | ||
|
@@ -60,32 +62,32 @@ def search( self, git_dir, terms, revlist, clouseau ): | |
stdout=subprocess.PIPE) | ||
|
||
(out,err) = git_grep.communicate() | ||
|
||
clouseau.update( {term: {}} ) | ||
|
||
for line in out.split('\n'): | ||
for line in out.split(b'\n'): | ||
# We don't know how a lot of the data is encoded, so make sure it's utf-8 before | ||
# processing | ||
if line == '': | ||
continue | ||
try: | ||
line = unicode( line, 'utf-8' ) | ||
line = str( line, 'utf-8' ) | ||
except UnicodeDecodeError: | ||
line = unicode( line, 'latin-1' ) | ||
line = str( line, 'latin-1' ) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. More a comment than anything specific to this PR, this seems like an incredibly fragile way to test encoding. |
||
|
||
|
||
if file_name_heading.match( line ): | ||
title = line.split(':', 1)[1] | ||
title = line.replace('/','_') | ||
title = title.replace('.','_').strip() | ||
_src = line.strip().encode('utf-8') | ||
_srca = _src.split(':', 1) | ||
_srca = _src.split(b':', 1) | ||
clouseau[term][title] = {'src' : _srca[1] } | ||
clouseau[term][title]['refspec'] = _srca[0] | ||
git_log_cmd = subprocess.Popen( ['git', '--git-dir', git_dir, 'log', _srca[0] , '-1'],\ | ||
stderr=subprocess.PIPE, stdout=subprocess.PIPE ) | ||
git_log = git_log_cmd.communicate()[0] | ||
clouseau[term][title]['git_log'] = [ x.strip() for x in git_log.split('\n') if x != '' ] | ||
clouseau[term][title]['git_log'] = [ x.strip() for x in git_log.split(b'\n') if x != '' ] | ||
#clouseau[term][title] = {'ref' : _srca[0] } | ||
clouseau[term][title]['matched_lines'] = [] | ||
continue | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
jinja2 | ||
nose | ||
nose-progressive | ||
future |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
[nosetests] | ||
verbosity=2 | ||
nocapture=1 | ||
with-progressive=1 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[tox] | ||
envlist=py27,py36,py37 | ||
|
||
[testenv] | ||
deps=-rrequirements.txt | ||
commands=nosetests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If tox and Travis are using 3.6, want to bump this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good call