Skip to content

Commit

Permalink
Upgrade markdown generation script, can now detect missing descriptio…
Browse files Browse the repository at this point in the history
…ns outside game
  • Loading branch information
embeddedt committed Jul 28, 2023
1 parent 13cc103 commit eee22d7
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ eclipse
run
libs
media
__pycache__
*.pyc
classes/
.architectury-transformer/
fabric/fabricloader.log
Expand Down
32 changes: 26 additions & 6 deletions scripts/gen-markdown-patchlist.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,46 @@
#!/usr/bin/python3

import json
import subprocess
import json, os, subprocess, sys
# to import other scripts in same folder
sys.path.append(os.path.dirname(os.path.realpath(__file__)))

from contextlib import redirect_stdout
from modernfixlib import get_valid_mixin_options

branch_name = subprocess.check_output(['git', 'branch', '--show-current']).decode("utf-8").strip()

with open('doc/generated/' + branch_name + '-Summary-of-Patches.md', 'w') as output_file:
all_current_mixin_options = get_valid_mixin_options()
options_missing_descriptions = set()
with redirect_stdout(output_file):
with open('common/src/main/resources/assets/modernfix/lang/en_us.json') as lang_json:
lang_obj = json.loads(lang_json.read())
option_names = []
option_names = set()
for key, value in lang_obj.items():
if key.startswith("modernfix.option.mixin."):
option_names.append(key.replace("modernfix.option.", ""))
option_names.sort()
option_names.add(key.replace("modernfix.option.", ""))
option_names_sorted = list(option_names)
option_names_sorted.sort()
print()
for option in option_names:
for option in option_names_sorted:
if option not in all_current_mixin_options:
continue
option_description = lang_obj.get("modernfix.option." + option)
option_friendly_name = lang_obj.get("modernfix.option.name." + option)
print(f"### `{option}`")
print()
if option_description is not None:
print(option_description)
print("")
else:
options_missing_descriptions.add(option)
options_missing_descriptions.update(all_current_mixin_options.difference(option_names))

# sort the list of missing descriptions and print them out if there are any
missing_descriptions_list = list(options_missing_descriptions)
missing_descriptions_list.sort()
num_missing = len(missing_descriptions_list)
if num_missing > 0:
print(f"Missing {num_missing} descriptions:")
for option in missing_descriptions_list:
print(f" - {option}")
22 changes: 22 additions & 0 deletions scripts/modernfixlib.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

import os
import re

def get_valid_mixin_options():
all_mixin_options = set()
# gather all mixins in mixin folders
for platform in [ "common", "fabric", "forge" ]:
base_path = f"{platform}/src/main/java/org/embeddedt/modernfix/{platform}/mixin"
for root, dirs, files in os.walk(base_path):
for file in files:
if file.endswith(".java"):
mixin_name = root.replace(base_path, "").replace(os.path.sep, ".")
if mixin_name.startswith("."):
mixin_name = mixin_name[1:]
all_mixin_options.add("mixin." + mixin_name)
# gather any mixin strings referenced in ModernFixEarlyConfig
with open('common/src/main/java/org/embeddedt/modernfix/core/config/ModernFixEarlyConfig.java') as config_java:
config_str = config_java.read()
for option in re.findall(r"\"(mixin(?:\.[a-z_]+)+)\"", config_str):
all_mixin_options.add(option)
return all_mixin_options

0 comments on commit eee22d7

Please sign in to comment.