Skip to content

Commit 91fbf61

Browse files
committed
scripts: set_assigner: fix python lint issues
Fix various issues detected by ruff and remove exclusion of file. Signed-off-by: Anas Nashif <anas.nashif@intel.com>
1 parent 7a36221 commit 91fbf61

File tree

2 files changed

+70
-63
lines changed

2 files changed

+70
-63
lines changed

.ruff-excludes.toml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -715,14 +715,6 @@
715715
"UP007", # https://docs.astral.sh/ruff/rules/non-pep604-annotation-union
716716
"UP035", # https://docs.astral.sh/ruff/rules/deprecated-import
717717
]
718-
"./scripts/set_assignees.py" = [
719-
"E402", # https://docs.astral.sh/ruff/rules/module-import-not-at-top-of-file
720-
"E501", # https://docs.astral.sh/ruff/rules/line-too-long
721-
"E741", # https://docs.astral.sh/ruff/rules/ambiguous-variable-name
722-
"F541", # https://docs.astral.sh/ruff/rules/f-string-missing-placeholders
723-
"I001", # https://docs.astral.sh/ruff/rules/unsorted-imports
724-
"SIM113", # https://docs.astral.sh/ruff/rules/enumerate-for-loop
725-
]
726718
"./scripts/snippets.py" = [
727719
"I001", # https://docs.astral.sh/ruff/rules/unsorted-imports
728720
"UP006", # https://docs.astral.sh/ruff/rules/non-pep585-annotation

scripts/set_assignees.py

Lines changed: 70 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -16,47 +16,62 @@
1616

1717
TOP_DIR = os.path.join(os.path.dirname(__file__))
1818
sys.path.insert(0, os.path.join(TOP_DIR, "scripts"))
19-
from get_maintainer import Maintainers
19+
from get_maintainer import Maintainers # noqa: E402
2020

2121
zephyr_base = os.getenv('ZEPHYR_BASE', os.path.join(TOP_DIR, '..'))
2222

23+
2324
def log(s):
2425
if args.verbose > 0:
2526
print(s, file=sys.stdout)
2627

28+
2729
def parse_args():
2830
global args
2931
parser = argparse.ArgumentParser(
3032
description=__doc__,
31-
formatter_class=argparse.RawDescriptionHelpFormatter, allow_abbrev=False)
32-
33-
parser.add_argument("-M", "--maintainer-file", required=False, default="MAINTAINERS.yml",
34-
help="Maintainer file to be used.")
33+
formatter_class=argparse.RawDescriptionHelpFormatter,
34+
allow_abbrev=False,
35+
)
36+
37+
parser.add_argument(
38+
"-M",
39+
"--maintainer-file",
40+
required=False,
41+
default="MAINTAINERS.yml",
42+
help="Maintainer file to be used.",
43+
)
3544

3645
group = parser.add_mutually_exclusive_group()
37-
group.add_argument("-P", "--pull_request", required=False, default=None, type=int,
38-
help="Operate on one pull-request only.")
39-
group.add_argument("-I", "--issue", required=False, default=None, type=int,
40-
help="Operate on one issue only.")
41-
group.add_argument("-s", "--since", required=False,
42-
help="Process pull-requests since date.")
43-
group.add_argument("-m", "--modules", action="store_true",
44-
help="Process pull-requests from modules.")
45-
46-
parser.add_argument("-y", "--dry-run", action="store_true", default=False,
47-
help="Dry run only.")
48-
49-
parser.add_argument("-o", "--org", default="zephyrproject-rtos",
50-
help="Github organisation")
51-
52-
parser.add_argument("-r", "--repo", default="zephyr",
53-
help="Github repository")
54-
55-
parser.add_argument( "--updated-manifest", default=None,
56-
help="Updated manifest file to compare against current west.yml")
57-
58-
parser.add_argument("-v", "--verbose", action="count", default=0,
59-
help="Verbose Output")
46+
group.add_argument(
47+
"-P",
48+
"--pull_request",
49+
required=False,
50+
default=None,
51+
type=int,
52+
help="Operate on one pull-request only.",
53+
)
54+
group.add_argument(
55+
"-I", "--issue", required=False, default=None, type=int, help="Operate on one issue only."
56+
)
57+
group.add_argument("-s", "--since", required=False, help="Process pull-requests since date.")
58+
group.add_argument(
59+
"-m", "--modules", action="store_true", help="Process pull-requests from modules."
60+
)
61+
62+
parser.add_argument("-y", "--dry-run", action="store_true", default=False, help="Dry run only.")
63+
64+
parser.add_argument("-o", "--org", default="zephyrproject-rtos", help="Github organisation")
65+
66+
parser.add_argument("-r", "--repo", default="zephyr", help="Github repository")
67+
68+
parser.add_argument(
69+
"--updated-manifest",
70+
default=None,
71+
help="Updated manifest file to compare against current west.yml",
72+
)
73+
74+
parser.add_argument("-v", "--verbose", action="count", default=0, help="Verbose Output")
6075

6176
args = parser.parse_args()
6277

@@ -71,11 +86,9 @@ def process_manifest(old_manifest_file):
7186
old_projs = set((p.name, p.revision) for p in old_manifest.projects)
7287
new_projs = set((p.name, p.revision) for p in new_manifest.projects)
7388
# Removed projects
74-
rprojs = set(filter(lambda p: p[0] not in list(p[0] for p in new_projs),
75-
old_projs - new_projs))
89+
rprojs = set(filter(lambda p: p[0] not in list(p[0] for p in new_projs), old_projs - new_projs))
7690
# Updated projects
77-
uprojs = set(filter(lambda p: p[0] in list(p[0] for p in old_projs),
78-
new_projs - old_projs))
91+
uprojs = set(filter(lambda p: p[0] in list(p[0] for p in old_projs), new_projs - old_projs))
7992
# Added projects
8093
aprojs = new_projs - old_projs - uprojs
8194

