diff --git a/common/util/parse_diff.py b/common/util/parse_diff.py index a12e1b190..2c1ad81c9 100644 --- a/common/util/parse_diff.py +++ b/common/util/parse_diff.py @@ -9,7 +9,7 @@ Hunk = namedtuple("Hunk", ("raw_lines", "changes", "head_start", "head_length", "saved_start", "saved_length")) Change = namedtuple("Change", ("raw", "type", "head_pos", "saved_pos", "text")) -re_metadata = re.compile("^@@ -(\d+)(,(\d+))? \+(\d+)(,(\d+))? @@") +re_metadata = re.compile(r"^@@ -(\d+)(,(\d+))? \+(\d+)(,(\d+))? @@") def parse_diff(diff_str): diff --git a/core/commands/commit_compare.py b/core/commands/commit_compare.py index d53ca03a9..a82831830 100644 --- a/core/commands/commit_compare.py +++ b/core/commands/commit_compare.py @@ -9,7 +9,7 @@ COMMIT_NODE_CHAR = "●" COMMIT_NODE_CHAR_OPTIONS = "●*" -COMMIT_LINE = re.compile("[%s][ /_\|\-.]*([a-z0-9]{3,})" % COMMIT_NODE_CHAR_OPTIONS) +COMMIT_LINE = re.compile(r"[%s][ /_\|\-.]*([a-z0-9]{3,})" % COMMIT_NODE_CHAR_OPTIONS) class GsCompareCommitCommand(WindowCommand, GitCommand): diff --git a/core/commands/diff.py b/core/commands/diff.py index 54d38f363..8d1110a65 100644 --- a/core/commands/diff.py +++ b/core/commands/diff.py @@ -166,9 +166,9 @@ def run(self, edit, reset=False): cursor_pts = tuple(cursor.a for cursor in self.view.sel() if cursor.a == cursor.b) self.diff_starts = tuple(region.a for region in self.view.find_all("^diff")) - self.diff_header_ends = tuple(region.b for region in self.view.find_all("^\+\+\+.+\n(?=@@)")) + self.diff_header_ends = tuple(region.b for region in self.view.find_all(r"^\+\+\+.+\n(?=@@)")) self.hunk_starts = tuple(region.a for region in self.view.find_all("^@@")) - hunk_starts_following_headers = {region.b for region in self.view.find_all("^\+\+\+.+\n(?=@@)")} + hunk_starts_following_headers = {region.b for region in self.view.find_all(r"^\+\+\+.+\n(?=@@)")} self.hunk_ends = sorted(list( # Hunks end when the next diff starts. set(self.diff_starts[1:]) | diff --git a/core/commands/log.py b/core/commands/log.py index 563d8843d..b48e7d833 100644 --- a/core/commands/log.py +++ b/core/commands/log.py @@ -80,7 +80,7 @@ def run_async(self, **kwargs): commiter_str = self.git("shortlog", "-sne", "HEAD") for line in commiter_str.split('\n'): - m = re.search('\s*(\d*)\s*(.*)\s<(.*)>', line) + m = re.search(r'\s*(\d*)\s*(.*)\s<(.*)>', line) if m is None: continue commit_count, author_name, author_email = m.groups() diff --git a/core/commands/log_graph.py b/core/commands/log_graph.py index 60a3cfeb0..2b9666912 100644 --- a/core/commands/log_graph.py +++ b/core/commands/log_graph.py @@ -10,7 +10,7 @@ COMMIT_NODE_CHAR = "●" COMMIT_NODE_CHAR_OPTIONS = "●*" -GRAPH_CHAR_OPTIONS = " /_\|\-." +GRAPH_CHAR_OPTIONS = r" /_\|\-." COMMIT_LINE = re.compile( "^[{graph_chars}]*[{node_chars}][{graph_chars}]* (?P[a-f0-9]{{5,40}})".format( graph_chars=GRAPH_CHAR_OPTIONS, node_chars=COMMIT_NODE_CHAR_OPTIONS)) @@ -69,7 +69,7 @@ def run(self, edit): args = self.view.settings().get("git_savvy.git_graph_args") graph_content += self.git(*args) graph_content = re.sub( - '(^[{}]*)\*'.format(GRAPH_CHAR_OPTIONS), + r'(^[{}]*)\*'.format(GRAPH_CHAR_OPTIONS), r'\1' + COMMIT_NODE_CHAR, graph_content, flags=re.MULTILINE) @@ -107,7 +107,7 @@ def run_async(self): commiter_str = self.git("shortlog", "-sne", "HEAD") for line in commiter_str.split('\n'): - m = re.search('\s*(\d*)\s*(.*)\s<(.*)>', line) + m = re.search(r'\s*(\d*)\s*(.*)\s<(.*)>', line) if m is None: continue commit_count, author_name, author_email = m.groups() diff --git a/core/git_command.py b/core/git_command.py index 80929658d..8c9909381 100755 --- a/core/git_command.py +++ b/core/git_command.py @@ -317,10 +317,9 @@ def git_binary_path(self): major = int(match.group(1)) minor = int(match.group(2)) patch = int(match.group(3)) - if major < GIT_REQUIRE_MAJOR or \ - (major == GIT_REQUIRE_MAJOR and minor < GIT_REQUIRE_MINOR) or \ - (major == GIT_REQUIRE_MAJOR and minor == GIT_REQUIRE_MINOR and - patch < GIT_REQUIRE_PATCH): + if major < GIT_REQUIRE_MAJOR \ + or (major == GIT_REQUIRE_MAJOR and minor < GIT_REQUIRE_MINOR) \ + or (major == GIT_REQUIRE_MAJOR and minor == GIT_REQUIRE_MINOR and patch < GIT_REQUIRE_PATCH): msg = GIT_TOO_OLD_MSG.format( GIT_REQUIRE_MAJOR, GIT_REQUIRE_MINOR, diff --git a/core/git_mixins/active_branch.py b/core/git_mixins/active_branch.py index c324044b8..465fb3959 100644 --- a/core/git_mixins/active_branch.py +++ b/core/git_mixins/active_branch.py @@ -42,8 +42,8 @@ def _get_branch_status_components(self): valid_punctuation = "".join(c for c in string.punctuation if c not in "~^:?*[\\") branch_pattern = "[A-Za-z0-9" + re.escape(valid_punctuation) + "\u263a-\U0001f645]+?" - branch_suffix = "( \[((ahead (\d+))(, )?)?(behind (\d+))?(gone)?\])?)" - short_status_pattern = "## (" + branch_pattern + ")(\.\.\.(" + branch_pattern + ")" + branch_suffix + "?$" + branch_suffix = r"( \[((ahead (\d+))(, )?)?(behind (\d+))?(gone)?\])?)" + short_status_pattern = "## (" + branch_pattern + r")(\.\.\.(" + branch_pattern + ")" + branch_suffix + "?$" status_match = re.match(short_status_pattern, first_line) if not status_match: diff --git a/core/git_mixins/remotes.py b/core/git_mixins/remotes.py index 0d254c030..e9a8701ef 100644 --- a/core/git_mixins/remotes.py +++ b/core/git_mixins/remotes.py @@ -73,7 +73,7 @@ def project_name_from_url(self, input_url): # git@github.com:divmain/GitSavvy.git # Kind of funky, but does the job _split_url = re.split('/|:', input_url) - _split_url = re.split('\.', _split_url[-1]) + _split_url = re.split(r'\.', _split_url[-1]) return _split_url[0] if len(_split_url) >= 1 else '' def username_from_url(self, input_url): diff --git a/core/interfaces/rebase.py b/core/interfaces/rebase.py index b4d35e2a5..e82eee89b 100644 --- a/core/interfaces/rebase.py +++ b/core/interfaces/rebase.py @@ -15,7 +15,7 @@ COMMIT_NODE_CHAR = "●" COMMIT_NODE_CHAR_OPTIONS = "●*" -COMMIT_LINE = re.compile("\s*[%s]\s*([a-z0-9]{3,})" % COMMIT_NODE_CHAR_OPTIONS) +COMMIT_LINE = re.compile(r"\s*[%s]\s*([a-z0-9]{3,})" % COMMIT_NODE_CHAR_OPTIONS) NEAREST_NODE_PATTERN = re.compile(r'.*\*.*\[(.*?)(?:(?:[\^\~]+[\d]*){1})\]') # http://regexr.com/3gm03 NOT_A_COMMIT_SHA = 'not_a_commit_sha' diff --git a/setup.cfg b/setup.cfg index fb6e4d972..c04f5a052 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,4 +1,4 @@ [pycodestyle] count = False -ignore = E401 +ignore = E401, W503, W504 max-line-length = 120