Cleanup: reduce right-shift in Python scripts

Also place the return type on it's own line as it's easier to identify
when it's in a predictable location instead of the line ending.
This commit is contained in:
Campbell Barton 2024-02-28 11:02:54 +11:00
parent 44e64b8f29
commit 2e6739967e
3 changed files with 90 additions and 58 deletions

@ -285,7 +285,8 @@ def resolve_external_url(blender_url: str, repo_name: str) -> str:
def external_script_copy_old_submodule_over(
args: argparse.Namespace,
directory: Path,
old_submodules_dir: Path) -> None:
old_submodules_dir: Path,
) -> None:
blender_git_root = get_blender_git_root()
external_dir = blender_git_root / directory
@ -305,10 +306,12 @@ def external_script_copy_old_submodule_over(
call((args.git_command, "config", "--file", str(git_config), "--unset", "core.worktree"))
def floating_checkout_initialize_if_needed(args: argparse.Namespace,
repo_name: str,
directory: Path,
old_submodules_dir: Optional[Path] = None) -> None:
def floating_checkout_initialize_if_needed(
args: argparse.Namespace,
repo_name: str,
directory: Path,
old_submodules_dir: Optional[Path] = None,
) -> None:
"""Initialize checkout of an external repository"""
blender_git_root = get_blender_git_root()
@ -338,9 +341,11 @@ def floating_checkout_initialize_if_needed(args: argparse.Namespace,
call((args.git_command, "clone", "--origin", origin_name, external_url, str(external_dir)))
def floating_checkout_add_origin_if_needed(args: argparse.Namespace,
repo_name: str,
directory: Path) -> None:
def floating_checkout_add_origin_if_needed(
args: argparse.Namespace,
repo_name: str,
directory: Path,
) -> None:
"""
Add remote called 'origin' if there is a fork of the external repository available
@ -397,12 +402,14 @@ def floating_checkout_add_origin_if_needed(args: argparse.Namespace,
return
def floating_checkout_update(args: argparse.Namespace,
repo_name: str,
directory: Path,
branch: Optional[str],
old_submodules_dir: Optional[Path] = None,
only_update: bool = False) -> str:
def floating_checkout_update(
args: argparse.Namespace,
repo_name: str,
directory: Path,
branch: Optional[str],
old_submodules_dir: Optional[Path] = None,
only_update: bool = False,
) -> str:
"""Update a single external checkout with the given name in the scripts folder"""
blender_git_root = get_blender_git_root()
@ -479,26 +486,32 @@ def floating_checkout_update(args: argparse.Namespace,
return skip_msg
def external_scripts_update(args: argparse.Namespace,
repo_name: str,
directory_name: str,
branch: Optional[str]) -> str:
return floating_checkout_update(args,
repo_name,
Path("scripts") / directory_name,
branch,
old_submodules_dir=Path("release") / "scripts" / directory_name)
def external_scripts_update(
args: argparse.Namespace,
repo_name: str,
directory_name: str,
branch: Optional[str],
) -> str:
return floating_checkout_update(
args,
repo_name,
Path("scripts") / directory_name,
branch,
old_submodules_dir=Path("release") / "scripts" / directory_name,
)
def floating_libraries_update(args: argparse.Namespace, branch: Optional[str]) -> str:
"""Update libraries checkouts which are floating (not attached as Git submodules)"""
msg = ""
msg += floating_checkout_update(args,
"benchmarks",
Path("tests") / "benchmarks",
branch,
only_update=True)
msg += floating_checkout_update(
args,
"benchmarks",
Path("tests") / "benchmarks",
branch,
only_update=True,
)
return msg

@ -15,7 +15,11 @@ Example usage:
import argparse
import datetime
from gitea_utils import gitea_json_issues_search, gitea_json_issue_events_filter, git_username_detect
from gitea_utils import (
git_username_detect,
gitea_json_issue_events_filter,
gitea_json_issues_search,
)
def print_needing_info_urls(username: str, before: str) -> None:
@ -23,11 +27,13 @@ def print_needing_info_urls(username: str, before: str) -> None:
print(f"Needs information from user before {before}:")
label = "Status/Needs Information from User"
issues_json = gitea_json_issues_search(type="issues",
state="open",
before=before,
labels=label,
verbose=True)
issues_json = gitea_json_issues_search(
type="issues",
state="open",
before=before,
labels=label,
verbose=True,
)
for issue in issues_json:
fullname = issue["repository"]["full_name"]

@ -40,7 +40,8 @@ from typing import (
def argparse_create() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(
description="Generate Weekly Report",
epilog="This script is typically used to help write weekly reports")
epilog="This script is typically used to help write weekly reports",
)
parser.add_argument(
"--username",
@ -48,21 +49,26 @@ def argparse_create() -> argparse.ArgumentParser:
metavar='USERNAME',
type=str,
required=False,
help="")
help="",
)
parser.add_argument(
"--weeks-ago",
dest="weeks_ago",
type=int,
default=1,
help="Determine which week the report should be generated for. 0 means the current week. "
"The default is 1, to create a report for the previous week.")
help=(
"Determine which week the report should be generated for. 0 means the current week. "
"The default is 1, to create a report for the previous week."
),
)
parser.add_argument(
"-v",
"--verbose",
action="store_true",
help="increase output verbosity")
help="increase output verbosity",
)
return parser
@ -160,14 +166,17 @@ def report_personal_weekly_get(username: str, start: datetime.datetime, verbose:
print(f"[{int(100 * (process / len_total))}%] Checking issue {issue} ", end="\r", flush=True)
process += 1
issue_events = gitea_json_issue_events_filter(issue,
date_start=start,
date_end=date_end,
username=username,
labels={
"Status/Confirmed",
"Status/Needs Information from User",
"Status/Needs Info from Developers"})
issue_events = gitea_json_issue_events_filter(
issue,
date_start=start,
date_end=date_end,
username=username,
labels={
"Status/Confirmed",
"Status/Needs Information from User",
"Status/Needs Info from Developers"
}
)
for event in issue_events:
label_name = event["label"]["name"]
@ -182,12 +191,14 @@ def report_personal_weekly_get(username: str, start: datetime.datetime, verbose:
print(f"[{int(100 * (process / len_total))}%] Checking issue {issue} ", end="\r", flush=True)
process += 1
issue_events = gitea_json_issue_events_filter(issue,
date_start=start,
date_end=date_end,
username=username,
event_type={"close", "commit_ref"},
labels={"Status/Duplicate"})
issue_events = gitea_json_issue_events_filter(
issue,
date_start=start,
date_end=date_end,
username=username,
event_type={"close", "commit_ref"},
labels={"Status/Duplicate"},
)
for event in issue_events:
event_type = event["type"]
@ -202,11 +213,13 @@ def report_personal_weekly_get(username: str, start: datetime.datetime, verbose:
print(f"[{int(100 * (process / len_total))}%] Checking pull {pull} ", end="\r", flush=True)
process += 1
pull_events = gitea_json_issue_events_filter(pull.replace("pulls", "issues"),
date_start=start,
date_end=date_end,
username=username,
event_type={"comment"})
pull_events = gitea_json_issue_events_filter(
pull.replace("pulls", "issues"),
date_start=start,
date_end=date_end,
username=username,
event_type={"comment"},
)
if pull_events:
pull_data = gitea_json_issue_get_cached(pull)