mirror of
https://github.com/espressif/esp-idf.git
synced 2026-05-05 12:25:03 +02:00
style: format python files with isort and double-quote-string-fixer
This commit is contained in:
@@ -24,8 +24,8 @@ import sys
|
||||
|
||||
from idf_ci_utils import IDF_PATH
|
||||
|
||||
CODEOWNERS_PATH = os.path.join(IDF_PATH, ".gitlab", "CODEOWNERS")
|
||||
CODEOWNER_GROUP_PREFIX = "@esp-idf-codeowners/"
|
||||
CODEOWNERS_PATH = os.path.join(IDF_PATH, '.gitlab', 'CODEOWNERS')
|
||||
CODEOWNER_GROUP_PREFIX = '@esp-idf-codeowners/'
|
||||
|
||||
|
||||
def get_all_files():
|
||||
@@ -33,7 +33,7 @@ def get_all_files():
|
||||
Get list of all file paths in the repository.
|
||||
"""
|
||||
# only split on newlines, since file names may contain spaces
|
||||
return subprocess.check_output(["git", "ls-files"], cwd=IDF_PATH).decode("utf-8").strip().split('\n')
|
||||
return subprocess.check_output(['git', 'ls-files'], cwd=IDF_PATH).decode('utf-8').strip().split('\n')
|
||||
|
||||
|
||||
def pattern_to_regex(pattern):
|
||||
@@ -93,7 +93,7 @@ def action_identify(args):
|
||||
with open(CODEOWNERS_PATH) as f:
|
||||
for line in f:
|
||||
line = line.strip()
|
||||
if not line or line.startswith("#"):
|
||||
if not line or line.startswith('#'):
|
||||
continue
|
||||
tokens = line.split()
|
||||
path_pattern = tokens[0]
|
||||
@@ -121,18 +121,18 @@ def action_ci_check(args):
|
||||
errors = []
|
||||
|
||||
def add_error(msg):
|
||||
errors.append("{}:{}: {}".format(CODEOWNERS_PATH, line_no, msg))
|
||||
errors.append('{}:{}: {}'.format(CODEOWNERS_PATH, line_no, msg))
|
||||
|
||||
all_files = get_all_files()
|
||||
prev_path_pattern = ""
|
||||
prev_path_pattern = ''
|
||||
with open(CODEOWNERS_PATH) as f:
|
||||
for line_no, line in enumerate(f, start=1):
|
||||
# Skip empty lines and comments
|
||||
line = line.strip()
|
||||
if line.startswith("# sort-order-reset"):
|
||||
prev_path_pattern = ""
|
||||
if line.startswith('# sort-order-reset'):
|
||||
prev_path_pattern = ''
|
||||
|
||||
if not line or line.startswith("#"):
|
||||
if not line or line.startswith('#'):
|
||||
continue
|
||||
|
||||
# Each line has a form of "<path> <owners>+"
|
||||
@@ -140,18 +140,18 @@ def action_ci_check(args):
|
||||
path_pattern = tokens[0]
|
||||
owners = tokens[1:]
|
||||
if not owners:
|
||||
add_error("no owners specified for {}".format(path_pattern))
|
||||
add_error('no owners specified for {}'.format(path_pattern))
|
||||
|
||||
# Check that the file is sorted by path patterns
|
||||
path_pattern_for_cmp = path_pattern.replace("-", "_") # ignore difference between _ and - for ordering
|
||||
path_pattern_for_cmp = path_pattern.replace('-', '_') # ignore difference between _ and - for ordering
|
||||
if prev_path_pattern and path_pattern_for_cmp < prev_path_pattern:
|
||||
add_error("file is not sorted: {} < {}".format(path_pattern_for_cmp, prev_path_pattern))
|
||||
add_error('file is not sorted: {} < {}'.format(path_pattern_for_cmp, prev_path_pattern))
|
||||
prev_path_pattern = path_pattern_for_cmp
|
||||
|
||||
# Check that the pattern matches at least one file
|
||||
files = files_by_pattern(all_files, path_pattern)
|
||||
if not files:
|
||||
add_error("no files matched by pattern {}".format(path_pattern))
|
||||
add_error('no files matched by pattern {}'.format(path_pattern))
|
||||
|
||||
for o in owners:
|
||||
# Sanity-check the owner group name
|
||||
@@ -159,9 +159,9 @@ def action_ci_check(args):
|
||||
add_error("owner {} doesn't start with {}".format(o, CODEOWNER_GROUP_PREFIX))
|
||||
|
||||
if not errors:
|
||||
print("No errors found.")
|
||||
print('No errors found.')
|
||||
else:
|
||||
print("Errors found!")
|
||||
print('Errors found!')
|
||||
for e in errors:
|
||||
print(e)
|
||||
raise SystemExit(1)
|
||||
@@ -169,29 +169,29 @@ def action_ci_check(args):
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(
|
||||
sys.argv[0], description="Internal helper script for working with the CODEOWNERS file."
|
||||
sys.argv[0], description='Internal helper script for working with the CODEOWNERS file.'
|
||||
)
|
||||
subparsers = parser.add_subparsers(dest="action")
|
||||
subparsers = parser.add_subparsers(dest='action')
|
||||
|
||||
identify = subparsers.add_parser(
|
||||
"identify",
|
||||
help="List the owners of the specified path within IDF."
|
||||
'identify',
|
||||
help='List the owners of the specified path within IDF.'
|
||||
"This command doesn't support files inside submodules, or files not added to git repository.",
|
||||
)
|
||||
identify.add_argument("path", help="Path of the file relative to the root of the repository")
|
||||
identify.add_argument('path', help='Path of the file relative to the root of the repository')
|
||||
|
||||
subparsers.add_parser(
|
||||
"ci-check",
|
||||
help="Check CODEOWNERS file: every line should match at least one file, sanity-check group names, "
|
||||
"check that the file is sorted by paths",
|
||||
'ci-check',
|
||||
help='Check CODEOWNERS file: every line should match at least one file, sanity-check group names, '
|
||||
'check that the file is sorted by paths',
|
||||
)
|
||||
|
||||
test_pattern = subparsers.add_parser(
|
||||
"test-pattern",
|
||||
help="Print files in the repository for a given CODEOWNERS pattern. Useful when adding new rules."
|
||||
'test-pattern',
|
||||
help='Print files in the repository for a given CODEOWNERS pattern. Useful when adding new rules.'
|
||||
)
|
||||
test_pattern.add_argument("--regex", action="store_true", help="Print the equivalent regular expression instead of the file list.")
|
||||
test_pattern.add_argument("pattern", help="Path pattern to get the list of files for")
|
||||
test_pattern.add_argument('--regex', action='store_true', help='Print the equivalent regular expression instead of the file list.')
|
||||
test_pattern.add_argument('pattern', help='Path pattern to get the list of files for')
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
@@ -199,10 +199,10 @@ def main():
|
||||
parser.print_help()
|
||||
parser.exit(1)
|
||||
|
||||
action_func_name = "action_" + args.action.replace("-", "_")
|
||||
action_func_name = 'action_' + args.action.replace('-', '_')
|
||||
action_func = globals()[action_func_name]
|
||||
action_func(args)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user