Skip to content

Commit e7aed98

Browse files
committed
flake8 fixes
1 parent 3c8c9dc commit e7aed98

File tree

9 files changed

+44
-17
lines changed

9 files changed

+44
-17
lines changed

.flake8

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[flake8]
2+
max-line-length = 120

README.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# pick-git
22

3+
4+
![License](https://camo.githubusercontent.com/890acbdcb87868b382af9a4b1fac507b9659d9bf/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)
5+
36
__pick-git__ is a set of command line tools for leveraging thoughtbot's [pick](https://github.com/calleerlandsson/pick) to turbocharge your Git workflow.
47

58
Git can be a bit of a pain, especially when passing branches or commit hashes as args. Big projects have lots of branches and tons of commits. Finding and copying commit hashes to compare commits, for example, is awkward and slow.
@@ -25,7 +28,6 @@ Check out how __pick-git__ removes the pain of finding and comparing commits.
2528

2629
![pick-git -b commit git diff](https://raw.githubusercontent.com/kylebebak/pick-git/master/examples/ghp.gif)
2730

28-
2931
I invoked `ghp -b gd`, but what just happened? Let's break it down.
3032

3133
I have `ghp` aliased to `pick-git --function commit`. The function argument is one of the public functions exposed by pick-git.
@@ -34,6 +36,7 @@ I have `ghp` aliased to `pick-git --function commit`. The function argument is o
3436

3537
At the end the final command that was invoked, `gd 28faaf7 4750072`, was printed to the console. I was able to find two commits and compare them very quickly and with very few keystrokes. __Even if these commits had been in a much bigger project and were months old__, pick's fuzzy select would have found them in no time as long as my commit messages were descriptive.
3638

39+
3740
### Shortcuts to pick-git Public Functions
3841
It's a good idea to create shortcut aliases to all of the functions exposed by __pick-git__. You can simply copy and paste the following into your startup script, e.g. `.bash_profile`.
3942

@@ -64,6 +67,7 @@ Here are descriptions of __pick-git__'s public functions. Run `pick-git -h` to g
6467
- __branch_compare__: Find out how far ahead or behind `this` branch is compared with `that`. A `detailed` comparison shows all commits instead of just the commit count.
6568
- __file_commit__: Pick a file from index, and show all commits for this file. Pick a commit and diff file against HEAD or `show` it.
6669

70+
6771
### --shell and --rcfile
6872
I actually lied above. I really have `ghp` aliased to `pick-git --shell /bin/bash --rcfile ~/.git_aliases --function commit`. What are these --shell and --rcfile args, and why are they useful?
6973

@@ -82,6 +86,7 @@ alias ga='git add'
8286
alias gr='git reset'
8387
~~~
8488

89+
8590
### Help
8691
Run `pick-git -h`.
8792

main.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from pick_git.command_line import main
22

3+
34
if __name__ == '__main__':
45
"""Ensure that the script can be invoked from the command line while testing
56
the package, i.e. without going through the shim created by `setuptools` when

pick_git/command_line.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import subprocess, argparse, sys
1+
import subprocess
2+
import argparse
3+
import sys
24

35
from .pg import PG
46
from .helpers import PGPublicMethodMixin

pick_git/core.py

+13-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import subprocess, sys, os
1+
import subprocess
2+
import sys
3+
import os
24
from subprocess import STDOUT, PIPE
35
from functools import wraps
46

@@ -8,13 +10,15 @@ def repository_root():
810
"""
911
return subprocess.check_output(['git', 'rev-parse', '--show-toplevel']).strip().decode('utf-8')
1012

13+
1114
def cd_repository_root():
1215
"""Change directory to repo root. `os.chdir` means directory is changed for
1316
instance of shell from which script is executed, rather than only in child
1417
process.
1518
"""
1619
os.chdir(repository_root())
1720

21+
1822
def current_branch():
1923
"""Return name of currently checked out branch.
2024
"""
@@ -32,6 +36,7 @@ def add_new_line(b):
3236
b += bytes('\n', 'utf-8')
3337
return b
3438

39+
3540
def exit_on_keyboard_interrupt(f):
3641
"""Decorator that allows user to exit script by sending a keyboard interrupt
3742
(ctrl + c) without raising an exception.
@@ -47,6 +52,7 @@ def wrapper(*args, **kwargs):
4752
raise KeyboardInterrupt
4853
return wrapper
4954

55+
5056
@exit_on_keyboard_interrupt
5157
def pick_branch(*args):
5258
"""Pick a branch, local or remote.
@@ -55,6 +61,7 @@ def pick_branch(*args):
5561
branch = subprocess.check_output(['pick'], stdin=branches.stdout)
5662
return branch.split()[-1].decode('utf-8')
5763

64+
5865
@exit_on_keyboard_interrupt
5966
def pick_tag(*args):
6067
"""Pick a local tag.
@@ -63,6 +70,7 @@ def pick_tag(*args):
6370
branch = subprocess.check_output(['pick'], stdin=branches.stdout)
6471
return branch.split()[-1].decode('utf-8')
6572

73+
6674
@exit_on_keyboard_interrupt
6775
def pick_commit(*args):
6876
"""Pick a commit hash.
@@ -73,6 +81,7 @@ def pick_commit(*args):
7381
commit = p.communicate(input=commits)[0]
7482
return commit.split()[0].decode('utf-8')
7583

84+
7685
@exit_on_keyboard_interrupt
7786
def pick_commit_reflog(*args):
7887
"""Pick a commit hash from the reflog.
@@ -83,15 +92,17 @@ def pick_commit_reflog(*args):
8392
commit = p.communicate(input=commits)[0]
8493
return commit.split()[0].decode('utf-8')
8594

95+
8696
@exit_on_keyboard_interrupt
8797
def pick_modified_file(*args):
8898
"""Pick a file whose state differs between branches or commits, which are
8999
passed in `args`. `args` can contain between 0 and 2 elements.
90100
"""
91-
files = subprocess.Popen(('git', 'diff', '--name-only',) + args, stdout=PIPE)
101+
files = subprocess.Popen(('git', 'diff', '--name-only') + args, stdout=PIPE)
92102
file = subprocess.check_output(['pick'], stdin=files.stdout)
93103
return file.strip().decode('utf-8')
94104

105+
95106
@exit_on_keyboard_interrupt
96107
def pick_file(*args):
97108
"""Pick a file from the index.

pick_git/helpers.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,13 @@ def _pick_file(self, *args, **kwargs):
6464
function = kwargs.get('function')
6565
show = kwargs.pop('show', False)
6666
cd_repository_root()
67-
entities = [function(), function() if kwargs.pop('both', False) else 'HEAD']; self.copy(' '.join(entities))
67+
entities = [function(), function() if kwargs.pop('both', False) else 'HEAD']
68+
self.copy(' '.join(entities))
6869
file = pick_modified_file(*entities)
69-
if show: # ugly syntax, but (a, b*, c) syntax isn't valid in python 2
70-
self.execute(*('git', 'show',) + args + ('{}:{}'.format(entities[0], file),))
70+
if show: # ugly syntax, but (a, b*, c) syntax isn't valid in python 2
71+
self.execute(*('git', 'show') + args + ('{}:{}'.format(entities[0], file),))
7172
else:
72-
self.execute(*('git', 'diff',) + args + ('{} -- {} {}'.format(entities[0], entities[1], file),))
73+
self.execute(*('git', 'diff') + args + ('{} -- {} {}'.format(entities[0], entities[1], file),))
7374

7475
def branch_file(self, *args, **kwargs):
7576
"""Pick branch(es), get list of files that are different in these
@@ -112,13 +113,14 @@ def file_commit(self, *args, **kwargs):
112113
"""
113114
show = kwargs.pop('show', False)
114115
cd_repository_root()
115-
file = pick_file(); self.copy(file)
116+
file = pick_file()
117+
self.copy(file)
116118
commit = pick_commit('--follow', '--', file)
117119
try:
118120
other_file = pick_modified_file(commit, raise_exception=True)
119121
except KeyboardInterrupt:
120122
other_file = file
121123
if show:
122-
self.execute(*('git', 'show',) + args + ('{}:{}'.format(commit, file),))
124+
self.execute(*('git', 'show') + args + ('{}:{}'.format(commit, file),))
123125
else:
124-
self.execute(*('git', 'diff',) + args + ('{} -- {} {}'.format(commit, file, other_file),))
126+
self.execute(*('git', 'diff') + args + ('{} -- {} {}'.format(commit, file, other_file),))

pick_git/pg.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ def __init__(self, no_copy=False, shell='', rcfile='', **kwargs):
1111
self.rcfile = rcfile
1212

1313
self._copy = lambda text: None
14-
if no_copy: # don't attempt to use pyperclip
14+
if no_copy: # don't attempt to use pyperclip
1515
return
16-
try: # import pyperclip if it's installed, use `pyperclip.copy` if it works
16+
try: # import pyperclip if it's installed, use `pyperclip.copy` if it works
1717
import pyperclip
1818
except ImportError:
1919
print('install pyperclip for a better experience')
@@ -36,7 +36,8 @@ def execute(self, *commands):
3636
`shell` var, the shell specified by the $SHELL env var, or by the default
3737
shell.
3838
"""
39-
commands = ' '.join(commands); print(commands)
39+
commands = ' '.join(commands)
40+
print(commands)
4041
rcfile = ['--rcfile', self.rcfile] if self.rcfile else []
4142
if self.shell:
4243
p = Popen([self.shell] + rcfile + ['-i', '-c', commands])

setup.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
from setuptools import setup
22

3+
34
setup(
45
name='pick-git',
56
version='1.2.1',
67
description="Use pick by thoughtbot to turbocharge your Git workflow",
78
long_description='Check it out on GitHub',
89
keywords='pick git thoughtbot fuzzy select terminal productivity',
910
url='https://github.com/kylebebak/pick-git',
10-
download_url = 'https://github.com/kylebebak/pick-git/tarball/1.2.1',
11+
download_url='https://github.com/kylebebak/pick-git/tarball/1.2.1',
1112
author='kylebebak',
1213
author_email='[email protected]',
1314
license='MIT',
@@ -22,5 +23,5 @@
2223
'Intended Audience :: Developers',
2324
'License :: OSI Approved :: MIT License',
2425
'Programming Language :: Python',
25-
]
26+
],
2627
)

tests/test_core.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import unittest
22
from pick_git import pg
33

4+
45
class TestCore(unittest.TestCase):
56

67
def test_name(self):
7-
self.assertEqual(1,1)
8+
self.assertEqual(1, 1)
9+
810

911
if __name__ == '__main__':
1012
unittest.main()

0 commit comments

Comments
 (0)