Skip to content

Commit 459a97b

Browse files
committed
Linting fixes.
1 parent 036bbb4 commit 459a97b

17 files changed

+136
-108
lines changed

.flake8

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[flake8]
2+
max-line-length = 88
3+
ignore = E203, W503

.pre-commit-config.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ repos:
33
rev: 6.0.0
44
hooks:
55
- id: flake8
6+
exclude: ^tests/
67
- repo: https://github.com/psf/black
78
rev: 22.12.0
89
hooks:

gitbark/bark_core/parents/invalid_parents.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ def validate_invalid_parents(
5050
invalid_parents = []
5151

5252
for parent in parents:
53-
if not cache.get(parent.hash).valid:
53+
value = cache.get(parent.hash)
54+
if value and not value.valid:
5455
invalid_parents.append(parent)
5556

5657
if len(invalid_parents) == 0:
@@ -59,6 +60,6 @@ def validate_invalid_parents(
5960
invalid_parent_hashes = [parent.hash for parent in invalid_parents]
6061
commit_msg = commit.get_commit_message()
6162
for hash in invalid_parent_hashes:
62-
if not hash in commit_msg:
63+
if hash not in commit_msg:
6364
return False
6465
return True

gitbark/bark_core/signatures/commands/add_approvals_cmd.py

+18-14
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
import re
2323
import sys
2424
import click
25+
import logging
26+
27+
logger = logging.getLogger(__name__)
2528

2629

2730
@click.command()
@@ -31,7 +34,7 @@ def add_approvals(ctx, commit_msg_file):
3134
"""
3235
Include approvals in a merge commit message.
3336
34-
NOTE: This command should only be invoked as part of a
37+
NOTE: This command should only be invoked as part of a
3538
prepare-commit-msg hook.
3639
3740
\b
@@ -44,37 +47,38 @@ def add_approvals(ctx, commit_msg_file):
4447
try:
4548
merge_head_hash = repo.revparse_single("MERGE_HEAD").id.__str__()
4649
merge_head = Commit(merge_head_hash)
47-
except:
50+
except Exception:
4851
return
49-
52+
5053
head = Commit(repo.revparse_single("HEAD").id)
5154
threshold = get_approval_threshold(head)
5255
if not threshold:
5356
return
54-
57+
5558
approvals = get_approvals(merge_head, project)
5659
if len(approvals) < threshold:
5760
raise CliFail(
58-
f"Found {len(approvals)} approvals for {merge_head.hash} but expected {threshold}."
61+
f"Found {len(approvals)} approvals for {merge_head.hash} "
62+
"but expected {threshold}."
5963
)
60-
64+
6165
click.echo(f"Found {len(approvals)} approvals for {merge_head.hash}!")
6266
sys.stdin = open("/dev/tty", "r")
6367
click.confirm(
6468
"Do you want to include them in the merge commit message?",
6569
abort=True,
66-
err=True
70+
err=True,
6771
)
6872
write_approvals_to_commit_msg(
69-
approvals,
70-
commit_msg_file,
71-
project.project_path,
72-
merge_head
73+
approvals, commit_msg_file, project.project_path, merge_head
7374
)
7475

7576

7677
def write_approvals_to_commit_msg(
77-
approvals: list[str], commit_msg_file: str, project_path: str, merge_head: Commit
78+
approvals: list[str],
79+
commit_msg_file: str,
80+
project_path: str,
81+
merge_head: Commit,
7882
):
7983
with open(f"{project_path}/{commit_msg_file}", "w") as f:
8084
f.write("\n" * 2)
@@ -101,8 +105,8 @@ def get_approvals(merge_head: Commit, project):
101105
# Try to fetch approvals from remote
102106
try:
103107
cmd("git", "origin", "fetch", "refs/signatures/*:refs/signatures/*")
104-
except:
105-
pass
108+
except Exception:
109+
logger.error("Failed to fetch from 'refs/signatures'")
106110

107111
references = repo.references.iterator()
108112
approvals = []

gitbark/bark_core/signatures/commands/approve_cmd.py

+7-15
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import os
2323
import click
2424

25+
2526
class KeyType(Enum):
2627
GPG = 1
2728
SSH = 2
@@ -44,32 +45,23 @@ def click_parse_commit(ctx, param, val):
4445
except Exception:
4546
raise CliFail(f"{val} is not a valid commit object!")
4647

48+
4749
@click.command()
4850
@click.pass_context
4951
@click.argument("commit", default="HEAD", callback=click_parse_commit)
50-
@click.option(
51-
"--gpg-key-id",
52-
type=str,
53-
default="",
54-
help="The GPG key ID."
55-
)
52+
@click.option("--gpg-key-id", type=str, default="", help="The GPG key ID.")
5653
@click.option(
5754
"--ssh-key-path",
5855
type=str,
5956
default="",
60-
help="The path to your private SSH key."
57+
help="The path to your private SSH key.",
6158
)
62-
def approve(
63-
ctx,
64-
commit,
65-
gpg_key_id,
66-
ssh_key_path
67-
):
59+
def approve(ctx, commit, gpg_key_id, ssh_key_path):
6860
"""Add your signature to a commit.
6961
70-
This will create a signature over a given commit object, that
62+
This will create a signature over a given commit object, that
7163
is stored under `refs/signatures`.
72-
64+
7365
\b
7466
COMMIT the commit to sign.
7567
"""

gitbark/bark_core/signatures/require_approval.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,18 @@ def validate(self, commit: Commit) -> bool:
3838

3939
def require_approval(commit: Commit, threshold: int, authorized_pubkeys: list[Pubkey]):
4040
"""
41-
Verifies that the parent from the merged branch contains a threshold of approvals. These approvals are detached signatures
42-
included in the merge commit message.
41+
Verifies that the parent from the merged branch contains a threshold of approvals.
42+
These approvals are detached signatures included in the merge commit message.
4343
44-
Note: The second parent of a merge request will always be the parent of the merged branch.
44+
Note: The second parent of a merge request will always be the parent
45+
of the merged branch.
4546
"""
4647
parents = commit.get_parents()
4748
violation = ""
4849

4950
if len(parents) <= 1:
5051
# Require approval can only be applied on pull requests
51-
violation = f"Commit does not originate from a pull request"
52+
violation = "Commit does not originate from a pull request"
5253
return False, violation
5354

5455
# The merge head

gitbark/bark_core/signatures/require_signature.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def require_signature(commit: Commit, authorized_pubkeys: list[Pubkey]):
3636

3737
if not signature:
3838
# No signature
39-
violation = f"Commit was not signed"
39+
violation = "Commit was not signed"
4040
return False, violation
4141

4242
if len(authorized_pubkeys) == 0:

gitbark/bark_core/signatures/util.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ def _parse_pubkey(self, pubkey: str) -> Union[PGPKey, PKey]:
1818
key, _ = PGPKey.from_blob(pubkey)
1919
fingerprint = str(key.fingerprint)
2020
return key, fingerprint
21-
except:
21+
except Exception:
2222
pass
2323
try:
2424
key = PKey(data=pubkey)
2525
fingerprint = key.fingerprint.split(":")[1]
26-
except:
26+
except Exception:
2727
pass
2828
raise ValueError("Could not parse public key!")
2929

@@ -45,7 +45,7 @@ def verify_pgp_signature(pubkey: PGPKey, signature: Any, subject: Any) -> bool:
4545
return True
4646
else:
4747
return False
48-
except:
48+
except Exception:
4949
return False
5050

5151

gitbark/cli/__main__.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
CliFail,
2626
handle_exit,
2727
get_root,
28-
_add_subcommands
28+
_add_subcommands,
2929
)
3030

3131
from typing import Optional
@@ -79,7 +79,6 @@ def install(ctx):
7979

8080
if report.is_repo_valid():
8181
click.echo("Installed GitBark successfully!")
82-
8382

8483
handle_exit(report)
8584

@@ -168,7 +167,6 @@ def verify(ctx, branch, ref_update, all, bootstrap):
168167
if not is_installed(project):
169168
click.echo('Error: Bark is not installed! Run "bark install" first!')
170169
exit(1)
171-
# store = ctx.obj["store"]
172170

173171
head = None
174172
if not all:
@@ -185,8 +183,6 @@ def verify(ctx, branch, ref_update, all, bootstrap):
185183
elif not ref_update:
186184
click.echo(f"{branch} is in a valid state!")
187185

188-
# store.update_project(project)
189-
190186
handle_exit(report)
191187

192188

gitbark/cli/util.py

+11-7
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ def inner(ctx, param, val):
7777

7878
return wrap
7979

80+
8081
def get_root() -> str:
8182
try:
8283
root = os.path.abspath(cmd("git", "rev-parse", "--show-toplevel")[0])
@@ -85,19 +86,20 @@ def get_root() -> str:
8586
"Failed to find Git repository! Make sure "
8687
"you are not inside the .git directory."
8788
)
88-
89+
8990
return root
9091

92+
9193
def _add_subcommands(group: click.Group):
9294
try:
9395
toplevel = get_root()
9496
project = Project(toplevel)
9597
globals.init(toplevel)
9698
if not is_installed(project):
9799
return
98-
except:
100+
except Exception:
99101
return
100-
102+
101103
bark_rules = get_bark_rules(project)
102104
subcommand_entrypoints = project.get_subcommand_entrypoints(bark_rules)
103105
for entrypoint in subcommand_entrypoints:
@@ -107,23 +109,25 @@ def _add_subcommands(group: click.Group):
107109
group.add_command(ep.resolve())
108110
except Exception as e:
109111
raise e
110-
111-
112+
113+
112114
def verify_bootstrap(project: Project):
113115
repo = project.repo
114116
if not repo.lookup_branch("branch_rules"):
115117
raise CliFail('Error: The "branch_rules" branch has not been created!')
116118

119+
117120
def is_local_branch(branch: str):
118121
return branch.startswith("refs/heads")
119122

123+
120124
def restore_incoming_changes():
121125
try:
122126
cmd("git", "restore", "--staged", ".")
123127
cmd("git", "restore", ".")
124-
except:
128+
except Exception:
125129
pass
126-
130+
127131

128132
def handle_exit(report: Report):
129133
exit_status = 0

gitbark/commands/verify.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ def verify(
8181
) -> Report:
8282
"""Verifies a branch or the entire repository.
8383
84-
If `all` is set, the entire repository will be validated. Otherwise `branch` will be validated.
84+
If `all` is set, the entire repository will be validated. Otherwise
85+
`branch` will be validated.
8586
"""
8687
report = Report()
8788

0 commit comments

Comments
 (0)