(bytecode_class: BytecodeClass)
| 596 | |
| 597 | |
| 598 | def generate_bytecode_description_string(bytecode_class: BytecodeClass) -> str: |
| 599 | # examples: |
| 600 | # f3f05dc would have the description: "removed `SYNC` and `SLAVE` tokens" |
| 601 | # 506df14 would have the description: "removed `decimals` function" |
| 602 | # a7aad78 would have the description: "added `deep_equal` function" |
| 603 | # d6b31da would have the description: "added `PUPPET` token, token `SLAVESYNC` renamed to `PUPPETSYNC`" |
| 604 | |
| 605 | description: str = "" |
| 606 | |
| 607 | def add_to_desc(format_str: str, listarg: list[str]) -> None: |
| 608 | nonlocal description |
| 609 | if len(description) > 0: |
| 610 | description += ", " |
| 611 | description += format_str.format("`, `".join(listarg)) |
| 612 | if len(listarg) > 1: |
| 613 | description += "s" |
| 614 | |
| 615 | if len(bytecode_class.added_tokens) > 0: |
| 616 | # make a new list with all the added_tokens with the prefixes "TK_PR_", "TK_CF_", and "TK_" removed |
| 617 | new_added_tokens = [ |
| 618 | token.replace("TK_PR_", "").replace("TK_CF_", "").replace("TK_", "") |
| 619 | for token in bytecode_class.added_tokens |
| 620 | ] |
| 621 | |
| 622 | add_to_desc("added `{}` token", new_added_tokens) |
| 623 | if len(bytecode_class.removed_tokens) > 0: |
| 624 | new_removed_tokens = [ |
| 625 | token.replace("TK_PR_", "").replace("TK_CF_", "").replace("TK_", "") |
| 626 | for token in bytecode_class.removed_tokens |
| 627 | ] |
| 628 | add_to_desc("removed `{}` token", new_removed_tokens) |
| 629 | if len(bytecode_class.added_functions) > 0: |
| 630 | add_to_desc("added `{}` function", bytecode_class.added_functions) |
| 631 | if len(bytecode_class.removed_functions) > 0: |
| 632 | add_to_desc("removed `{}` function", bytecode_class.removed_functions) |
| 633 | if len(bytecode_class.arg_count_changed) > 0: |
| 634 | add_to_desc("changed argument count for `{}` function", bytecode_class.arg_count_changed) |
| 635 | if len(bytecode_class.renamed_functions) > 0: |
| 636 | for dict_key, dict_val in bytecode_class.renamed_functions.items(): |
| 637 | fmt_insert = "{} to {}".format(dict_key, dict_val) |
| 638 | add_to_desc("renamed function {}", [fmt_insert]) |
| 639 | if len(bytecode_class.tokens_renamed) > 0: |
| 640 | for dict_key, dict_val in bytecode_class.tokens_renamed.items(): |
| 641 | fmt_insert = "`{}` to `{}`".format( |
| 642 | dict_key.replace("TK_PR_", "").replace("TK_CF_", "").replace("TK_", ""), |
| 643 | dict_val.replace("TK_PR_", "").replace("TK_CF_", "").replace("TK_", ""), |
| 644 | ) |
| 645 | add_to_desc("renamed token {}", [fmt_insert]) |
| 646 | if len(description) == 0: |
| 647 | if bytecode_class.bytecode_version == 100: |
| 648 | return "initial version" |
| 649 | elif bytecode_class.bytecode_version == 101: |
| 650 | return "content header size changed" |
| 651 | else: |
| 652 | return "bytecode version changed" |
| 653 | return description[0].upper() + description[1:] + "." |
| 654 | |
| 655 |
no test coverage detected