Skip to content
This repository was archived by the owner on Jan 19, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
128 commits
Select commit Hold shift + click to select a range
40e82f1
add missing annotation classes
Aclrian Nov 12, 2022
9512403
complete missing annotations-to-json functions
Aclrian Nov 14, 2022
53ba7ac
add tests for import and export annotations
Aclrian Nov 14, 2022
443b6ce
add import of annotations during `migrate`
Aclrian Nov 14, 2022
9d3a756
refactor: using tuple and move import
Aclrian Nov 14, 2022
13aae59
refactor: from_json returns everywhere annotations
Aclrian Nov 14, 2022
f418c51
refactor: unused import
Aclrian Nov 14, 2022
6763e62
ci: disable import-error rule of pylint
lars-reimann Nov 10, 2022
54ae4c0
ci: add back default disabled rules
lars-reimann Nov 10, 2022
bbce028
ci: another attempt to configure pylint
lars-reimann Nov 10, 2022
05f8385
ci: another attempt to configure pylint
lars-reimann Nov 10, 2022
5200a31
ci: another attempt to configure pylint
lars-reimann Nov 10, 2022
d224364
ci: another attempt to configure pylint
lars-reimann Nov 10, 2022
56f3f1f
refactor: meaglinter and other warning
Aclrian Nov 14, 2022
e39ecff
disable cyclic-import, unused-arguments
Aclrian Nov 14, 2022
064a73f
add AbstractDiffer class
Aclrian Nov 15, 2022
f51cdf3
change return type to float
Aclrian Nov 15, 2022
7e1bc6b
make Differ Methods static
Aclrian Nov 15, 2022
4f0832b
get code block from function
Aclrian Nov 6, 2022
b4bb805
get code from class
Aclrian Nov 6, 2022
0228088
save code from api elements
Aclrian Nov 7, 2022
7983859
style: apply automated linter fixes
Aclrian Nov 7, 2022
cf75abf
add tests and change to lineno from fromlineno
Aclrian Nov 8, 2022
4a7162f
update api data
Aclrian Nov 8, 2022
f1dc3eb
add a comma
Aclrian Nov 8, 2022
f2db401
update api data
Aclrian Nov 9, 2022
395aaa2
ci: disable import-error rule of pylint
lars-reimann Nov 10, 2022
80ca8f7
ci: add back default disabled rules
lars-reimann Nov 10, 2022
64b5f2e
ci: another attempt to configure pylint
lars-reimann Nov 10, 2022
d4b4785
ci: another attempt to configure pylint
lars-reimann Nov 10, 2022
1bfb9d4
ci: another attempt to configure pylint
lars-reimann Nov 10, 2022
8e2548c
style: fix linter errors
lars-reimann Nov 10, 2022
8f88c28
ci: another attempt to configure pylint
lars-reimann Nov 10, 2022
c2f6dbf
style: apply automated linter fixes
lars-reimann Nov 10, 2022
bc216d0
applying requested changes
Aclrian Nov 10, 2022
3b68cd6
style: apply automated linter fixes
Aclrian Nov 10, 2022
b843cb3
add SimpleDiffer class
Aclrian Nov 15, 2022
1a4b265
Update _differ.py
Aclrian Nov 15, 2022
0790cfe
ci: configure pylint
Aclrian Nov 15, 2022
25b71ef
style: apply automated linter fixes
Aclrian Nov 15, 2022
1ef98a2
refactor: remove unwanted changes
Aclrian Nov 15, 2022
5147778
Merge branch '1113-create-a-differ-abstract-base-class' into 1114-cre…
Aclrian Nov 15, 2022
5e93e1f
style: apply automated linter fixes
Aclrian Nov 15, 2022
8d7030f
add functions diff_codes and diff_names
Aclrian Nov 16, 2022
0083962
Merge branch '1113-create-a-differ-abstract-base-class' into 1114-cre…
Aclrian Nov 16, 2022
0ee9f00
add diff_codes, changes in visability
Aclrian Nov 16, 2022
882cea0
Merge branch '1110-support-import-of-annotations' into 1114-create-a-…
Aclrian Nov 16, 2022
f5ca14a
refactor: SimpleDiffer extends AbstractDiffer
Aclrian Nov 16, 2022
3b3f86c
style: apply automated linter fixes
Aclrian Nov 16, 2022
84394ca
Merge branch 'main' into 1113-create-a-differ-abstract-base-class
lars-reimann Nov 16, 2022
abb19aa
apply requested changes
Aclrian Nov 16, 2022
819961f
style: apply automated linter fixes
Aclrian Nov 16, 2022
c7c23ef
Merge branch '1113-create-a-differ-abstract-base-class' into 1114-cre…
Aclrian Nov 16, 2022
3b81be6
adapt changes from merge
Aclrian Nov 16, 2022
080c4ed
style: apply automated linter fixes
Aclrian Nov 16, 2022
6ed5a63
refactor: removed duplicated file
Aclrian Nov 16, 2022
689add0
add class InstanceAttribute
Aclrian Nov 17, 2022
1506c4e
refactor: fix linter errors
Aclrian Nov 17, 2022
6cb3b35
style: apply automated linter fixes
Aclrian Nov 17, 2022
caf04a0
Merge branch '1113-create-a-differ-abstract-base-class' into 1114-cre…
Aclrian Nov 17, 2022
79d696e
similarity is now highest at 1
Aclrian Nov 17, 2022
130a66a
fix static parser error
Aclrian Nov 17, 2022
ad4d0d8
style: apply automated linter fixes
Aclrian Nov 17, 2022
ce7af15
add tests
Aclrian Nov 19, 2022
64d5f19
Squashed commit of the following:
Aclrian Nov 20, 2022
a206dc6
add Mapping classes
Aclrian Nov 20, 2022
7a6482b
add mapping, reduce, combine and merge methods
Aclrian Nov 21, 2022
3b5fd24
style: apply automated linter fixes
Aclrian Nov 21, 2022
6d01f68
switch to list comprehension for better reading
Aclrian Nov 21, 2022
e2e7de3
style: apply automated linter fixes
Aclrian Nov 21, 2022
e04e7f3
ref: use List instead of sequence
Aclrian Nov 22, 2022
87748de
rename mapping.py
Aclrian Nov 22, 2022
3708f98
adding tests for mapping
Aclrian Nov 22, 2022
cffa2fb
fix linter errors
Aclrian Nov 22, 2022
a282570
style: apply automated linter fixes
Aclrian Nov 22, 2022
73823a3
add documentation and renamings
Aclrian Nov 23, 2022
c967efa
style: apply automated linter fixes
Aclrian Nov 23, 2022
d965ac6
rename (Instance)Attribute and use AbstractType
Aclrian Nov 24, 2022
f3e6a3d
fix (already existing) linter errors
Aclrian Nov 25, 2022
558aef2
Merge branch '1113-create-a-differ-abstract-base-class' into 1114-cre…
Aclrian Nov 25, 2022
d9c8e38
rename (Instance)Attribute
Aclrian Nov 25, 2022
60a3944
adapt changes
Aclrian Nov 25, 2022
c43b024
style: apply automated linter fixes
Aclrian Nov 25, 2022
91e1c50
Merge branch '1114-create-a-simple-implementation-of-the-differ' into…
Aclrian Nov 25, 2022
104104d
style: apply automated linter fixes
Aclrian Nov 25, 2022
4112de3
create class APIMapping
Aclrian Nov 26, 2022
bc4d25a
fix linter errors
Aclrian Nov 26, 2022
d8a38cf
style: apply automated linter fixes
Aclrian Nov 26, 2022
330ec0c
first draft
Aclrian Nov 26, 2022
2f2dcad
first draft part 2
Aclrian Nov 27, 2022
fe7aae9
first darft part 3
Aclrian Nov 28, 2022
0436d74
add changes already made
Aclrian Nov 28, 2022
e8bf4a6
fix tests
Aclrian Nov 28, 2022
0bab910
update test data
Aclrian Nov 28, 2022
dcb5b34
fix megalinter errors
Aclrian Nov 28, 2022
4b91222
style: apply automated linter fixes
Aclrian Nov 28, 2022
b8a7d87
Merge branch '1121-add-reviewResult-in-annotations' into 1120-migrate…
Aclrian Nov 28, 2022
54fd749
fix linter errors
Aclrian Nov 28, 2022
dc077c4
remove package migration.annotation
Aclrian Nov 28, 2022
e169293
fix linter error again
Aclrian Nov 28, 2022
1bf882a
style: apply automated linter fixes
Aclrian Nov 28, 2022
6a3818c
create packages model and annotation in migration
Aclrian Nov 28, 2022
7e56777
add test and add add_annotation to AnnotationStore
Aclrian Nov 29, 2022
5c1edb5
style: apply automated linter fixes
Aclrian Nov 29, 2022
5a238b3
fix tests
Aclrian Nov 29, 2022
c91e164
Merge branch '1120-migrate-rename-annotations' of https://github.com/…
Aclrian Nov 29, 2022
f91f621
Merge branch 'main' into 1114-create-a-simple-implementation-of-the-d…
Aclrian Nov 29, 2022
b736de3
Merge branch 'main' into 1120-migrate-rename-annotations
Aclrian Nov 29, 2022
df6253c
style: apply automated linter fixes
Aclrian Nov 29, 2022
3804c7b
Merge branch '1114-create-a-simple-implementation-of-the-differ' into…
Aclrian Nov 29, 2022
24bc9b2
Merge branch 'main' into 1121-add-reviewResult-in-annotations
Aclrian Nov 29, 2022
4271467
Merge branch '1121-add-reviewResult-in-annotations' into 1120-migrate…
Aclrian Nov 29, 2022
7a948aa
Merge branch '1118-map-list-of-old-api-elements-to-list-of-new-api-el…
Aclrian Nov 29, 2022
e64500c
remove duplicated file _differ
Aclrian Nov 29, 2022
8a56c33
style: apply automated linter fixes
Aclrian Nov 29, 2022
48a9c96
Merge branch 'main' into 1118-map-list-of-old-api-elements-to-list-of…
Aclrian Nov 30, 2022
a0bab02
use @dataclsss for mappings
Aclrian Nov 30, 2022
8a442cb
Merge branch 'main' into 1120-migrate-rename-annotations
Aclrian Nov 30, 2022
cf218da
undo not necessary changes
Aclrian Nov 30, 2022
d52094c
add new file for read and write classes
Aclrian Nov 30, 2022
f0d2d2d
style: apply automated linter fixes
Aclrian Nov 30, 2022
618588f
undo not necessary changes
Aclrian Nov 30, 2022
e235631
Merge branch '1118-map-list-of-old-api-elements-to-list-of-new-api-el…
Aclrian Nov 30, 2022
74e9010
add apiv1 data as v0.24.2
Aclrian Nov 30, 2022
df923f5
style: apply automated linter fixes
Aclrian Nov 30, 2022
c7937fc
Merge remote-tracking branch 'origin/main' into 1120-migrate-rename-a…
Aclrian Dec 1, 2022
5fcb745
change header class
Aclrian Dec 1, 2022
6e22eaa
Delete migration/_mapping.py
Aclrian Dec 1, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
252,312 changes: 252,312 additions & 0 deletions data/api/scikit-learn_v0.24.2_api.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package-parser/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

