Skip to content

Commit b49df6a

Browse files
authored
Ruff format. (#61)
1 parent 0917aa8 commit b49df6a

File tree

3 files changed

+35
-79
lines changed

3 files changed

+35
-79
lines changed

src/stack_pr/cli.py

Lines changed: 32 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,7 @@ def commit_id(self) -> str:
210210
return self._search_group(RE_RAW_COMMIT_ID, "commit")
211211

212212
def parents(self) -> List[str]:
213-
return [
214-
m.group("commit") for m in RE_RAW_PARENT.finditer(self.raw_header)
215-
]
213+
return [m.group("commit") for m in RE_RAW_PARENT.finditer(self.raw_header)]
216214

217215
def author(self) -> str:
218216
return self._search_group(RE_RAW_AUTHOR, "author")
@@ -225,8 +223,7 @@ def author_email(self) -> str:
225223

226224
def commit_msg(self) -> str:
227225
return "\n".join(
228-
m.group("line")
229-
for m in RE_RAW_COMMIT_MSG_LINE.finditer(self.raw_header)
226+
m.group("line") for m in RE_RAW_COMMIT_MSG_LINE.finditer(self.raw_header)
230227
)
231228

232229

@@ -437,9 +434,7 @@ def get_stack(base: str, head: str, verbose: bool) -> List[StackEntry]:
437434
st: List[StackEntry] = []
438435
stack = (
439436
split_header(
440-
get_command_output(
441-
["git", "rev-list", "--header", "^" + base, head]
442-
)
437+
get_command_output(["git", "rev-list", "--header", "^" + base, head])
443438
)
444439
)[::-1]
445440

@@ -506,7 +501,11 @@ def verify(st: List[StackEntry], check_base: bool = False):
506501
raise RuntimeError
507502

508503
# The first entry on the stack needs to be actually mergeable on GitHub.
509-
if check_base and index == 0 and d["mergeStateStatus"] not in ["CLEAN", "UNKNOWN", "UNSTABLE"]:
504+
if (
505+
check_base
506+
and index == 0
507+
and d["mergeStateStatus"] not in ["CLEAN", "UNKNOWN", "UNSTABLE"]
508+
):
510509
error(ERROR_STACKINFO_PR_NOT_MERGEABLE.format(**locals()))
511510
raise RuntimeError
512511

@@ -529,9 +528,7 @@ def draft_bitmask_type(value: str) -> List[bool]:
529528
# ===----------------------------------------------------------------------=== #
530529
# SUBMIT
531530
# ===----------------------------------------------------------------------=== #
532-
def add_or_update_metadata(
533-
e: StackEntry, needs_rebase: bool, verbose: bool
534-
) -> bool:
531+
def add_or_update_metadata(e: StackEntry, needs_rebase: bool, verbose: bool) -> bool:
535532
if needs_rebase:
536533
run_shell_command(
537534
[
@@ -631,14 +628,14 @@ def push_branches(st: List[StackEntry], remote, verbose: bool):
631628

632629
def print_cmd_failure_details(exc: SubprocessError):
633630
cmd_stdout = (
634-
exc.stdout.decode("utf-8")
635-
.replace("\\n", "\n")
636-
.replace("\\t", "\t") if exc.stdout else None
631+
exc.stdout.decode("utf-8").replace("\\n", "\n").replace("\\t", "\t")
632+
if exc.stdout
633+
else None
637634
)
638635
cmd_stderr = (
639-
exc.stderr.decode("utf-8")
640-
.replace("\\n", "\n")
641-
.replace("\\t", "\t") if exc.stderr else None
636+
exc.stderr.decode("utf-8").replace("\\n", "\n").replace("\\t", "\t")
637+
if exc.stderr
638+
else None
642639
)
643640
print(f"Exitcode: {exc.returncode}")
644641
print(f"Stdout: {cmd_stdout}")
@@ -716,9 +713,7 @@ def add_cross_links(st: List[StackEntry], keep_body: bool, verbose: bool):
716713
if keep_body:
717714
# Keep current body of the PR after the cross links component
718715
current_pr_body = get_current_pr_body(e)
719-
pr_body.append(
720-
current_pr_body.split(CROSS_LINKS_DELIMETER, 1)[-1].lstrip()
721-
)
716+
pr_body.append(current_pr_body.split(CROSS_LINKS_DELIMETER, 1)[-1].lstrip())
722717
else:
723718
pr_body.extend(
724719
[
@@ -758,15 +753,11 @@ def add_cross_links(st: List[StackEntry], keep_body: bool, verbose: bool):
758753
#
759754
# To avoid this, we temporarily set all base branches to point to 'main' - once
760755
# all the branches are pushed we can set the actual base branches.
761-
def reset_remote_base_branches(
762-
st: List[StackEntry], target: str, verbose: bool
763-
):
756+
def reset_remote_base_branches(st: List[StackEntry], target: str, verbose: bool):
764757
log(h("Resetting remote base branches"), level=1)
765758

766759
for e in filter(lambda e: e.has_pr(), st):
767-
run_shell_command(
768-
["gh", "pr", "edit", e.pr, "-B", target], quiet=not verbose
769-
)
760+
run_shell_command(["gh", "pr", "edit", e.pr, "-B", target], quiet=not verbose)
770761

771762

772763
# If local 'main' lags behind 'origin/main', and 'head' contains all commits
@@ -794,9 +785,7 @@ def should_update_local_base(
794785

795786
def update_local_base(base: str, remote: str, target: str, verbose: bool):
796787
log(h(f"Updating local branch {base} to {remote}/{target}"), level=1)
797-
run_shell_command(
798-
["git", "rebase", f"{remote}/{target}", base], quiet=not verbose
799-
)
788+
run_shell_command(["git", "rebase", f"{remote}/{target}", base], quiet=not verbose)
800789

801790

802791
class CommonArgs(NamedTuple):
@@ -882,9 +871,7 @@ def command_submit(
882871
args.head, args.base, args.remote, args.target, args.verbose
883872
):
884873
update_local_base(args.base, args.remote, args.target, args.verbose)
885-
run_shell_command(
886-
["git", "checkout", current_branch], quiet=not args.verbose
887-
)
874+
run_shell_command(["git", "checkout", current_branch], quiet=not args.verbose)
888875

889876
# Determine what commits belong to the stack
890877
st = get_stack(args.base, args.head, args.verbose)
@@ -902,18 +889,14 @@ def command_submit(
902889

903890
# Create local branches and initialize base and head fields in the stack
904891
# elements
905-
init_local_branches(
906-
st, args.remote, args.verbose, args.branch_name_template
907-
)
892+
init_local_branches(st, args.remote, args.verbose, args.branch_name_template)
908893
set_base_branches(st, args.target)
909894
print_stack(st, args.hyperlinks)
910895

911896
# If the current branch contains commits from the stack, we will need to
912897
# rebase it in the end since the commits will be modified.
913898
top_branch = st[-1].head
914-
need_to_rebase_current = is_ancestor(
915-
top_branch, current_branch, args.verbose
916-
)
899+
need_to_rebase_current = is_ancestor(top_branch, current_branch, args.verbose)
917900

918901
reset_remote_base_branches(st, args.target, args.verbose)
919902

@@ -923,9 +906,7 @@ def command_submit(
923906
# Now we have all the branches, so we can create the corresponding PRs
924907
log(h("Submitting PRs"), level=1)
925908
for e_idx, e in enumerate(st):
926-
is_pr_draft = draft or (
927-
(draft_bitmask is not None) and draft_bitmask[e_idx]
928-
)
909+
is_pr_draft = draft or ((draft_bitmask is not None) and draft_bitmask[e_idx])
929910
create_pr(e, is_pr_draft, reviewer)
930911

931912
# Verify consistency in everything we have so far
@@ -960,9 +941,7 @@ def command_submit(
960941
)
961942
else:
962943
log(h(f"Checking out the original branch '{current_branch}'"), level=1)
963-
run_shell_command(
964-
["git", "checkout", current_branch], quiet=not args.verbose
965-
)
944+
run_shell_command(["git", "checkout", current_branch], quiet=not args.verbose)
966945

967946
delete_local_branches(st, args.verbose)
968947
print_tips_after_export(st, args)
@@ -1012,9 +991,7 @@ def land_pr(e: StackEntry, remote: str, target: str, verbose: bool):
1012991
raise
1013992

1014993
# Switch PR base branch to 'main'
1015-
run_shell_command(
1016-
["gh", "pr", "edit", e.pr, "-B", target], quiet=not verbose
1017-
)
994+
run_shell_command(["gh", "pr", "edit", e.pr, "-B", target], quiet=not verbose)
1018995

1019996
# Form the commit message: it should contain the original commit message
1020997
# and nothing else.
@@ -1077,9 +1054,7 @@ def command_land(args: CommonArgs):
10771054
args.head, args.base, args.remote, args.target, args.verbose
10781055
):
10791056
update_local_base(args.base, args.remote, args.target, args.verbose)
1080-
run_shell_command(
1081-
["git", "checkout", current_branch], quiet=not args.verbose
1082-
)
1057+
run_shell_command(["git", "checkout", current_branch], quiet=not args.verbose)
10831058

10841059
# Determine what commits belong to the stack
10851060
st = get_stack(args.base, args.head, args.verbose)
@@ -1114,9 +1089,7 @@ def command_land(args: CommonArgs):
11141089
)
11151090

11161091
# Delete local and remote stack branches
1117-
run_shell_command(
1118-
["git", "checkout", current_branch], quiet=not args.verbose
1119-
)
1092+
run_shell_command(["git", "checkout", current_branch], quiet=not args.verbose)
11201093

11211094
delete_local_branches(st, args.verbose)
11221095

@@ -1166,9 +1139,7 @@ def command_abandon(args: CommonArgs):
11661139
return
11671140
current_branch = get_current_branch_name()
11681141

1169-
init_local_branches(
1170-
st, args.remote, args.verbose, args.branch_name_template
1171-
)
1142+
init_local_branches(st, args.remote, args.verbose, args.branch_name_template)
11721143
set_base_branches(st, args.target)
11731144
print_stack(st, args.hyperlinks)
11741145

@@ -1184,9 +1155,7 @@ def command_abandon(args: CommonArgs):
11841155
)
11851156

11861157
delete_local_branches(st, args.verbose)
1187-
delete_remote_branches(
1188-
st, args.remote, args.verbose, args.branch_name_template
1189-
)
1158+
delete_remote_branches(st, args.remote, args.verbose, args.branch_name_template)
11901159
log(h(blue("SUCCESS!")), level=1)
11911160

11921161

@@ -1235,10 +1204,7 @@ def command_view(args: CommonArgs):
12351204
level=1,
12361205
)
12371206
log(
1238-
(
1239-
"Consider updating your local branch by"
1240-
" running the following commands:"
1241-
),
1207+
("Consider updating your local branch by running the following commands:"),
12421208
level=1,
12431209
)
12441210
log(
@@ -1279,9 +1245,7 @@ def create_argparser(
12791245
help="Remote name",
12801246
)
12811247
common_parser.add_argument("-B", "--base", help="Local base branch")
1282-
common_parser.add_argument(
1283-
"-H", "--head", default="HEAD", help="Local head branch"
1284-
)
1248+
common_parser.add_argument("-H", "--head", default="HEAD", help="Local head branch")
12851249
common_parser.add_argument(
12861250
"-T",
12871251
"--target",
@@ -1303,9 +1267,7 @@ def create_argparser(
13031267
)
13041268
common_parser.add_argument(
13051269
"--branch-name-template",
1306-
default=config.get(
1307-
"repo", "branch_name_template", fallback="$USERNAME/stack"
1308-
),
1270+
default=config.get("repo", "branch_name_template", fallback="$USERNAME/stack"),
13091271
help="A template for names of the branches stack-pr would use.",
13101272
)
13111273

src/stack_pr/git.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ def fetch_checkout_commit(
2626
run_shell_command(
2727
["git", "fetch", "--depth=1", remote, ref], cwd=repo_dir, quiet=quiet
2828
)
29-
run_shell_command(
30-
["git", "checkout", "FETCH_HEAD"], cwd=repo_dir, quiet=quiet
31-
)
29+
run_shell_command(["git", "checkout", "FETCH_HEAD"], cwd=repo_dir, quiet=quiet)
3230

3331

3432
def is_full_git_sha(s: str) -> bool:

src/stack_pr/shell_commands.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@ def run_shell_command(
3434
_ = subprocess.list2cmdline(cmd)
3535
kwargs.update({"check": check})
3636
if quiet:
37-
kwargs.update(
38-
{"stdout": subprocess.DEVNULL, "stderr": subprocess.DEVNULL}
39-
)
37+
kwargs.update({"stdout": subprocess.DEVNULL, "stderr": subprocess.DEVNULL})
4038
if SHOW_COMMANDS:
4139
print(f"Running: {cmd}")
4240
return subprocess.run(list(map(str, cmd)), **kwargs)
@@ -57,8 +55,6 @@ def get_command_output(cmd: ShellCommand, **kwargs: Any) -> str:
5755
ValueError: if the capture_output keyword argument is specified.
5856
"""
5957
if "capture_output" in kwargs:
60-
raise ValueError(
61-
"Cannot pass capture_output when using get_command_output"
62-
)
58+
raise ValueError("Cannot pass capture_output when using get_command_output")
6359
proc = run_shell_command(cmd, capture_output=True, quiet=False, **kwargs)
6460
return proc.stdout.decode("utf-8").rstrip()

0 commit comments

Comments
 (0)