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: 433 Creates a Dict from a given json List #437
Merged
GideonKoenig
merged 11 commits into
main
from
433-automatisch-unused-annotation-generieren
Apr 21, 2022
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
9d616ea
Creates a Dict from a given json List
jofaul 54bca77
Changed wrong Type Str to str
jofaul fd131e2
style: apply automatic fixes of linters
jofaul 9c234cd
fix: pytest failed on expected exception
Aclrian 8a57ab0
fix: file location is required
Aclrian 354a737
style: apply automatic fixes of linters
Aclrian 81f5dec
fix: assumed wrong working dir
Aclrian 961e744
removed changes in .idea and added it to gitignore of package-parser
jofaul ef47e62
Merge branch 'main' into 433-automatisch-unused-annotation-generieren
GideonKoenig 3c22e01
revert changes in .idea folder
Aclrian f8b8dfe
improve code style
Aclrian 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
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 |
---|---|---|
|
@@ -30,3 +30,6 @@ out/ | |
|
||
# VSCode Settings | ||
.vscode/ | ||
|
||
# IntelliJ/Pycharm settings | ||
.idea/ | ||
Empty file.
44 changes: 44 additions & 0 deletions
44
package-parser/package_parser/commands/generate_annotations/_generate_unused_annotations.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,44 @@ | ||
import json | ||
import re | ||
from typing import Dict, List, Tuple | ||
|
||
|
||
def generate_unused_annotations(in_file_path: str): | ||
""" | ||
Returns a Dict of unused functions or classes | ||
|
||
:param in_file_path: JSON file that contains a list of unused functions or classes | ||
""" | ||
|
||
with open(in_file_path, "r", encoding="UTF-8") as in_file: | ||
data = json.load(in_file) | ||
|
||
unuseds: Dict[str, Dict[str, str]] = {} | ||
for name in data: | ||
formatted_name = format_name(name) | ||
unuseds[formatted_name] = {"target": formatted_name} | ||
|
||
return unuseds | ||
|
||
|
||
def format_name(name: str): | ||
if name is None: | ||
return None | ||
|
||
parts = re.split("\\.", name) | ||
newname = "sklearn/" + parts[0] | ||
GideonKoenig marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if len(parts) == 1: | ||
return newname | ||
|
||
slash = False | ||
for part in parts[1:-1]: | ||
if not slash and re.match("^_{0,2}[A-Z]", part): | ||
slash = True | ||
if slash: | ||
newname += "/" + part | ||
else: | ||
newname += "." + part | ||
|
||
newname += "/" + parts[-1] | ||
return newname |
Empty file.
67 changes: 67 additions & 0 deletions
67
package-parser/tests/commands/generate_annotations/test_generate_unused_annotations.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,67 @@ | ||
import pytest | ||
from package_parser.commands.generate_annotations._generate_unused_annotations import ( | ||
format_name, | ||
generate_unused_annotations, | ||
) | ||
|
||
EXPECTED_VALUE = { | ||
"sklearn/sklearn.base/_BaseEstimator/__setstate__": { | ||
"target": "sklearn/sklearn.base/_BaseEstimator/__setstate__" | ||
}, | ||
"sklearn/sklearn.base/is_regressor": { | ||
"target": "sklearn/sklearn.base/is_regressor" | ||
}, | ||
"sklearn/sklearn.cluster._agglomerative/linkage_tree": { | ||
"target": "sklearn/sklearn.cluster._agglomerative/linkage_tree" | ||
}, | ||
"sklearn/sklearn.cluster._kmeans/MiniBatchKMeans/init_size_": { | ||
"target": "sklearn/sklearn.cluster._kmeans/MiniBatchKMeans/init_size_" | ||
}, | ||
} | ||
|
||
|
||
def test_format_underscores(): | ||
assert ( | ||
format_name("sklearn.cluster._kmeans._MiniBatchKMeans.random_state_") | ||
== "sklearn/sklearn.cluster._kmeans/_MiniBatchKMeans/random_state_" | ||
) | ||
|
||
|
||
def test_format_uppercase(): | ||
assert ( | ||
format_name("sklearn.cluster._kmeans.MiniBatchKMeans.random_state_") | ||
== "sklearn/sklearn.cluster._kmeans/MiniBatchKMeans/random_state_" | ||
) | ||
GideonKoenig marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
def test_format_normal(): | ||
assert ( | ||
format_name("sklearn.cluster._mean_shift.get_bin_seeds") | ||
== "sklearn/sklearn.cluster._mean_shift/get_bin_seeds" | ||
) | ||
|
||
|
||
def test_format_one_part(): | ||
assert format_name("test") == "sklearn/test" | ||
|
||
|
||
def test_format_none(): | ||
assert format_name(None) is None | ||
|
||
|
||
def test_format_empty(): | ||
assert format_name("") == "sklearn/" | ||
|
||
|
||
def test_generate(): | ||
assert ( | ||
generate_unused_annotations( | ||
"tests/commands/generate_annotations/unused_functions_list.json" | ||
) | ||
== EXPECTED_VALUE | ||
) | ||
|
||
|
||
def test_generate_bad_path(): | ||
with pytest.raises(FileNotFoundError): | ||
generate_unused_annotations("aaaaaaaaaaaAAAAAAAAAAAA") |
6 changes: 6 additions & 0 deletions
6
package-parser/tests/commands/generate_annotations/unused_functions_list.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,6 @@ | ||
[ | ||
"sklearn.base._BaseEstimator.__setstate__", | ||
"sklearn.base.is_regressor", | ||
"sklearn.cluster._agglomerative.linkage_tree", | ||
"sklearn.cluster._kmeans.MiniBatchKMeans.init_size_" | ||
] | ||
GideonKoenig marked this conversation as resolved.
Show resolved
Hide resolved
|
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.