A tool to analyze client and API code written in Python.

### Installation
## Installation

1. Install Python 3.10.
2. Install [poetry](https://python-poetry.org/docs/master/#installation).
Expand All @@ -15,7 +15,7 @@ A tool to analyze client and API code written in Python.
poetry shell
```

### Example usage
## Example usage

1. Analyze an API:
```shell
Expand All @@ -32,5 +32,5 @@ A tool to analyze client and API code written in Python.
```
4. Migrate annotations for a new version of the API:
```shell
parse-package migrate -a1 data/api/sklearn__api.json -a2 data/api/sklearn__apiv2.json -a data/annotations/annotations.json -o out
parse-package migrate -a1 data/api/scikit-learn_v0.24.2_api.json -a2 data/api/sklearn__apiv2.json -a data/annotations/annotations.json -o out
```
52 changes: 52 additions & 0 deletions package-parser/package_parser/cli/_read_and_write_file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import json
from pathlib import Path

from package_parser.cli._json_encoder import CustomEncoder
from package_parser.processing.annotations.model import AnnotationStore
from package_parser.processing.api.model import API
from package_parser.processing.usages.model import UsageCountStore
from package_parser.utils import ensure_file_exists


def _read_annotations_file(annotations_file_path: Path) -> AnnotationStore:
with open(annotations_file_path, encoding="utf-8") as annotations_file:
annotations_json = json.load(annotations_file)

return AnnotationStore.from_json(annotations_json)


def _write_annotations_file(
annotations: AnnotationStore, annotations_file_path: Path
) -> None:
ensure_file_exists(annotations_file_path)
with annotations_file_path.open("w", encoding="utf-8") as f:
json.dump(annotations.to_json(), f, indent=2)


def _read_api_file(api_file_path: Path) -> API:
with open(api_file_path, encoding="utf-8") as api_file:
api_json = json.load(api_file)

return API.from_json(api_json)


def _read_usages_file(usages_file_path: Path) -> UsageCountStore:
with open(usages_file_path, encoding="utf-8") as usages_file:
usages_json = json.load(usages_file)

return UsageCountStore.from_json(usages_json)


def _write_api_file(api: API, out_dir_path: Path) -> Path:
out_file_api = out_dir_path.joinpath(f"{api.package}__api.json")
ensure_file_exists(out_file_api)
with out_file_api.open("w", encoding="utf-8") as f:
json.dump(api.to_json(), f, indent=2, cls=CustomEncoder)
return out_file_api


def _write_api_dependency_file(api: API, api_dependencies, out):
out_file_api_dependencies = out.joinpath(f"{api.package}__api_dependencies.json")
ensure_file_exists(out_file_api_dependencies)
with out_file_api_dependencies.open("w") as f:
json.dump(api_dependencies.to_json(), f, indent=2, cls=CustomEncoder)
33 changes: 6 additions & 27 deletions package-parser/package_parser/cli/_run_annotations.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import json
from pathlib import Path

from package_parser.processing.annotations import generate_annotations
from package_parser.processing.annotations.model import AnnotationStore
from package_parser.processing.api.model import API
from package_parser.processing.usages.model import UsageCountStore
from package_parser.utils import ensure_file_exists

from ._read_and_write_file import (
_read_api_file,
_read_usages_file,
_write_annotations_file,
)


def _run_annotations(
Expand All @@ -23,25 +24,3 @@ def _run_annotations(
usages = _read_usages_file(usages_file_path)
annotations = generate_annotations(api, usages)
_write_annotations_file(annotations, annotations_file_path)


def _read_api_file(api_file_path: Path) -> API:
with open(api_file_path) as api_file:
api_json = json.load(api_file)

return API.from_json(api_json)


def _read_usages_file(usages_file_path: Path) -> UsageCountStore:
with open(usages_file_path) as usages_file:
usages_json = json.load(usages_file)

return UsageCountStore.from_json(usages_json)


def _write_annotations_file(
annotations: AnnotationStore, annotations_file_path: Path
) -> None:
ensure_file_exists(annotations_file_path)
with annotations_file_path.open("w") as f:
json.dump(annotations.to_json(), f, indent=2)
23 changes: 3 additions & 20 deletions package-parser/package_parser/cli/_run_api.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import json
from pathlib import Path
from typing import Optional

from package_parser.cli._json_encoder import CustomEncoder
from package_parser.cli._shared_constants import _API_KEY
from package_parser.processing.api import get_api
from package_parser.processing.api.model import API
from package_parser.processing.dependencies import get_dependencies
from package_parser.utils import ensure_file_exists

from ._read_and_write_file import _write_api_dependency_file, _write_api_file
from ._shared_constants import _API_KEY


def _run_api_command(
Expand All @@ -24,18 +22,3 @@ def _run_api_command(

if result_dict is not None:
result_dict[_API_KEY] = api_file_path


def _write_api_file(api: API, out_dir_path: Path) -> Path:
out_file_api = out_dir_path.joinpath(f"{api.package}__api.json")
ensure_file_exists(out_file_api)
with out_file_api.open("w") as f:
json.dump(api.to_json(), f, indent=2, cls=CustomEncoder)
return out_file_api


def _write_api_dependency_file(api: API, api_dependencies, out):
out_file_api_dependencies = out.joinpath(f"{api.package}__api_dependencies.json")
ensure_file_exists(out_file_api_dependencies)
with out_file_api_dependencies.open("w") as f:
json.dump(api_dependencies.to_json(), f, indent=2, cls=CustomEncoder)
37 changes: 16 additions & 21 deletions package-parser/package_parser/cli/_run_migrate.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import json
from pathlib import Path

from package_parser.processing.annotations.model import AnnotationStore
from package_parser.processing.api.model import API
from package_parser.processing.migration import migrate_annotations
from package_parser.processing.migration.model import APIMapping, SimpleDiffer

from ._read_and_write_file import (
_read_annotations_file,
_read_api_file,
_write_annotations_file,
)


def _run_migrate_command(
Expand All @@ -11,21 +16,11 @@ def _run_migrate_command(
apiv2_file_path: Path,
out_dir_path: Path,
) -> None:
# pylint: disable=unused-argument
_read_api_file(apiv1_file_path)
_read_api_file(apiv2_file_path)
_read_annotations_file(annotations_file_path)


def _read_annotations_file(annotations_file_path: Path) -> AnnotationStore:
with open(annotations_file_path, encoding="utf-8") as annotations_file:
annotations_json = json.load(annotations_file)

return AnnotationStore.from_json(annotations_json)


def _read_api_file(api_file_path: Path) -> API:
with open(api_file_path, encoding="utf-8") as api_file:
api_json = json.load(api_file)

return API.from_json(api_json)
apiv1 = _read_api_file(apiv1_file_path)
apiv2 = _read_api_file(apiv2_file_path)
annotationsv1 = _read_annotations_file(annotations_file_path)
differ = SimpleDiffer()
api_mapping = APIMapping(apiv1, apiv2, differ)
mappings = api_mapping.map_api()
annotationsv2 = migrate_annotations(annotationsv1, mappings)
_write_annotations_file(annotationsv2, out_dir_path)
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from ._annotations import (
ANNOTATION_SCHEMA_VERSION,
AbstractAnnotation,
BoundaryAnnotation,
CalledAfterAnnotation,
CompleteAnnotation,
Expand Down Expand Up @@ -105,6 +106,34 @@ def from_json(json: Any) -> AnnotationStore:
valueAnnotations,
)

def add_annotation(self, annotation: AbstractAnnotation):
if isinstance(annotation, BoundaryAnnotation):
self.boundaryAnnotations.append(annotation)
if isinstance(annotation, BoundaryAnnotation):
self.boundaryAnnotations.append(annotation)
if isinstance(annotation, CalledAfterAnnotation):
self.calledAfterAnnotations.append(annotation)
if isinstance(annotation, CompleteAnnotation):
self.completeAnnotations.append(annotation)
if isinstance(annotation, DescriptionAnnotation):
self.descriptionAnnotations.append(annotation)
if isinstance(annotation, EnumAnnotation):
self.enumAnnotations.append(annotation)
if isinstance(annotation, GroupAnnotation):
self.groupAnnotations.append(annotation)
if isinstance(annotation, MoveAnnotation):
self.moveAnnotations.append(annotation)
if isinstance(annotation, PureAnnotation):
self.pureAnnotations.append(annotation)
if isinstance(annotation, RemoveAnnotation):
self.removeAnnotations.append(annotation)
if isinstance(annotation, RenameAnnotation):
self.renameAnnotations.append(annotation)
if isinstance(annotation, TodoAnnotation):
self.todoAnnotations.append(annotation)
if isinstance(annotation, ValueAnnotation):
self.valueAnnotations.append(annotation)

def to_json(self) -> dict:
return {
"schemaVersion": ANNOTATION_SCHEMA_VERSION,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
from ._differ import AbstractDiffer, SimpleDiffer
from ._mapping import (
from package_parser.processing.migration.model import (
AbstractDiffer,
APIMapping,
ManyToManyMapping,
ManyToOneMapping,
Mapping,
OneToManyMapping,
OneToOneMapping,
SimpleDiffer,
)

from ._migrate import migrate_annotations
36 changes: 36 additions & 0 deletions package-parser/package_parser/processing/migration/_migrate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from typing import Optional

from package_parser.processing.annotations.model import (
AbstractAnnotation,
AnnotationStore,
)
from package_parser.processing.api.model import Attribute, Result
from package_parser.processing.migration.annotations import migrate_rename_annotation
from package_parser.processing.migration.model import Mapping


def _get_mapping_from_annotation(
annotation: AbstractAnnotation, mappings: list[Mapping]
) -> Optional[Mapping]:
for mapping in mappings:
for element in mapping.get_apiv1_elements():
if (
not isinstance(element, (Attribute, Result))
and element.id == annotation.target
):
return mapping
return None


def migrate_annotations(
annotationsv1: AnnotationStore, mappings: list[Mapping]
) -> AnnotationStore:
migrated_annotation_store = AnnotationStore()

for rename_annotation in annotationsv1.renameAnnotations:
mapping = _get_mapping_from_annotation(rename_annotation, mappings)
if mapping is not None:
for annotation in migrate_rename_annotation(rename_annotation, mapping):
migrated_annotation_store.add_annotation(annotation)

return migrated_annotation_store
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from ._constants import migration_author
from ._migrate_rename_annotation import migrate_rename_annotation
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
migration_author = "migration"
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
from copy import deepcopy

from package_parser.processing.annotations.model import (
AbstractAnnotation,
EnumReviewResult,
RenameAnnotation,
TodoAnnotation,
)
from package_parser.processing.api.model import Attribute, Result
from package_parser.processing.migration.model import (
ManyToOneMapping,
Mapping,
OneToOneMapping,
)

from ._constants import migration_author


def migrate_rename_annotation(
rename_annotation: RenameAnnotation, mapping: Mapping
) -> list[AbstractAnnotation]:
rename_annotation = deepcopy(rename_annotation)
new_name = rename_annotation.newName
authors = rename_annotation.authors
authors.append(migration_author)
rename_annotation.authors = authors

if isinstance(mapping, (ManyToOneMapping, OneToOneMapping)):
element = mapping.get_apiv2_elements()[0]
if isinstance(element, (Attribute, Result)):
return []
rename_annotation.target = element.id
return [rename_annotation]

migrate_text = (
"The @Rename Annotation with the new name '"
+ rename_annotation.newName
+ "' from the previous version was at '"
+ rename_annotation.target
+ "' and the possible alternatives in the new version of the api are: "
+ ", ".join(
map(lambda api_element: api_element.name, mapping.get_apiv2_elements())
)
)

todo_annotations: list[AbstractAnnotation] = []
for element in mapping.get_apiv2_elements():
if not isinstance(element, (Attribute, Result)):
if element.name in (
new_name,
rename_annotation.target.split(".")[-1],
):
rename_annotation.target = element.id
rename_annotation.reviewResult = EnumReviewResult.UNSURE
if len(rename_annotation.comment) > 0:
rename_annotation.comment += "\n"
rename_annotation.comment += migrate_text
return [rename_annotation]
todo_annotations.append(
TodoAnnotation(
element.id, authors, [], "", EnumReviewResult.NONE, migrate_text
)
)
return todo_annotations
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from ._differ import AbstractDiffer, SimpleDiffer
from ._mapping import (
APIMapping,
ManyToManyMapping,
ManyToOneMapping,
Mapping,
OneToManyMapping,
OneToOneMapping,
)
Loading