Skip to content

Commit

Permalink
fix format and ignore E501
Browse files Browse the repository at this point in the history
  • Loading branch information
Czaki committed Jul 22, 2024
1 parent 5835116 commit c70e6a8
Show file tree
Hide file tree
Showing 12 changed files with 259 additions and 206 deletions.
42 changes: 26 additions & 16 deletions add_login_to_citation_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
This is a script for adding logins to the existing CITATION.cff file.
This simplifies future updating of this file. It creates a backup file with .bck suffix/
"""

from __future__ import annotations

import argparse
Expand All @@ -23,7 +24,7 @@
)

LOCAL_DIR = Path(__file__).parent
DEFAULT_CORRECTION_FILE = LOCAL_DIR / "name_corrections.yaml"
DEFAULT_CORRECTION_FILE = LOCAL_DIR / 'name_corrections.yaml'


def get_name(user, correction_dict):
Expand All @@ -36,10 +37,12 @@ def get_name(user, correction_dict):

def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("path", help="The path to the citation file to sort", type=Path)
parser.add_argument(
"--correction-file",
help="The file with the corrections",
'path', help='The path to the citation file to sort', type=Path
)
parser.add_argument(
'--correction-file',
help='The file with the corrections',
default=DEFAULT_CORRECTION_FILE,
type=existing_file,
)
Expand All @@ -51,7 +54,7 @@ def main():
def add_logins(cff_path: Path, correction_file: Path | None = None) -> None:
setup_cache()

with cff_path.open(encoding="utf8") as f:
with cff_path.open(encoding='utf8') as f:
data = safe_load(f)

contributors_iterable = get_repo().get_contributors()
Expand All @@ -62,30 +65,37 @@ def add_logins(cff_path: Path, correction_file: Path | None = None) -> None:

contributors = {
get_name(user, correction_dict): user
for user in tqdm(contributors_iterable, total=contributors_iterable.totalCount)
for user in tqdm(
contributors_iterable, total=contributors_iterable.totalCount
)
if get_name(user, correction_dict) is not None
}

for user in get_repo().get_contributors():
if get_name(user, correction_dict) is None and user.login not in BOT_LIST:
print(f"Could not find {user.login}", file=sys.stderr)
if (
get_name(user, correction_dict) is None
and user.login not in BOT_LIST
):
print(f'Could not find {user.login}', file=sys.stderr)

# assert len(contributors) == contributors_iterable.totalCount

for i, author in enumerate(data["authors"]):
if "alias" in author:
for i, author in enumerate(data['authors']):
if 'alias' in author:
continue
name = unidecode(f'{author["given-names"]} {author["family-names"]}'.lower())
name = unidecode(
f'{author["given-names"]} {author["family-names"]}'.lower()
)
if name in contributors:
author["alias"] = contributors[name].login
author['alias'] = contributors[name].login
else:
print(f"Could not find {name}", file=sys.stderr)
print(f'Could not find {name}', file=sys.stderr)

shutil.copy(str(cff_path), f"{cff_path}.bck")
shutil.copy(str(cff_path), f'{cff_path}.bck')

with cff_path.open("w", encoding="utf8") as f:
with cff_path.open('w', encoding='utf8') as f:
safe_dump(data, f, sort_keys=False, allow_unicode=True)


if __name__ == "__main__":
if __name__ == '__main__':
main()
62 changes: 37 additions & 25 deletions cherry_pick_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"""
This is script to cherry-pick commits base on PR labels
"""

from __future__ import annotations

import argparse
Expand All @@ -28,32 +29,38 @@

def main():
parser = argparse.ArgumentParser()
parser.add_argument("base_branch", help="The base branch.")
parser.add_argument("milestone", help="The milestone to list")
parser.add_argument('base_branch', help='The base branch.')
parser.add_argument('milestone', help='The milestone to list')
parser.add_argument(
'--first-commits',
help='file with list of first commits to cherry pick',
)
parser.add_argument(
"--first-commits", help="file with list of first commits to cherry pick"
'--stop-after', help='Stop after this PR', default=0, type=int
)
parser.add_argument("--stop-after", help="Stop after this PR", default=0, type=int)
parser.add_argument(
"--git-main-branch",
help="The git main branch",
default=os.environ.get("GIT_RELEASE_MAIN_BRANCH", "main"),
'--git-main-branch',
help='The git main branch',
default=os.environ.get('GIT_RELEASE_MAIN_BRANCH', 'main'),
)

parser.add_argument(
"--working-dir", help="path to repository", default=LOCAL_DIR, type=Path
'--working-dir',
help='path to repository',
default=LOCAL_DIR,
type=Path,
)
parser.add_argument(
"--skip-commits",
nargs="+",
help="list of commits to skip as they are already cherry-picked",
'--skip-commits',
nargs='+',
help='list of commits to skip as they are already cherry-picked',
type=int,
)

argcomplete.autocomplete(parser)
args = parser.parse_args()

target_branch = f"v{args.milestone}x"
target_branch = f'v{args.milestone}x'

if args.first_commits is not None:
with open(args.first_commits) as f:
Expand All @@ -74,18 +81,23 @@ def main():


def prepare_repo(
working_dir: Path, target_branch: str, base_branch: str, main_branch: str = "main"
working_dir: Path,
target_branch: str,
base_branch: str,
main_branch: str = 'main',
) -> Repo:
if not working_dir.exists():
repo = Repo.clone_from(f"git@{GH}:{GH_USER}/{GH_REPO}.git", working_dir)
repo = Repo.clone_from(
f'git@{GH}:{GH_USER}/{GH_REPO}.git', working_dir
)
else:
repo = Repo(LOCAL_DIR / REPO_DIR_NAME)

if target_branch not in repo.branches:
repo.git.checkout(base_branch)
repo.git.checkout("HEAD", b=target_branch)
repo.git.checkout('HEAD', b=target_branch)
else:
repo.git.reset("--hard", "HEAD")
repo.git.reset('--hard', 'HEAD')
repo.git.checkout(main_branch)
repo.git.pull()
repo.git.checkout(target_branch)
Expand All @@ -101,7 +113,7 @@ def perform_cherry_pick(
first_commits: set,
stop_after: int | None,
base_branch: str,
main_branch: str = "main",
main_branch: str = 'main',
skip_commits: list[int] = None,
):
"""
Expand Down Expand Up @@ -141,13 +153,13 @@ def perform_cherry_pick(
setup_cache()

milestone = get_milestone(milestone_str)
patch_dir_path = working_dir / "patch_dir" / milestone.title
patch_dir_path = working_dir / 'patch_dir' / milestone.title
patch_dir_path.mkdir(parents=True, exist_ok=True)

# with short_cache(60):
pr_targeted_for_release = [
x
for x in iter_pull_request(f"milestone:{milestone.title} is:merged")
for x in iter_pull_request(f'milestone:{milestone.title} is:merged')
if x.milestone == milestone
]

Expand Down Expand Up @@ -187,20 +199,20 @@ def perform_cherry_pick(
# commit = repo.commit(pr_commits_dict[pull.number])
# print("hash", pr_commits_dict[pull.number])
# break
patch_file = patch_dir_path / f"{pull.number}.patch"
patch_file = patch_dir_path / f'{pull.number}.patch'
if patch_file.exists():
print(f"Apply patch {patch_file}")
print(f'Apply patch {patch_file}')
repo.git.am(str(patch_file))
continue
try:
repo.git.cherry_pick(pr_commits_dict[pull.number])
except GitCommandError:
print(pull, pr_commits_dict[pull.number])
repo.git.mergetool()
repo.git.cherry_pick("--continue")
with open(patch_file, "w") as f:
f.write(repo.git.format_patch("HEAD~1", "--stdout"))
repo.git.cherry_pick('--continue')
with open(patch_file, 'w') as f:
f.write(repo.git.format_patch('HEAD~1', '--stdout'))


if __name__ == "__main__":
if __name__ == '__main__':
main()
40 changes: 22 additions & 18 deletions docs_cherry_pick.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,36 @@
)

parser = argparse.ArgumentParser()
parser.add_argument("milestone", help="The milestone to list")
parser.add_argument('milestone', help='The milestone to list')
parser.add_argument(
"--first-commits", help="file with list of first commits to cherry pick"
'--first-commits', help='file with list of first commits to cherry pick'
)
parser.add_argument("--stop-after", help="Stop after this commit", default=0, type=int)
parser.add_argument(
"--git-repository",
help="The git repository",
'--stop-after', help='Stop after this commit', default=0, type=int
)
parser.add_argument(
'--git-repository',
help='The git repository',
default=os.environ.get(
"GIT_RELEASE_REPOSITORY", "git@github.com:napari/napari.git"
'GIT_RELEASE_REPOSITORY', 'git@github.com:napari/napari.git'
),
)

parser.add_argument(
"--git-main-branch",
help="The git main branch",
default=os.environ.get("GIT_RELEASE_MAIN_BRANCH", "main"),
'--git-main-branch',
help='The git main branch',
default=os.environ.get('GIT_RELEASE_MAIN_BRANCH', 'main'),
)


def get_consumed_pr():
res = set()

base = repo.merge_base(f"docs_{milestone.title}", f"v{milestone.title}x")
base = repo.merge_base(f'docs_{milestone.title}', f'v{milestone.title}x')

for commit in repo.iter_commits(f"{base[0].binsha.hex()}..docs_{milestone.title}"):
for commit in repo.iter_commits(
f'{base[0].binsha.hex()}..docs_{milestone.title}'
):
if (match := PR_NUM_PATTERN.search(commit.message)) is not None:
pr_num = int(match[1])
res.add(pr_num)
Expand All @@ -59,36 +63,36 @@ def get_consumed_pr():

milestone = get_milestone(args.milestone)

if not (LOCAL_DIR / "patch_dir").exists():
(LOCAL_DIR / "patch_dir").mkdir()
if not (LOCAL_DIR / 'patch_dir').exists():
(LOCAL_DIR / 'patch_dir').mkdir()

patch_dir_path = LOCAL_DIR / "patch_dir" / f"docs_{milestone.title}"
patch_dir_path = LOCAL_DIR / 'patch_dir' / f'docs_{milestone.title}'

if not patch_dir_path.exists():
patch_dir_path.mkdir()


repo = Repo(LOCAL_DIR / REPO_DIR_NAME)
repo.git.checkout(f"docs_{milestone.title}")
repo.git.checkout(f'docs_{milestone.title}')


pr_list_base = sorted(
iter_pull_request(f"milestone:{args.milestone} is:merged", repo="docs"),
iter_pull_request(f'milestone:{args.milestone} is:merged', repo='docs'),
key=lambda x: x.closed_at,
)

skip_pr = {58, 106, 149, 151, 181, 175} | get_consumed_pr()


for pull in tqdm(pr_list_base):
patch_file = patch_dir_path / f"{pull.number}.patch"
patch_file = patch_dir_path / f'{pull.number}.patch'
if pull.number in skip_pr:
continue

print(pull.number, pull.title)
if not patch_file.exists():
urllib.request.urlretrieve(
f"https://github.com/napari/docs/commit/{pull.merge_commit_sha}.patch",
f'https://github.com/napari/docs/commit/{pull.merge_commit_sha}.patch',
patch_file,
)
repo.git.am(str(patch_file))
Loading

0 comments on commit c70e6a8

Please sign in to comment.