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
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from package_parser.processing.migration.annotations import (
migrate_enum_annotation,
migrate_rename_annotation,
migrate_todo_annotation,
)
from package_parser.processing.migration.model import Mapping

Expand Down Expand Up @@ -42,4 +43,10 @@ def migrate_annotations(
for annotation in migrate_rename_annotation(rename_annotation, mapping):
migrated_annotation_store.add_annotation(annotation)

for todo_annotation in annotationsv1.todoAnnotations:
mapping = _get_mapping_from_annotation(todo_annotation, mappings)
if mapping is not None:
for annotation in migrate_todo_annotation(todo_annotation, mapping):
migrated_annotation_store.add_annotation(annotation)

return migrated_annotation_store
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from ._constants import migration_author
from ._migrate_enum_annotation import migrate_enum_annotation
from ._migrate_rename_annotation import migrate_rename_annotation
from ._migrate_todo_annotation import migrate_todo_annotation
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,12 @@ def migrate_enum_annotation(
return [enum_annotation]
return [
TodoAnnotation(
parameter.id, authors, [], "", EnumReviewResult.NONE, migrate_text
parameter.id,
authors,
enum_annotation.reviewers,
enum_annotation.comment,
EnumReviewResult.NONE,
migrate_text,
)
]

Expand All @@ -113,8 +118,8 @@ def migrate_enum_annotation(
EnumAnnotation(
parameter.id,
authors,
[],
"",
enum_annotation.reviewers,
enum_annotation.comment,
EnumReviewResult.NONE,
enum_annotation.enumName,
enum_annotation.pairs,
Expand All @@ -127,8 +132,8 @@ def migrate_enum_annotation(
TodoAnnotation(
parameter.id,
authors,
[],
"",
enum_annotation.reviewers,
enum_annotation.comment,
EnumReviewResult.UNSURE,
migrate_text,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,12 @@ def migrate_rename_annotation(
return [rename_annotation]
todo_annotations.append(
TodoAnnotation(
element.id, authors, [], "", EnumReviewResult.NONE, migrate_text
element.id,
authors,
rename_annotation.reviewers,
rename_annotation.comment,
EnumReviewResult.NONE,
migrate_text,
)
)
return todo_annotations
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
from copy import deepcopy

from package_parser.processing.annotations.model import (
AbstractAnnotation,
EnumReviewResult,
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_todo_annotation(
todo_annotation: TodoAnnotation, mapping: Mapping
) -> list[AbstractAnnotation]:
todo_annotation = deepcopy(todo_annotation)
authors = todo_annotation.authors
authors.append(migration_author)
todo_annotation.authors = authors

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

migrate_text = (
"The @Todo Annotation with the todo '"
+ todo_annotation.newTodo
+ "' from the previous version was at '"
+ todo_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())
)
)

annotated_apiv1_element = None
for element in mapping.get_apiv1_elements():
if not isinstance(element, (Attribute, Result)) and element.id:
annotated_apiv1_element = element

todo_annotations: list[AbstractAnnotation] = []
for element in mapping.get_apiv2_elements():
if isinstance(element, type(annotated_apiv1_element)) and not isinstance(
element, (Attribute, Result)
):
todo_annotations.append(
TodoAnnotation(
element.id,
authors,
todo_annotation.reviewers,
todo_annotation.comment,
EnumReviewResult.NONE,
todo_annotation.newTodo,
)
)
elif not isinstance(element, (Attribute, Result)):
todo_annotations.append(
TodoAnnotation(
element.id,
authors,
todo_annotation.reviewers,
todo_annotation.comment,
EnumReviewResult.UNSURE,
migrate_text,
)
)
return todo_annotations
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,23 @@ def migrate_rename_annotation_data_one_to_one_mapping() -> Tuple[
documentation=ParameterDocumentation("", "", ""),
)
mappings = OneToOneMapping(1.0, parameterv1, parameterv2)
annotationsv1 = RenameAnnotation(
annotationv1 = RenameAnnotation(
target="test/test.Test_",
authors=["testauthor"],
reviewers=[],
comment="",
reviewResult=EnumReviewResult.NONE,
newName="TestE",
)
annotationsv2 = RenameAnnotation(
annotationv2 = RenameAnnotation(
target="test/test.TestB",
authors=["testauthor", migration_author],
reviewers=[],
comment="",
reviewResult=EnumReviewResult.NONE,
newName="TestE",
)
return mappings, annotationsv1, [annotationsv2]
return mappings, annotationv1, [annotationv2]


def migrate_rename_annotation_data_one_to_many_mapping__with_changed_new_name() -> Tuple[
Expand All @@ -68,50 +68,50 @@ def migrate_rename_annotation_data_one_to_many_mapping__with_changed_new_name()
list[AbstractAnnotation],
]:
parameterv1 = Parameter(
id_="test/test.Test",
id_="test/test.rename.Test",
name="Test",
qname="test.Test",
qname="test.rename.Test",
default_value=None,
assigned_by=ParameterAssignment.POSITION_OR_NAME,
is_public=True,
documentation=ParameterDocumentation("", "", ""),
)
parameterv2_a = Parameter(
id_="test/test.TestA",
id_="test/test.rename.TestA",
name="TestA",
qname="test.TestA",
qname="test.rename.TestA",
default_value=None,
assigned_by=ParameterAssignment.POSITION_OR_NAME,
is_public=True,
documentation=ParameterDocumentation("", "", ""),
)
parameterv2_b = Parameter(
id_="test/test.TestB",
id_="test/test.rename.TestB",
name="TestB",
qname="test.TestB",
qname="test.rename.TestB",
default_value=None,
assigned_by=ParameterAssignment.POSITION_OR_NAME,
is_public=True,
documentation=ParameterDocumentation("", "", ""),
)
mappings = OneToManyMapping(1.0, parameterv1, [parameterv2_a, parameterv2_b])
annotationsv1 = RenameAnnotation(
target="test/test.Test",
annotationv1 = RenameAnnotation(
target="test/test.rename.Test",
authors=["testauthor"],
reviewers=[],
comment="",
reviewResult=EnumReviewResult.NONE,
newName="TestA",
)
annotationsv2 = RenameAnnotation(
target="test/test.TestA",
annotationv2 = RenameAnnotation(
target="test/test.rename.TestA",
authors=["testauthor", migration_author],
reviewers=[],
comment="The @Rename Annotation with the new name 'TestA' from the previous version was at 'test/test.Test' and the possible alternatives in the new version of the api are: TestA, TestB",
comment="The @Rename Annotation with the new name 'TestA' from the previous version was at 'test/test.rename.Test' and the possible alternatives in the new version of the api are: TestA, TestB",
reviewResult=EnumReviewResult.UNSURE,
newName="TestA",
)
return mappings, annotationsv1, [annotationsv2]
return mappings, annotationv1, [annotationv2]


def migrate_rename_annotation_data_one_to_many_mapping() -> Tuple[
Expand All @@ -120,59 +120,59 @@ def migrate_rename_annotation_data_one_to_many_mapping() -> Tuple[
list[AbstractAnnotation],
]:
parameterv1 = Parameter(
id_="test/test.Test",
id_="test/test.rename.Test",
name="Test",
qname="test.Test",
qname="test.rename.Test",
default_value=None,
assigned_by=ParameterAssignment.POSITION_OR_NAME,
is_public=True,
documentation=ParameterDocumentation("", "", ""),
)
parameterv2_a = Parameter(
id_="test/test.TestA",
id_="test/test.rename.TestA",
name="TestA",
qname="test.TestA",
qname="test.rename.TestA",
default_value=None,
assigned_by=ParameterAssignment.POSITION_OR_NAME,
is_public=True,
documentation=ParameterDocumentation("", "", ""),
)
parameterv2_b = Parameter(
id_="test/test.TestB",
id_="test/test.rename.TestB",
name="TestB",
qname="test.TestB",
qname="test.rename.TestB",
default_value=None,
assigned_by=ParameterAssignment.POSITION_OR_NAME,
is_public=True,
documentation=ParameterDocumentation("", "", ""),
)
mappings = OneToManyMapping(1.0, parameterv1, [parameterv2_a, parameterv2_b])
annotationsv1 = RenameAnnotation(
target="test/test.Test",
annotationv1 = RenameAnnotation(
target="test/test.rename.Test",
authors=["testauthor"],
reviewers=[],
comment="",
reviewResult=EnumReviewResult.NONE,
newName="TestZ",
)
annotationsv2_a = TodoAnnotation(
target="test/test.TestA",
annotationv2_a = TodoAnnotation(
target="test/test.rename.TestA",
authors=["testauthor", migration_author],
reviewers=[],
comment="",
reviewResult=EnumReviewResult.NONE,
newTodo="The @Rename Annotation with the new name 'TestZ' from the previous version was at 'test/test.Test' and the possible alternatives in the new version of the api are: TestA, TestB",
newTodo="The @Rename Annotation with the new name 'TestZ' from the previous version was at 'test/test.rename.Test' and the possible alternatives in the new version of the api are: TestA, TestB",
)
annotationsv2_b = TodoAnnotation(
target="test/test.TestB",
annotationv2_b = TodoAnnotation(
target="test/test.rename.TestB",
authors=["testauthor", migration_author],
reviewers=[],
comment="",
reviewResult=EnumReviewResult.NONE,
newTodo="The @Rename Annotation with the new name 'TestZ' from the previous version was at 'test/test.Test' and the possible alternatives in the new version of the api are: TestA, TestB",
newTodo="The @Rename Annotation with the new name 'TestZ' from the previous version was at 'test/test.rename.Test' and the possible alternatives in the new version of the api are: TestA, TestB",
)
return (
mappings,
annotationsv1,
[annotationsv2_a, annotationsv2_b],
annotationv1,
[annotationv2_a, annotationv2_b],
)
Loading