@@ -91,8 +104,8 @@ def process_manifest(old_manifest_file):
91104
log(f'manifest areas: {areas}')
92105
return areas
93106

94-
def process_pr(gh, maintainer_file, number):
95107

108+
def process_pr(gh, maintainer_file, number):
96109
gh_repo = gh.get_repo(f"{args.org}/{args.repo}")
97110
pr = gh_repo.get_pull(number)
98111

@@ -113,21 +126,16 @@ def process_pr(gh, maintainer_file, number):
113126
return
114127

115128
# areas where assignment happens if only area is affected
116-
meta_areas = [
117-
'Release Notes',
118-
'Documentation',
119-
'Samples'
120-
]
129+
meta_areas = ['Release Notes', 'Documentation', 'Samples']
121130

122131
for changed_file in fn:
123-
124132
num_files += 1
125133
log(f"file: {changed_file.filename}")
126134

127135
areas = []
128-
if changed_file.filename in ['west.yml','submanifests/optional.yaml']:
136+
if changed_file.filename in ['west.yml', 'submanifests/optional.yaml']:
129137
if not args.updated_manifest:
130-
log("No updated manifest file provided, cannot process west.yml changes, skipping...")
138+
log("No updated manifest, cannot process west.yml changes, skipping...")
131139
continue
132140
parsed_areas = process_manifest(old_manifest_file=args.updated_manifest)
133141
for _area in parsed_areas:
@@ -177,7 +185,9 @@ def process_pr(gh, maintainer_file, number):
177185
collab = list(dict.fromkeys(collab))
178186
log(f"collab: {collab}")
179187

180-
_all_maintainers = dict(sorted(found_maintainers.items(), key=lambda item: item[1], reverse=True))
188+
_all_maintainers = dict(
189+
sorted(found_maintainers.items(), key=lambda item: item[1], reverse=True)
190+
)
181191

182192
log(f"Submitted by: {pr.user.login}")
183193
log(f"candidate maintainers: {_all_maintainers}")
@@ -233,10 +243,10 @@ def process_pr(gh, maintainer_file, number):
233243
# Set labels
234244
if labels:
235245
if len(labels) < 10:
236-
for l in labels:
237-
log(f"adding label {l}...")
246+
for label in labels:
247+
log(f"adding label {label}...")
238248
if not args.dry_run:
239-
pr.add_to_labels(l)
249+
pr.add_to_labels(label)
240250
else:
241251
log("Too many labels to be applied")
242252

@@ -249,10 +259,8 @@ def process_pr(gh, maintainer_file, number):
249259
existing_reviewers.add(review.user)
250260

251261
rl = pr.get_review_requests()
252-
page = 0
253-
for r in rl:
262+
for page, r in enumerate(rl):
254263
existing_reviewers |= set(r.get_page(page))
255-
page += 1
256264

257265
# check for reviewers that remove themselves from list of reviewer and
258266
# do not attempt to add them again based on MAINTAINERS file.
@@ -280,8 +288,10 @@ def process_pr(gh, maintainer_file, number):
280288
reviewer_vacancy = 15 - len(existing_reviewers)
281289
reviewers = reviewers[:reviewer_vacancy]
282290
else:
283-
log("not adding reviewers because the existing reviewer count is greater than or "
284-
"equal to 15. Adding maintainers of all areas as reviewers instead.")
291+
log(
292+
"not adding reviewers because the existing reviewer count is greater than or "
293+
"equal to 15. Adding maintainers of all areas as reviewers instead."
294+
)
285295
# FIXME: Here we could also add collaborators of the areas most
286296
# affected, i.e. the one with the final assigne.
287297
reviewers = list(_all_maintainers.keys())
@@ -394,8 +404,8 @@ def process_modules(gh, maintainers_file):
394404
repos[repo_name] = maintainers_file.areas[area]
395405

396406
query = "is:open is:pr no:assignee"
397-
for repo in repos:
398-
query += f" repo:{repo}"
407+
if repos:
408+
query += ' ' + ' '.join(f"repo:{repo}" for repo in repos)
399409

400410
issues = gh.search_issues(query=query)
401411
for issue in issues:
@@ -428,8 +438,10 @@ def main():
428438

429439
token = os.environ.get('GITHUB_TOKEN', None)
430440
if not token:
431-
sys.exit('Github token not set in environment, please set the '
432-
'GITHUB_TOKEN environment variable and retry.')
441+
sys.exit(
442+
'Github token not set in environment, please set the '
443+
'GITHUB_TOKEN environment variable and retry.'
444+
)
433445

434446
gh = Github(token)
435447
maintainer_file = Maintainers(args.maintainer_file)
@@ -447,7 +459,10 @@ def main():
447459
today = datetime.date.today()
448460
since = today - datetime.timedelta(days=1)
449461

450-
common_prs = f'repo:{args.org}/{args.repo} is:open is:pr base:main -is:draft no:assignee created:>{since}'
462+
common_prs = (
463+
f'repo:{args.org}/{args.repo} is:open is:pr base:main '
464+
f'-is:draft no:assignee created:>{since}'
465+
)
451466
pulls = gh.search_issues(query=f'{common_prs}')
452467

453468
for issue in pulls:

0 commit comments

Comments
 (0)