Merge pull request #16867 from miri64/dist/enh/use-fstrings-where-warned
dist/tools: use f-strings where possible
This commit is contained in:
commit
f93d1276b4
64
dist/tools/backport_pr/backport_pr.py
vendored
64
dist/tools/backport_pr/backport_pr.py
vendored
@ -101,11 +101,11 @@ def _get_latest_release(branches):
|
|||||||
|
|
||||||
def _find_remote(repo, user, repo_name):
|
def _find_remote(repo, user, repo_name):
|
||||||
for remote in repo.remotes:
|
for remote in repo.remotes:
|
||||||
if (remote.url.endswith("{}/{}.git".format(user, repo_name)) or
|
if (remote.url.endswith(f"{user}/{repo_name}.git") or
|
||||||
remote.url.endswith("{}/{}".format(user, repo_name))):
|
remote.url.endswith(f"{user}/{repo_name}")):
|
||||||
return remote
|
return remote
|
||||||
raise ValueError("Could not find remote with URL ending in {}/{}.git"
|
raise ValueError("Could not find remote with URL ending in "
|
||||||
.format(user, repo_name))
|
f"{user}/{repo_name}.git")
|
||||||
|
|
||||||
|
|
||||||
def _get_upstream(repo):
|
def _get_upstream(repo):
|
||||||
@ -150,7 +150,7 @@ def main():
|
|||||||
# TODO: exception handling
|
# TODO: exception handling
|
||||||
status, user = github_api.user.get()
|
status, user = github_api.user.get()
|
||||||
if status != 200:
|
if status != 200:
|
||||||
print("Could not retrieve user: {}".format(user['message']))
|
print(f'Could not retrieve user: {user["message"]}')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
# Token-scope-check: Is the token is powerful enough to complete
|
# Token-scope-check: Is the token is powerful enough to complete
|
||||||
# the Backport?
|
# the Backport?
|
||||||
@ -169,21 +169,19 @@ def main():
|
|||||||
username = user['login']
|
username = user['login']
|
||||||
status, pulldata = github_api.repos[ORG][REPO].pulls[args.PR].get()
|
status, pulldata = github_api.repos[ORG][REPO].pulls[args.PR].get()
|
||||||
if status != 200:
|
if status != 200:
|
||||||
print("Commit #{} not found: {}".format(args.PR, pulldata['message']))
|
print(f'Commit #{args.PR} not found: {pulldata["message"]}')
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
if not pulldata['merged']:
|
if not pulldata['merged']:
|
||||||
print("Original PR not yet merged")
|
print("Original PR not yet merged")
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
print("Fetching for commit: #{}: {}".format(args.PR, pulldata['title']))
|
print(f'Fetching for commit: #{args.PR}: {pulldata["title"]}')
|
||||||
orig_branch = pulldata['head']['ref']
|
orig_branch = pulldata['head']['ref']
|
||||||
status, commits = github_api.repos[ORG][REPO].pulls[args.PR].commits.get()
|
status, commits = github_api.repos[ORG][REPO].pulls[args.PR].commits.get()
|
||||||
if status != 200:
|
if status != 200:
|
||||||
print("No commits found for #{}: {}".format(args.PR,
|
print(f'No commits found for #{args.PR}: {commits["message"]}')
|
||||||
commits['message']))
|
|
||||||
sys.exit(3)
|
sys.exit(3)
|
||||||
for commit in commits:
|
for commit in commits:
|
||||||
print("found {} : {}".format(commit['sha'],
|
print(f'found {commit["sha"]} : {commit["commit"]["message"]}')
|
||||||
commit['commit']['message']))
|
|
||||||
|
|
||||||
# Find latest release branch
|
# Find latest release branch
|
||||||
if args.release_branch:
|
if args.release_branch:
|
||||||
@ -192,16 +190,14 @@ def main():
|
|||||||
else:
|
else:
|
||||||
status, branches = github_api.repos[ORG][REPO].branches.get()
|
status, branches = github_api.repos[ORG][REPO].branches.get()
|
||||||
if status != 200:
|
if status != 200:
|
||||||
print("Could not retrieve branches for {}/{}: {}"
|
print(f'Could not retrieve branches for {ORG}/{REPO}: '
|
||||||
.format(ORG,
|
f'{branches["message"]}')
|
||||||
REPO,
|
|
||||||
branches['message']))
|
|
||||||
sys.exit(4)
|
sys.exit(4)
|
||||||
release_shortname, release_fullname = _get_latest_release(branches)
|
release_shortname, release_fullname = _get_latest_release(branches)
|
||||||
if not release_fullname:
|
if not release_fullname:
|
||||||
print("No release branch found, exiting")
|
print("No release branch found, exiting")
|
||||||
sys.exit(5)
|
sys.exit(5)
|
||||||
print("Backport based on branch {}".format(release_fullname))
|
print(f"Backport based on branch {release_fullname}")
|
||||||
|
|
||||||
repo = git.Repo(args.gitdir)
|
repo = git.Repo(args.gitdir)
|
||||||
# Fetch current upstream
|
# Fetch current upstream
|
||||||
@ -209,20 +205,20 @@ def main():
|
|||||||
if not upstream_remote:
|
if not upstream_remote:
|
||||||
print("No upstream remote found, can't fetch")
|
print("No upstream remote found, can't fetch")
|
||||||
sys.exit(6)
|
sys.exit(6)
|
||||||
print("Fetching {} remote".format(upstream_remote))
|
print(f"Fetching {upstream_remote} remote")
|
||||||
|
|
||||||
upstream_remote.fetch()
|
upstream_remote.fetch()
|
||||||
# Build topic branch in temp dir
|
# Build topic branch in temp dir
|
||||||
new_branch = args.backport_branch_fmt.format(release=release_shortname,
|
new_branch = args.backport_branch_fmt.format(release=release_shortname,
|
||||||
origbranch=orig_branch)
|
origbranch=orig_branch)
|
||||||
if new_branch in repo.branches:
|
if new_branch in repo.branches:
|
||||||
print("ERROR: Branch {} already exists".format(new_branch))
|
print(f"ERROR: Branch {new_branch} already exists")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
worktree_dir = os.path.join(args.gitdir, WORKTREE_SUBDIR)
|
worktree_dir = os.path.join(args.gitdir, WORKTREE_SUBDIR)
|
||||||
repo.git.worktree("add", "-b",
|
repo.git.worktree("add", "-b",
|
||||||
new_branch,
|
new_branch,
|
||||||
WORKTREE_SUBDIR,
|
WORKTREE_SUBDIR,
|
||||||
"{}/{}".format(upstream_remote, release_fullname))
|
f"{upstream_remote}/{release_fullname}")
|
||||||
# transform branch name into Head object for later configuring
|
# transform branch name into Head object for later configuring
|
||||||
new_branch = repo.branches[new_branch]
|
new_branch = repo.branches[new_branch]
|
||||||
try:
|
try:
|
||||||
@ -232,13 +228,13 @@ def main():
|
|||||||
bp_repo.git.cherry_pick('-x', commit['sha'])
|
bp_repo.git.cherry_pick('-x', commit['sha'])
|
||||||
# Push to github
|
# Push to github
|
||||||
origin = _find_remote(repo, username, REPO)
|
origin = _find_remote(repo, username, REPO)
|
||||||
print("Pushing branch {} to {}".format(new_branch, origin))
|
print(f"Pushing branch {new_branch} to {origin}")
|
||||||
if not args.noop:
|
if not args.noop:
|
||||||
push_info = origin.push('{0}:{0}'.format(new_branch))
|
push_info = origin.push(f"{new_branch}:{new_branch}")
|
||||||
new_branch.set_tracking_branch(push_info[0].remote_ref)
|
new_branch.set_tracking_branch(push_info[0].remote_ref)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
# Delete worktree
|
# Delete worktree
|
||||||
print("Pruning temporary workdir at {}".format(worktree_dir))
|
print(f"Pruning temporary workdir at {worktree_dir}")
|
||||||
_delete_worktree(repo, worktree_dir)
|
_delete_worktree(repo, worktree_dir)
|
||||||
# also delete branch created by worktree; this is only possible after
|
# also delete branch created by worktree; this is only possible after
|
||||||
# the worktree was deleted
|
# the worktree was deleted
|
||||||
@ -246,7 +242,7 @@ def main():
|
|||||||
raise exc
|
raise exc
|
||||||
else:
|
else:
|
||||||
# Delete worktree
|
# Delete worktree
|
||||||
print("Pruning temporary workdir at {}".format(worktree_dir))
|
print(f"Pruning temporary workdir at {worktree_dir}")
|
||||||
_delete_worktree(repo, worktree_dir)
|
_delete_worktree(repo, worktree_dir)
|
||||||
|
|
||||||
labels = _get_labels(pulldata)
|
labels = _get_labels(pulldata)
|
||||||
@ -254,22 +250,19 @@ def main():
|
|||||||
if not args.noop:
|
if not args.noop:
|
||||||
# Open new PR on github
|
# Open new PR on github
|
||||||
pull_request = {
|
pull_request = {
|
||||||
'title': "{} [backport {}]".format(pulldata['title'],
|
'title': f'{pulldata["title"]} [backport {release_shortname}]',
|
||||||
release_shortname),
|
'head': f'{username}:{new_branch}',
|
||||||
'head': '{}:{}'.format(username, new_branch),
|
|
||||||
'base': release_fullname,
|
'base': release_fullname,
|
||||||
'body': "# Backport of #{}\n\n{}".format(args.PR,
|
'body': f'# Backport of #{args.PR}\n\n{pulldata["body"]}',
|
||||||
pulldata['body']),
|
|
||||||
'maintainer_can_modify': True,
|
'maintainer_can_modify': True,
|
||||||
}
|
}
|
||||||
status, new_pr = github_api.repos[ORG][REPO].pulls.post(
|
status, new_pr = github_api.repos[ORG][REPO].pulls.post(
|
||||||
body=pull_request)
|
body=pull_request)
|
||||||
if status != 201:
|
if status != 201:
|
||||||
print("Error creating the new pr: \"{}\". Is \"Public Repo\""
|
print(f'Error creating the new pr: "{new_pr["message"]}". '
|
||||||
" access enabled for the token"
|
'Is "Public Repo" access enabled for the token?')
|
||||||
.format(new_pr['message']))
|
|
||||||
pr_number = new_pr['number']
|
pr_number = new_pr['number']
|
||||||
print("Create PR number #{} for backport".format(pr_number))
|
print(f"Create PR number #{pr_number} for backport")
|
||||||
github_api.repos[ORG][REPO].issues[pr_number].labels.post(body=labels)
|
github_api.repos[ORG][REPO].issues[pr_number].labels.post(body=labels)
|
||||||
review_request = {"reviewers": [merger]}
|
review_request = {"reviewers": [merger]}
|
||||||
github_api.repos[ORG][REPO].pulls[pr_number].\
|
github_api.repos[ORG][REPO].pulls[pr_number].\
|
||||||
@ -277,13 +270,12 @@ def main():
|
|||||||
|
|
||||||
# Put commit under old PR
|
# Put commit under old PR
|
||||||
if args.comment and not args.noop:
|
if args.comment and not args.noop:
|
||||||
comment = {"body": "Backport provided in #{}".format(pr_number)}
|
comment = {"body": f"Backport provided in #{pr_number}"}
|
||||||
status, res = github_api.repos[ORG][REPO].\
|
status, res = github_api.repos[ORG][REPO].\
|
||||||
issues[args.PR].comments.post(body=comment)
|
issues[args.PR].comments.post(body=comment)
|
||||||
if status != 201:
|
if status != 201:
|
||||||
print("Something went wrong adding the comment: {}"
|
print(f'Something went wrong adding the comment: {res["message"]}')
|
||||||
.format(res['message']))
|
print(f"Added comment to #{args.PR}")
|
||||||
print("Added comment to #{}".format(args.PR))
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
@ -182,10 +182,10 @@ def check_is_board(riotdir, board):
|
|||||||
:returns: board name
|
:returns: board name
|
||||||
"""
|
"""
|
||||||
if board == 'common':
|
if board == 'common':
|
||||||
raise ValueError("'%s' is not a board" % board)
|
raise ValueError(f"'{board}' is not a board")
|
||||||
board_dir = os.path.join(riotdir, 'boards', board)
|
board_dir = os.path.join(riotdir, 'boards', board)
|
||||||
if not os.path.isdir(board_dir):
|
if not os.path.isdir(board_dir):
|
||||||
raise ValueError("Cannot find '%s' in %s/boards" % (board, riotdir))
|
raise ValueError(f"Cannot find '{board}' in {riotdir}/boards")
|
||||||
return board
|
return board
|
||||||
|
|
||||||
|
|
||||||
@ -254,7 +254,7 @@ class RIOTApplication():
|
|||||||
logging.basicConfig(stream=self.log_stream)
|
logging.basicConfig(stream=self.log_stream)
|
||||||
else:
|
else:
|
||||||
self.testcase = None
|
self.testcase = None
|
||||||
self.logger = logging.getLogger('%s.%s' % (board, appdir))
|
self.logger = logging.getLogger(f'{board}.{appdir}')
|
||||||
|
|
||||||
# Currently not handling absolute directories or outside of RIOT
|
# Currently not handling absolute directories or outside of RIOT
|
||||||
assert is_in_directory(self.resultdir, resultdir), \
|
assert is_in_directory(self.resultdir, resultdir), \
|
||||||
@ -392,7 +392,7 @@ class RIOTApplication():
|
|||||||
create_directory(self.resultdir, clean=True)
|
create_directory(self.resultdir, clean=True)
|
||||||
self._skip(
|
self._skip(
|
||||||
'disabled_has_no_tests',
|
'disabled_has_no_tests',
|
||||||
"{} has no tests".format(self.appdir)
|
f"{self.appdir} has no tests"
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -422,7 +422,7 @@ class RIOTApplication():
|
|||||||
else:
|
else:
|
||||||
self._skip(
|
self._skip(
|
||||||
'skip.no_test',
|
'skip.no_test',
|
||||||
"{} has no tests".format(self.appdir)
|
f"{self.appdir} has no tests"
|
||||||
)
|
)
|
||||||
|
|
||||||
self.logger.info('Success')
|
self.logger.info('Success')
|
||||||
@ -479,7 +479,7 @@ class RIOTApplication():
|
|||||||
|
|
||||||
# Run setup-tasks, output is only kept in case of error
|
# Run setup-tasks, output is only kept in case of error
|
||||||
for taskname, taskargs in setuptasks.items():
|
for taskname, taskargs in setuptasks.items():
|
||||||
taskname = '%s.%s' % (name, taskname)
|
taskname = f'{name}.{taskname}'
|
||||||
self.logger.info('Run %s', taskname)
|
self.logger.info('Run %s', taskname)
|
||||||
try:
|
try:
|
||||||
self.make(taskargs)
|
self.make(taskargs)
|
||||||
@ -503,7 +503,7 @@ class RIOTApplication():
|
|||||||
Returns `output` if it is there, None if not.
|
Returns `output` if it is there, None if not.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
with open(self._outfile('%s.success' % name),
|
with open(self._outfile(f'{name}.success'),
|
||||||
encoding='utf-8') as outputfd:
|
encoding='utf-8') as outputfd:
|
||||||
self.logger.info('Nothing to be done for %s', name)
|
self.logger.info('Nothing to be done for %s', name)
|
||||||
return outputfd.read()
|
return outputfd.read()
|
||||||
@ -515,7 +515,7 @@ class RIOTApplication():
|
|||||||
"""Handle exception during make step `name`."""
|
"""Handle exception during make step `name`."""
|
||||||
output = ' '.join(err.cmd) + '\n'
|
output = ' '.join(err.cmd) + '\n'
|
||||||
output += err.output + '\n'
|
output += err.output + '\n'
|
||||||
output += 'Return value: %s\n' % err.returncode
|
output += f'Return value: {err.returncode}\n'
|
||||||
outfile = self._write_resultfile(name, 'failed', output)
|
outfile = self._write_resultfile(name, 'failed', output)
|
||||||
|
|
||||||
self.logger.warning(output)
|
self.logger.warning(output)
|
||||||
@ -523,10 +523,10 @@ class RIOTApplication():
|
|||||||
if self.testcase:
|
if self.testcase:
|
||||||
self.testcase.stderr += err.output + '\n'
|
self.testcase.stderr += err.output + '\n'
|
||||||
if name == "test":
|
if name == "test":
|
||||||
self.testcase.add_failure_info("{} failed".format(err.cmd),
|
self.testcase.add_failure_info(f"{err.cmd} failed",
|
||||||
err.output)
|
err.output)
|
||||||
else:
|
else:
|
||||||
self.testcase.add_error_info("{} had an error".format(err.cmd),
|
self.testcase.add_error_info(f"{err.cmd} had an error",
|
||||||
err.output)
|
err.output)
|
||||||
raise ErrorInTest(name, self, outfile)
|
raise ErrorInTest(name, self, outfile)
|
||||||
|
|
||||||
@ -537,7 +537,7 @@ class RIOTApplication():
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
# Delete previous status files
|
# Delete previous status files
|
||||||
resultfiles = glob.glob(self._outfile('%s.*' % name))
|
resultfiles = glob.glob(self._outfile(f'{name}.*'))
|
||||||
for resultfile in resultfiles:
|
for resultfile in resultfiles:
|
||||||
try:
|
try:
|
||||||
os.remove(resultfile)
|
os.remove(resultfile)
|
||||||
@ -545,7 +545,7 @@ class RIOTApplication():
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
# Create new file
|
# Create new file
|
||||||
filename = '%s.%s' % (name, status)
|
filename = f'{name}.{status}'
|
||||||
outfile = self._outfile(filename)
|
outfile = self._outfile(filename)
|
||||||
|
|
||||||
with open(outfile, 'w+', encoding='utf-8',
|
with open(outfile, 'w+', encoding='utf-8',
|
||||||
@ -595,9 +595,9 @@ def _test_failed_summary(errors, relpathstart=None):
|
|||||||
|
|
||||||
summary = ''
|
summary = ''
|
||||||
for step, errs in sorted(errors_dict.items()):
|
for step, errs in sorted(errors_dict.items()):
|
||||||
summary += 'Failures during %s:\n' % step
|
summary += f'Failures during {step}:\n'
|
||||||
for appdir, errorfile in errs:
|
for appdir, errorfile in errs:
|
||||||
summary += '- [%s](%s)\n' % (appdir, errorfile)
|
summary += f'- [{appdir}]({errorfile})\n'
|
||||||
# Separate sections with a new line
|
# Separate sections with a new line
|
||||||
summary += '\n'
|
summary += '\n'
|
||||||
|
|
||||||
@ -755,7 +755,7 @@ def main(args):
|
|||||||
with open(report_file, "w+", encoding="utf-8") as report:
|
with open(report_file, "w+", encoding="utf-8") as report:
|
||||||
junit_xml.TestSuite.to_file(
|
junit_xml.TestSuite.to_file(
|
||||||
report,
|
report,
|
||||||
[junit_xml.TestSuite('compile_and_test_for_{}'.format(board),
|
[junit_xml.TestSuite(f'compile_and_test_for_{board}',
|
||||||
[app.testcase for app in applications])]
|
[app.testcase for app in applications])]
|
||||||
)
|
)
|
||||||
if num_errors:
|
if num_errors:
|
||||||
|
|||||||
@ -10,7 +10,7 @@ def test_help_message():
|
|||||||
script = 'compile_and_test_for_board.py'
|
script = 'compile_and_test_for_board.py'
|
||||||
|
|
||||||
# Read the help message from executing the script
|
# Read the help message from executing the script
|
||||||
help_bytes = subprocess.check_output(['./%s' % script, '--help'])
|
help_bytes = subprocess.check_output([f'./{script}', '--help'])
|
||||||
help_msg = help_bytes.decode('utf-8')
|
help_msg = help_bytes.decode('utf-8')
|
||||||
|
|
||||||
docstring = compile_and_test_for_board.__doc__
|
docstring = compile_and_test_for_board.__doc__
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user