mirror of
https://github.com/blender/blender-dev-tools.git
synced 2025-08-13 14:02:48 +00:00
code_clean: support passing in multiple edit arguments at once
Convenient for applying multiple common edits at once. The '--edit' argument has been renamed to '--edits'.
This commit is contained in:
@ -537,7 +537,7 @@ class edit_generators:
|
|||||||
"""
|
"""
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def edit_list_from_file(source: str, data: str, _shared_edit_data: Any) -> List[Edit]:
|
def edit_list_from_file(source: str, data: str, _shared_edit_data: Any) -> List[Edit]:
|
||||||
edits = []
|
edits: List[Edit] = []
|
||||||
|
|
||||||
# The user might exclude C++, if they forget, it is better not to operate on C.
|
# The user might exclude C++, if they forget, it is better not to operate on C.
|
||||||
if not source.lower().endswith((".h", ".c")):
|
if not source.lower().endswith((".h", ".c")):
|
||||||
@ -1343,7 +1343,7 @@ def wash_source_with_edits(
|
|||||||
def run_edits_on_directory(
|
def run_edits_on_directory(
|
||||||
build_dir: str,
|
build_dir: str,
|
||||||
regex_list: List[re.Pattern[str]],
|
regex_list: List[re.Pattern[str]],
|
||||||
edit_to_apply: str,
|
edits_to_apply: Sequence[str],
|
||||||
skip_test: bool = False,
|
skip_test: bool = False,
|
||||||
) -> int:
|
) -> int:
|
||||||
# currently only supports ninja or makefiles
|
# currently only supports ninja or makefiles
|
||||||
@ -1431,6 +1431,8 @@ def run_edits_on_directory(
|
|||||||
print(" ", c)
|
print(" ", c)
|
||||||
del args_orig_len
|
del args_orig_len
|
||||||
|
|
||||||
|
for i, edit_to_apply in enumerate(edits_to_apply):
|
||||||
|
print("Applying edit:", edit_to_apply, "({:d} of {:d})".format(i + 1, len(edits_to_apply)))
|
||||||
edit_generator_class = edit_class_from_id(edit_to_apply)
|
edit_generator_class = edit_class_from_id(edit_to_apply)
|
||||||
|
|
||||||
shared_edit_data = edit_generator_class.setup()
|
shared_edit_data = edit_generator_class.setup()
|
||||||
@ -1472,11 +1474,9 @@ def run_edits_on_directory(
|
|||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
def create_parser() -> argparse.ArgumentParser:
|
def create_parser(edits_all: Sequence[str]) -> argparse.ArgumentParser:
|
||||||
from textwrap import indent, dedent
|
from textwrap import indent, dedent
|
||||||
|
|
||||||
edits_all = edit_function_get_all()
|
|
||||||
|
|
||||||
# Create docstring for edits.
|
# Create docstring for edits.
|
||||||
edits_all_docs = []
|
edits_all_docs = []
|
||||||
for edit in edits_all:
|
for edit in edits_all:
|
||||||
@ -1503,10 +1503,12 @@ def create_parser() -> argparse.ArgumentParser:
|
|||||||
help="Match file paths against this expression",
|
help="Match file paths against this expression",
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--edit",
|
"--edits",
|
||||||
dest="edit",
|
dest="edits",
|
||||||
choices=edits_all,
|
help=(
|
||||||
help="Specify the edit preset to run.\n\n" + "\n".join(edits_all_docs) + "\n",
|
"Specify the edit preset to run.\n\n" +
|
||||||
|
"\n".join(edits_all_docs) + "\n"
|
||||||
|
"Multiple edits may be passed at once (comma separated, no spaces)."),
|
||||||
required=True,
|
required=True,
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
@ -1525,7 +1527,8 @@ def create_parser() -> argparse.ArgumentParser:
|
|||||||
|
|
||||||
|
|
||||||
def main() -> int:
|
def main() -> int:
|
||||||
parser = create_parser()
|
edits_all = edit_function_get_all()
|
||||||
|
parser = create_parser(edits_all)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
build_dir = args.build_dir
|
build_dir = args.build_dir
|
||||||
@ -1538,7 +1541,20 @@ def main() -> int:
|
|||||||
print(f"Error in expression: {expr}\n {ex}")
|
print(f"Error in expression: {expr}\n {ex}")
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
return run_edits_on_directory(build_dir, regex_list, args.edit, args.skip_test)
|
edits_all_from_args = args.edits.split(",")
|
||||||
|
if not edits_all_from_args:
|
||||||
|
print("Error, no '--edits' arguments given!")
|
||||||
|
return 1
|
||||||
|
|
||||||
|
for edit in edits_all_from_args:
|
||||||
|
if edit not in edits_all:
|
||||||
|
print("Error, unrecognized '--edits' argument '{:s}', expected a value in {{{:s}}}".format(
|
||||||
|
edit,
|
||||||
|
", ".join(edits_all),
|
||||||
|
))
|
||||||
|
return 1
|
||||||
|
|
||||||
|
return run_edits_on_directory(build_dir, regex_list, edits_all_from_args, args.skip_test)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
Reference in New Issue
Block a user