Skip to content

Commit

Permalink
Properly document flake8 config and fix errors
Browse files Browse the repository at this point in the history
  • Loading branch information
David Lynch committed Jan 11, 2017
1 parent 124bba0 commit 879a187
Show file tree
Hide file tree
Showing 12 changed files with 111 additions and 62 deletions.
7 changes: 7 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[flake8]
ignore =
# E128 continuation line under-indented for visual indent
# E128,
# E501 line too long
E501
exclude = .git,__pycache__,syntax
16 changes: 10 additions & 6 deletions git/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ def find_plugin_directory():
full = os.path.normpath(os.path.join(os.path.dirname(__file__), '..'))
dirname = os.path.split(full)[-1]
return "Packages/" + dirname.replace(".sublime-package", "")


PLUGIN_DIRECTORY = find_plugin_directory()


Expand Down Expand Up @@ -149,6 +151,8 @@ def find_binary(cmd):
)
path = _test_paths_for_executable(extra_paths, cmd)
return path


GIT = find_binary('git')
GITK = find_binary('gitk')

Expand Down Expand Up @@ -205,11 +209,13 @@ def run(self):
env[str('HOME')] = str(env['USERPROFILE'])

# universal_newlines seems to break `log` in python3
proc = subprocess.Popen(self.command,
proc = subprocess.Popen(
self.command,
stdout=self.stdout, stderr=subprocess.STDOUT,
stdin=subprocess.PIPE, startupinfo=startupinfo,
shell=shell, universal_newlines=False,
env=env, cwd=cwd)
env=env, cwd=cwd
)
output = proc.communicate(self.stdin)[0]
if self.error_suppresses_output and proc.returncode is not None and proc.returncode > 0:
output = False
Expand Down Expand Up @@ -241,8 +247,7 @@ def run(self):
class GitCommand(object):
may_change_files = False

def run_command(self, command, callback=None, show_status=True,
filter_empty_args=True, no_save=False, **kwargs):
def run_command(self, command, callback=None, show_status=True, filter_empty_args=True, no_save=False, **kwargs):
if filter_empty_args:
command = [arg for arg in command if arg]
if 'working_dir' not in kwargs:
Expand Down Expand Up @@ -297,8 +302,7 @@ def generic_done(self, result, **kw):
return
self.panel(result)

