This repository was archived by the owner on Jan 19, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
feat: 436 create a json file that integrates the dictionaries from and #438
Merged
GideonKoenig
merged 25 commits into
main
from
436-create-a-json-file-that-integrates-the-dictionaries-from-and
Apr 21, 2022
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
a42e1cd
Added combine
nvollroth a50e008
Some changes in the combine methode
lukarade b2cccf5
Comments + Tests
nvollroth 59dbb35
style: apply automatic fixes of linters
nvollroth f1b1034
Added JSON test file
nvollroth 85f11a1
Merge branch '436-create-a-json-file-that-integrates-the-dictionaries…
nvollroth 81681cd
style: apply automatic fixes of linters
nvollroth 0b35412
Changed directory in test
nvollroth de6bd46
Merge branch '436-create-a-json-file-that-integrates-the-dictionaries…
nvollroth 9a6ff3b
Funktionalität extrahiert
nvollroth cc7a152
style: apply automatic fixes of linters
nvollroth d4a09fe
output path variable correction in combine file
1dbab86
Important comment in combine
3671dd3
style: apply automatic fixes of linters
DavidTen1 dfca7d3
Documentation in the combine files
d0d17e4
style: apply automatic fixes of linters
DavidTen1 73c4ea2
Merge branch 'main' into 436-create-a-json-file-that-integrates-the-d…
GideonKoenig 109905a
Datei gelöscht + Kommentare angepasst
nvollroth 07a658b
style: apply automatic fixes of linters
nvollroth 6b5a74d
Typisierung hinzugefügt
lukarade 662685f
style: apply automatic fixes of linters
lukarade 254fa15
Test import korrigiert
lukarade 6b5a4f2
Merge branch '436-create-a-json-file-that-integrates-the-dictionaries…
lukarade 956ff32
Merge branch 'main' into 436-create-a-json-file-that-integrates-the-d…
GideonKoenig 974923f
style: apply automatic fixes of linters
GideonKoenig File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
package-parser/package_parser/commands/generate_annotations/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
from ._combine import write_json | ||
from ._generate_annotations import generate_annotations |
102 changes: 102 additions & 0 deletions
102
package-parser/package_parser/commands/generate_annotations/_combine.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import argparse | ||
import json | ||
import os | ||
|
||
|
||
def write_json(output_path: str, constant_path: str, unused_path: str) -> None: | ||
""" | ||
Dient zum Mergen von Unused-Dictionary und Constant-Dictionary und anschließende Erzeugen einer JSON - File, | ||
die das erzeugte Dictionary beinhaltet. | ||
|
||
:param output_path: Dateipfad für Output-JSON aus beiden Dictionaries(Unused und Constant) | ||
:param constant_path: Dateipfad zur Constant Annotation File, die eine Constant Dictionary enthält | ||
:param unused_path: Dateipfad zur Unused Annotation File, die eine Unused Dictionary enthält | ||
""" | ||
# Platzhalter für echte Funktion | ||
# unused_dict = find_unused(unused_path) | ||
|
||
# entfernen, wenn Funktion aus Issue 433 fertig | ||
unused_dict = { | ||
"sklearn/sklearn.__check_build/raise_build_error": { | ||
"target": "sklearn/sklearn.__check_build/raise_build_error" | ||
} | ||
} | ||
# Platzhalter für echte Funktion | ||
# constant_dict = find_constant(constant_path) | ||
|
||
# entfernen, wenn Funktion aus Issue 434 fertig | ||
constant_dict = { | ||
"sklearn/sklearn._config/config_context/assume_finite": { | ||
"target": "sklearn/sklearn._config/config_context/assume_finite", | ||
"defaultType": "boolean", | ||
"defaultValue": True, | ||
}, | ||
"sklearn/sklearn._config/config_context/working_memory": { | ||
"target": "sklearn/sklearn._config/config_context/working_memory", | ||
"defaultType": "string", | ||
"defaultValue": "bla", | ||
}, | ||
"sklearn/sklearn._config/config_context/print_changed_only": { | ||
"target": "sklearn/sklearn._config/config_context/print_changed_only", | ||
"defaultType": "none", | ||
"defaultValue": None, | ||
}, | ||
"sklearn/sklearn._config/config_context/display": { | ||
"target": "sklearn/sklearn._config/config_context/display", | ||
"defaultType": "number", | ||
"defaultValue": "3", | ||
}, | ||
} | ||
result_dict = __combine_dictionaries(unused_dict, constant_dict) | ||
|
||
with open(os.path.join(output_path, "annotations.json"), "w") as file: | ||
json.dump( | ||
result_dict, | ||
file, | ||
indent=2, | ||
) | ||
|
||
|
||
def __combine_dictionaries(unused_dict: dict, constant_dict: dict) -> dict: | ||
""" | ||
Funktion, die die Dictionaries kombiniert | ||
:param unused_dict : Dictionary der unused annotations | ||
:param constant_dict : Dictionary der constant annotations | ||
:return result_dict : Kombiniertes Dictionary | ||
""" | ||
|
||
result_dict = { | ||
"unused": unused_dict, | ||
"constant": constant_dict, | ||
} | ||
return result_dict | ||
|
||
|
||
# sollte, sobald final eingebunden wird entfernt werden, da es nicht weiter benötigt wird, dient zZ. nur zur Anschauung | ||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser(prog="combine") | ||
|
||
# Argument 1: outputPath | ||
parser.add_argument( | ||
"outputPath", | ||
metavar="output-filepath", | ||
type=str, | ||
help="paste the location of the output file in here ", | ||
) | ||
# Argument 2: inputPath(Pfad einer Constant-Datei) | ||
parser.add_argument( | ||
"constantPath", | ||
metavar="input-filepath", | ||
type=str, | ||
help='paste the location of the "constant" file in here ', | ||
) | ||
# Argument 3: inputPath(Pfad einer Unused-Datei) | ||
parser.add_argument( | ||
"unusedPath", | ||
metavar="input-filepath", | ||
type=str, | ||
help='paste the location of the "unused" file in here ', | ||
) | ||
# Erzeuge kombinierte JSON-Datei jeweils aus der Constant- und der Unused-Dictionary | ||
args = parser.parse_args() # Argumente werden auf Nutzen als Parameter vorbereitet | ||
write_json(args.outputPath, args.constantPath, args.unusedPath) |
29 changes: 29 additions & 0 deletions
29
package-parser/tests/commands/generate_annotations/annotations.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"unused": { | ||
"sklearn/sklearn.__check_build/raise_build_error": { | ||
"target": "sklearn/sklearn.__check_build/raise_build_error" | ||
} | ||
}, | ||
"constant": { | ||
"sklearn/sklearn._config/config_context/assume_finite": { | ||
"target": "sklearn/sklearn._config/config_context/assume_finite", | ||
"defaultType": "boolean", | ||
"defaultValue": true | ||
}, | ||
"sklearn/sklearn._config/config_context/working_memory": { | ||
"target": "sklearn/sklearn._config/config_context/working_memory", | ||
"defaultType": "string", | ||
"defaultValue": "bla" | ||
}, | ||
"sklearn/sklearn._config/config_context/print_changed_only": { | ||
"target": "sklearn/sklearn._config/config_context/print_changed_only", | ||
"defaultType": "none", | ||
"defaultValue": null | ||
}, | ||
"sklearn/sklearn._config/config_context/display": { | ||
"target": "sklearn/sklearn._config/config_context/display", | ||
"defaultType": "number", | ||
"defaultValue": "3" | ||
} | ||
} | ||
} |
82 changes: 82 additions & 0 deletions
82
package-parser/tests/commands/generate_annotations/test_combine.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import json | ||
import os | ||
|
||
import package_parser.commands.generate_annotations._combine as comb | ||
import pytest | ||
|
||
test_unused_dict = { | ||
"sklearn/sklearn.__check_build/raise_build_error": { | ||
"target": "sklearn/sklearn.__check_build/raise_build_error" | ||
} | ||
} | ||
|
||
test_constant_dict = { | ||
"sklearn/sklearn._config/config_context/assume_finite": { | ||
"target": "sklearn/sklearn._config/config_context/assume_finite", | ||
"defaultType": "boolean", | ||
"defaultValue": True, | ||
}, | ||
"sklearn/sklearn._config/config_context/working_memory": { | ||
"target": "sklearn/sklearn._config/config_context/working_memory", | ||
"defaultType": "string", | ||
"defaultValue": "bla", | ||
}, | ||
"sklearn/sklearn._config/config_context/print_changed_only": { | ||
"target": "sklearn/sklearn._config/config_context/print_changed_only", | ||
"defaultType": "none", | ||
"defaultValue": None, | ||
}, | ||
"sklearn/sklearn._config/config_context/display": { | ||
"target": "sklearn/sklearn._config/config_context/display", | ||
"defaultType": "number", | ||
"defaultValue": "3", | ||
}, | ||
} | ||
|
||
test_combined_dict = { | ||
"unused": { | ||
"sklearn/sklearn.__check_build/raise_build_error": { | ||
"target": "sklearn/sklearn.__check_build/raise_build_error" | ||
} | ||
}, | ||
"constant": { | ||
"sklearn/sklearn._config/config_context/assume_finite": { | ||
"target": "sklearn/sklearn._config/config_context/assume_finite", | ||
"defaultType": "boolean", | ||
"defaultValue": True, | ||
}, | ||
"sklearn/sklearn._config/config_context/working_memory": { | ||
"target": "sklearn/sklearn._config/config_context/working_memory", | ||
"defaultType": "string", | ||
"defaultValue": "bla", | ||
}, | ||
"sklearn/sklearn._config/config_context/print_changed_only": { | ||
"target": "sklearn/sklearn._config/config_context/print_changed_only", | ||
"defaultType": "none", | ||
"defaultValue": None, | ||
}, | ||
"sklearn/sklearn._config/config_context/display": { | ||
"target": "sklearn/sklearn._config/config_context/display", | ||
"defaultType": "number", | ||
"defaultValue": "3", | ||
}, | ||
}, | ||
} | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"test_unused, test_constant, expected", | ||
[ | ||
(test_unused_dict, test_constant_dict, test_combined_dict), | ||
], | ||
) | ||
def test_combine_dictionaries(test_unused, test_constant, expected): | ||
""" | ||
Funktion, die feststellt ob die kombinierte JSON-Datei gleich der gefragten JSON-Datei ist oder nicht | ||
:param test_unused: Unused Dictionary als Parameter | ||
:param test_constant: Constant Dictionary als Parameter | ||
:param expected: gemergte JSON-Datei aus den 2 Dictionaries, die entsteht | ||
""" | ||
|
||
eval_dict = comb.__combine_dictionaries(test_unused, test_constant) | ||
assert eval_dict == expected |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.