Skip to content

Commit

Permalink
Add and fix Flake8 warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk committed Oct 11, 2023
1 parent 5a2a1f8 commit 035180e
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 14 deletions.
3 changes: 3 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[flake8]
extend-ignore = E203
max-line-length = 88
7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,12 @@ repos:
- id: isort
args: [--add-import=from __future__ import annotations]

- repo: https://github.com/PyCQA/flake8
rev: 6.1.0
hooks:
- id: flake8
additional_dependencies:
[flake8-2020, flake8-implicit-str-concat, flake8-logging]

ci:
autoupdate_schedule: quarterly
33 changes: 23 additions & 10 deletions cherry_picker/cherry_picker.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,9 @@ def set_paused_state(self):
set_state(WORKFLOW_STATES.BACKPORT_PAUSED)

def remember_previous_branch(self):
"""Save the current branch into Git config to be able to get back to it later."""
"""Save the current branch into Git config
to be able to get back to it later.
"""
current_branch = get_current_branch()
save_cfg_vals_to_git_cfg(previous_branch=current_branch)

Expand All @@ -161,7 +163,8 @@ def upstream(self):
"""Get the remote name to use for upstream branches
Uses the remote passed to `--upstream-remote`.
If this flag wasn't passed, it uses "upstream" if it exists or "origin" otherwise.
If this flag wasn't passed, it uses "upstream" if it exists or "origin"
otherwise.
"""
# the cached calculated value of the property
if self._upstream is not None:
Expand Down Expand Up @@ -204,7 +207,10 @@ def get_cherry_pick_branch(self, maint_branch):
return f"backport-{self.commit_sha1[:7]}-{maint_branch}"

def get_pr_url(self, base_branch, head_branch):
return f"https://github.com/{self.config['team']}/{self.config['repo']}/compare/{base_branch}...{self.username}:{head_branch}?expand=1"
return (
f"https://github.com/{self.config['team']}/{self.config['repo']}"
f"/compare/{base_branch}...{self.username}:{head_branch}?expand=1"
)

def fetch_upstream(self):
"""git fetch <upstream>"""
Expand Down Expand Up @@ -547,7 +553,9 @@ def abort_cherry_pick(self):
state = self.get_state_and_verify()
if state != WORKFLOW_STATES.BACKPORT_PAUSED:
raise ValueError(
f"One can only abort a paused process. Current state: {state}. Expected state: {WORKFLOW_STATES.BACKPORT_PAUSED}"
"One can only abort a paused process. "
f"Current state: {state}. "
f"Expected state: {WORKFLOW_STATES.BACKPORT_PAUSED}"
)

try:
Expand Down Expand Up @@ -580,7 +588,9 @@ def continue_cherry_pick(self):
state = self.get_state_and_verify()
if state != WORKFLOW_STATES.BACKPORT_PAUSED:
raise ValueError(
f"One can only continue a paused process. Current state: {state}. Expected state: {WORKFLOW_STATES.BACKPORT_PAUSED}"
"One can only continue a paused process. "
f"Current state: {state}. "
f"Expected state: {WORKFLOW_STATES.BACKPORT_PAUSED}"
)

cherry_pick_branch = get_current_branch()
Expand Down Expand Up @@ -628,7 +638,8 @@ def continue_cherry_pick(self):

else:
click.echo(
f"Current branch ({cherry_pick_branch}) is not a backport branch. Will not continue. \U0001F61B"
f"Current branch ({cherry_pick_branch}) is not a backport branch. "
"Will not continue. \U0001F61B"
)
set_state(WORKFLOW_STATES.CONTINUATION_FAILED)

Expand All @@ -640,8 +651,8 @@ def check_repo(self):
"""
Check that the repository is for the project we're configured to operate on.
This function performs the check by making sure that the sha specified in the config
is present in the repository that we're operating on.
This function performs the check by making sure that the sha specified in the
config is present in the repository that we're operating on.
"""
try:
validate_sha(self.config["check_sha"])
Expand Down Expand Up @@ -828,7 +839,8 @@ def get_base_branch(cherry_pick_branch):

if prefix != "backport":
raise ValueError(
'branch name is not prefixed with "backport-". Is this a cherry_picker branch?'
'branch name is not prefixed with "backport-". '
"Is this a cherry_picker branch?"
)

if not re.match("[0-9a-f]{7,40}", sha):
Expand Down Expand Up @@ -856,7 +868,8 @@ def validate_sha(sha):
subprocess.check_output(cmd, stderr=subprocess.STDOUT)
except subprocess.SubprocessError:
raise ValueError(
f"The sha listed in the branch name, {sha}, is not present in the repository"
f"The sha listed in the branch name, {sha}, "
"is not present in the repository"
)


Expand Down
11 changes: 7 additions & 4 deletions cherry_picker/test_cherry_picker.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,8 @@ def test_get_updated_commit_message_without_links_replacement(config):

@mock.patch("subprocess.check_output")
def test_is_cpython_repo(subprocess_check_output):
subprocess_check_output.return_value = """commit 7f777ed95a19224294949e1b4ce56bbffcb1fe9f
subprocess_check_output.return_value = """\
commit 7f777ed95a19224294949e1b4ce56bbffcb1fe9f
Author: Guido van Rossum <[email protected]>
Date: Thu Aug 9 14:25:15 1990 +0000
Expand Down Expand Up @@ -503,7 +504,8 @@ def test_load_config_no_head_sha(tmp_git_repo_dir, git_add, git_commit):


def test_normalize_long_commit_message():
commit_message = """[3.6] Fix broken `Show Source` links on documentation pages (GH-3113)
commit_message = """\
[3.6] Fix broken `Show Source` links on documentation pages (GH-3113)
The `Show Source` was broken because of a change made in sphinx 1.5.1
In Sphinx 1.4.9, the sourcename was "index.txt".
Expand All @@ -529,7 +531,8 @@ def test_normalize_long_commit_message():


def test_normalize_short_commit_message():
commit_message = """[3.6] Fix broken `Show Source` links on documentation pages (GH-3113)
commit_message = """\
[3.6] Fix broken `Show Source` links on documentation pages (GH-3113)
(cherry picked from commit b9ff498793611d1c6a9b99df464812931a1e2d69)
Expand Down Expand Up @@ -879,7 +882,7 @@ class tested_state:
with mock.patch(
"cherry_picker.cherry_picker.validate_sha", return_value=True
), pytest.raises(InvalidRepoException, match=expected_msg_regexp):
cherry_picker = CherryPicker("origin", "xxx", [])
CherryPicker("origin", "xxx", [])


def test_push_to_remote_fail(tmp_git_repo_dir):
Expand Down

0 comments on commit 035180e

Please sign in to comment.