diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000..e19c0a5 --- /dev/null +++ b/.flake8 @@ -0,0 +1,3 @@ +[flake8] +extend-ignore = E203 +max-line-length = 88 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 9475e71..3f04ef5 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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 diff --git a/cherry_picker/cherry_picker.py b/cherry_picker/cherry_picker.py index 8ab3f7f..5422496 100755 --- a/cherry_picker/cherry_picker.py +++ b/cherry_picker/cherry_picker.py @@ -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) @@ -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: @@ -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 """ @@ -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: @@ -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() @@ -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) @@ -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"]) @@ -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): @@ -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" ) diff --git a/cherry_picker/test_cherry_picker.py b/cherry_picker/test_cherry_picker.py index 8049a8e..bffb11d 100644 --- a/cherry_picker/test_cherry_picker.py +++ b/cherry_picker/test_cherry_picker.py @@ -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 Date: Thu Aug 9 14:25:15 1990 +0000 @@ -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". @@ -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) @@ -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):