|
| 1 | +import argparse |
| 2 | +import json |
| 3 | +import os |
| 4 | + |
| 5 | + |
| 6 | +def write_json(output_path: str, constant_path: str, unused_path: str) -> None: |
| 7 | + """ |
| 8 | + Dient zum Mergen von Unused-Dictionary und Constant-Dictionary und anschließende Erzeugen einer JSON - File, |
| 9 | + die das erzeugte Dictionary beinhaltet. |
| 10 | +
|
| 11 | + :param output_path: Dateipfad für Output-JSON aus beiden Dictionaries(Unused und Constant) |
| 12 | + :param constant_path: Dateipfad zur Constant Annotation File, die eine Constant Dictionary enthält |
| 13 | + :param unused_path: Dateipfad zur Unused Annotation File, die eine Unused Dictionary enthält |
| 14 | + """ |
| 15 | + # Platzhalter für echte Funktion |
| 16 | + # unused_dict = find_unused(unused_path) |
| 17 | + |
| 18 | + # entfernen, wenn Funktion aus Issue 433 fertig |
| 19 | + unused_dict = { |
| 20 | + "sklearn/sklearn.__check_build/raise_build_error": { |
| 21 | + "target": "sklearn/sklearn.__check_build/raise_build_error" |
| 22 | + } |
| 23 | + } |
| 24 | + # Platzhalter für echte Funktion |
| 25 | + # constant_dict = find_constant(constant_path) |
| 26 | + |
| 27 | + # entfernen, wenn Funktion aus Issue 434 fertig |
| 28 | + constant_dict = { |
| 29 | + "sklearn/sklearn._config/config_context/assume_finite": { |
| 30 | + "target": "sklearn/sklearn._config/config_context/assume_finite", |
| 31 | + "defaultType": "boolean", |
| 32 | + "defaultValue": True, |
| 33 | + }, |
| 34 | + "sklearn/sklearn._config/config_context/working_memory": { |
| 35 | + "target": "sklearn/sklearn._config/config_context/working_memory", |
| 36 | + "defaultType": "string", |
| 37 | + "defaultValue": "bla", |
| 38 | + }, |
| 39 | + "sklearn/sklearn._config/config_context/print_changed_only": { |
| 40 | + "target": "sklearn/sklearn._config/config_context/print_changed_only", |
| 41 | + "defaultType": "none", |
| 42 | + "defaultValue": None, |
| 43 | + }, |
| 44 | + "sklearn/sklearn._config/config_context/display": { |
| 45 | + "target": "sklearn/sklearn._config/config_context/display", |
| 46 | + "defaultType": "number", |
| 47 | + "defaultValue": "3", |
| 48 | + }, |
| 49 | + } |
| 50 | + result_dict = __combine_dictionaries(unused_dict, constant_dict) |
| 51 | + |
| 52 | + with open(os.path.join(output_path, "annotations.json"), "w") as file: |
| 53 | + json.dump( |
| 54 | + result_dict, |
| 55 | + file, |
| 56 | + indent=2, |
| 57 | + ) |
| 58 | + |
| 59 | + |
| 60 | +def __combine_dictionaries(unused_dict: dict, constant_dict: dict) -> dict: |
| 61 | + """ |
| 62 | + Funktion, die die Dictionaries kombiniert |
| 63 | + :param unused_dict : Dictionary der unused annotations |
| 64 | + :param constant_dict : Dictionary der constant annotations |
| 65 | + :return result_dict : Kombiniertes Dictionary |
| 66 | + """ |
| 67 | + |
| 68 | + result_dict = { |
| 69 | + "unused": unused_dict, |
| 70 | + "constant": constant_dict, |
| 71 | + } |
| 72 | + return result_dict |
| 73 | + |
| 74 | + |
| 75 | +# sollte, sobald final eingebunden wird entfernt werden, da es nicht weiter benötigt wird, dient zZ. nur zur Anschauung |
| 76 | +if __name__ == "__main__": |
| 77 | + parser = argparse.ArgumentParser(prog="combine") |
| 78 | + |
| 79 | + # Argument 1: outputPath |
| 80 | + parser.add_argument( |
| 81 | + "outputPath", |
| 82 | + metavar="output-filepath", |
| 83 | + type=str, |
| 84 | + help="paste the location of the output file in here ", |
| 85 | + ) |
| 86 | + # Argument 2: inputPath(Pfad einer Constant-Datei) |
| 87 | + parser.add_argument( |
| 88 | + "constantPath", |
| 89 | + metavar="input-filepath", |
| 90 | + type=str, |
| 91 | + help='paste the location of the "constant" file in here ', |
| 92 | + ) |
| 93 | + # Argument 3: inputPath(Pfad einer Unused-Datei) |
| 94 | + parser.add_argument( |
| 95 | + "unusedPath", |
| 96 | + metavar="input-filepath", |
| 97 | + type=str, |
| 98 | + help='paste the location of the "unused" file in here ', |
| 99 | + ) |
| 100 | + # Erzeuge kombinierte JSON-Datei jeweils aus der Constant- und der Unused-Dictionary |
| 101 | + args = parser.parse_args() # Argumente werden auf Nutzen als Parameter vorbereitet |
| 102 | + write_json(args.outputPath, args.constantPath, args.unusedPath) |
0 commit comments