def _output_to_view(self, output_file, output, clear=False,
syntax="Packages/Diff/Diff.tmLanguage", **kwargs):
def _output_to_view(self, output_file, output, clear=False, syntax="Packages/Diff/Diff.tmLanguage", **kwargs):
output_file.set_syntax_file(syntax)
args = {
'output': output,
Expand Down
6 changes: 4 additions & 2 deletions git/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ def panel_followup(self, picked_status, picked_file, picked_index):
command += ['rm']
command += ['--', picked_file]

self.run_command(command, self.rerun,
working_dir=working_dir)
self.run_command(
command, self.rerun,
working_dir=working_dir
)

def rerun(self, result):
self.run()
Expand Down
20 changes: 13 additions & 7 deletions git/commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ def run(self, edit, target=None):
if target is None:
# 'target' might also be False, in which case we just don't provide an add argument
target = self.get_file_name()
self.get_window().show_input_panel("Message", "",
functools.partial(self.on_input, target), None, None)
self.get_window().show_input_panel(
"Message", "",
functools.partial(self.on_input, target), None, None
)

def on_input(self, target, message):
if message.strip() == "":
Expand Down Expand Up @@ -129,8 +131,10 @@ def message_done(self, message):
# filter out the comments (git commit doesn't do this automatically)
settings = sublime.load_settings("Git.sublime-settings")
historySize = settings.get('history_size')
lines = [line for line in message.split("\n# --------------")[0].split("\n")
if not line.lstrip().startswith('#')]
lines = [
line for line in message.split("\n# --------------")[0].split("\n")
if not line.lstrip().startswith('#')
]
message = '\n'.join(lines).strip()

if len(message) and historySize:
Expand All @@ -141,9 +145,11 @@ def message_done(self, message):
message_file.close()
self.message_file = message_file
# and actually commit
with codecs.open(message_file.name, mode = 'r', encoding = 'utf-8') as fp:
self.run_command(['git', 'commit', '-F', '-', self.extra_options],
self.commit_done, working_dir=self.working_dir, stdin=fp.read())
with codecs.open(message_file.name, mode='r', encoding='utf-8') as fp:
self.run_command(
['git', 'commit', '-F', '-', self.extra_options],
self.commit_done, working_dir=self.working_dir, stdin=fp.read()
)

def commit_done(self, result, **kwargs):
os.remove(self.message_file.name)
Expand Down
3 changes: 1 addition & 2 deletions git/config.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import absolute_import, unicode_literals, print_function, division

import os
import re

import sublime
from . import GitWindowCommand, git_root
Expand Down Expand Up @@ -29,7 +28,7 @@ def url_done(self, result):
if user_end > -1:
# Remove user and pass from url
user_start = url.index('//') + 1
user = url[user_start+1:user_end+1]
user = url[user_start + 1:user_end + 1]
url = url.replace(user, '')
self.window.run_command('open_url', {"url": url})
else:
Expand Down
14 changes: 8 additions & 6 deletions git/core.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import absolute_import, unicode_literals, print_function, division

import os
import sublime
import sublime_plugin

Expand All @@ -11,8 +10,10 @@ class GitCustomCommand(GitWindowCommand):
may_change_files = True

def run(self):
self.get_window().show_input_panel("Git command", "",
self.on_input, None, None)
self.get_window().show_input_panel(
"Git command", "",
self.on_input, None, None
)

def on_input(self, command):
command = str(command) # avoiding unicode
Expand All @@ -38,7 +39,6 @@ def run(self, **args):
import shlex
command_split = shlex.split(self.command)

working_dir = None
if args.get('append_current_file', False) and self.active_file_name():
command_split.extend(('--', self.active_file_name()))

Expand All @@ -61,8 +61,10 @@ def run(self, **args):
def show_in_quick_panel(self, result):
self.results = list(result.rstrip().split('\n'))
if len(self.results):
self.quick_panel(self.results,
self.do_nothing, sublime.MONOSPACE_FONT)
self.quick_panel(
self.results,
self.do_nothing, sublime.MONOSPACE_FONT
)
else:
sublime.status_message("Nothing to show")

Expand Down
6 changes: 3 additions & 3 deletions git/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import sublime_plugin
import os
import re
from . import git_root, GitTextCommand, GitWindowCommand, do_when, goto_xy
from . import GitTextCommand, GitWindowCommand, do_when, goto_xy


class GitDiff (object):
Expand All @@ -22,9 +22,9 @@ def diff_done(self, result):
s = sublime.load_settings("Git.sublime-settings")
syntax = s.get("diff_syntax", "Packages/Diff/Diff.tmLanguage")
if s.get('diff_panel'):
view = self.panel(result, syntax=syntax)
self.panel(result, syntax=syntax)
else:
view = self.scratch(result, title="Git Diff", syntax=syntax)
self.scratch(result, title="Git Diff", syntax=syntax)


class GitDiffCommit (object):
Expand Down
22 changes: 14 additions & 8 deletions git/flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def is_visible(self):
if s.get('flow'):
return True
return False

def is_notag(self):
s = sublime.load_settings("Git.sublime-settings")
if s.get('flow-notag'):
Expand All @@ -32,8 +32,10 @@ def run(self):

def feature_done(self, result):
self.results = result.rstrip().split('\n')
self.quick_panel(self.results, self.panel_done,
sublime.MONOSPACE_FONT)
self.quick_panel(
self.results, self.panel_done,
sublime.MONOSPACE_FONT
)

def panel_done(self, picked):
if 0 > picked < len(self.results):
Expand All @@ -59,8 +61,10 @@ def run(self):

def release_done(self, result):
self.results = result.rstrip().split('\n')
self.quick_panel(self.results, self.panel_done,
sublime.MONOSPACE_FONT)
self.quick_panel(
self.results, self.panel_done,
sublime.MONOSPACE_FONT
)

def panel_done(self, picked):
if 0 > picked < len(self.results):
Expand All @@ -74,7 +78,7 @@ def panel_done(self, picked):
else:
self.picked_release = picked_release
self.get_window().show_input_panel('Enter Tag message:', '', self.tag_message_done, None, None)

def tag_message_done(self, tag_message):
self.run_command(['git', 'flow', 'release', 'finish', '-m', tag_message, self.picked_release])

Expand All @@ -93,8 +97,10 @@ def run(self):

def hotfix_done(self, result):
self.results = result.rstrip().split('\n')
self.quick_panel(self.results, self.panel_done,
sublime.MONOSPACE_FONT)
self.quick_panel(
self.results, self.panel_done,
sublime.MONOSPACE_FONT
)

def panel_done(self, picked):
if 0 > picked < len(self.results):
Expand Down
26 changes: 16 additions & 10 deletions git/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import re

import sublime
import sublime_plugin
from . import GitTextCommand, GitWindowCommand, plugin_file


Expand Down Expand Up @@ -46,8 +45,10 @@ def get_lines(self, selection):
return begin_line + 1, end_line + 1

def blame_done(self, result, focused_line=1):
view = self.scratch(result, title="Git Blame", focused_line=focused_line,
syntax=plugin_file("syntax/Git Blame.tmLanguage"))
self.scratch(
result, title="Git Blame", focused_line=focused_line,
syntax=plugin_file("syntax/Git Blame.tmLanguage")
)


class GitLog(object):
Expand All @@ -62,8 +63,11 @@ def run_log(self, follow, *args):
# 9000 is a pretty arbitrarily chosen limit; picked entirely because
# it's about the size of the largest repo I've tested this on... and
# there's a definite hiccup when it's loading that
command = ['git', 'log', '--no-color', '--pretty=%s (%h)\a%an <%aE>\a%ad (%ar)',
'--date=local', '--max-count=9000', '--follow' if follow else None]
command = [
'git', 'log', '--no-color', '--pretty=%s (%h)\a%an <%aE>\a%ad (%ar)',
'--date=local', '--max-count=9000',
'--follow' if follow else None
]
command.extend(args)
self.run_command(
command,
Expand Down Expand Up @@ -107,7 +111,7 @@ def run(self, edit=None):
# GitLog Copy-Past
self.run_command(
['git', 'log', '--no-color', '--pretty=%s (%h)\a%an <%aE>\a%ad (%ar)',
'--date=local', '--max-count=9000', '--', self.get_file_name()],
'--date=local', '--max-count=9000', '--', self.get_file_name()],
self.show_done)

def show_done(self, result):
Expand Down Expand Up @@ -182,8 +186,10 @@ def run(self):

def branch_done(self, result):
self.results = result.rstrip().split('\n')
self.quick_panel(self.results, self.branch_panel_done,
sublime.MONOSPACE_FONT)
self.quick_panel(
self.results, self.branch_panel_done,
sublime.MONOSPACE_FONT
)

def branch_panel_done(self, picked):
if 0 > picked < len(self.results):
Expand Down Expand Up @@ -268,6 +274,6 @@ def show_done(self, result):
def is_enabled(self):
selection = self.view.sel()[0]
return (
self.view.match_selector(selection.a, "text.git-blame")
or self.view.match_selector(selection.a, "text.git-graph")
self.view.match_selector(selection.a, "text.git-blame") or
self.view.match_selector(selection.a, "text.git-graph")
)
19 changes: 13 additions & 6 deletions git/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import re

import sublime
from . import GitTextCommand, GitWindowCommand, git_root
from . import GitWindowCommand, git_root
from .status import GitStatusCommand


Expand All @@ -25,8 +25,10 @@ def panel_followup(self, picked_status, picked_file, picked_index):
command += ['update-index', '--assume-unchanged']
command += ['--', picked_file]

self.run_command(command, self.rerun,
working_dir=working_dir)
self.run_command(
command, self.rerun,
working_dir=working_dir
)

def rerun(self, result):
self.run()
Expand All @@ -47,8 +49,10 @@ def status_done(self, result):
sublime.status_message("Nothing to show")

def show_status_list(self):
self.quick_panel(self.results, self.panel_done,
sublime.MONOSPACE_FONT)
self.quick_panel(
self.results, self.panel_done,
sublime.MONOSPACE_FONT
)

def status_filter(self, item):
# for this class we don't actually care
Expand All @@ -65,7 +69,10 @@ def panel_done(self, picked):
picked_file = picked_file[0]
# first 1 character is a status code, the second is a space
picked_file = picked_file[2:]
self.run_command(['git', 'update-index', '--no-assume-unchanged', picked_file.strip('"')],self.rerun, working_dir=root)
self.run_command(
['git', 'update-index', '--no-assume-unchanged', picked_file.strip('"')],
self.rerun, working_dir=root
)

def rerun(self, result):
self.run()
Loading

0 comments on commit 879a187

Please sign in to comment.