diff --git a/package-parser/package_parser/processing/migration/_migrate.py b/package-parser/package_parser/processing/migration/_migrate.py index d0dba93ec..f9273a2c3 100644 --- a/package-parser/package_parser/processing/migration/_migrate.py +++ b/package-parser/package_parser/processing/migration/_migrate.py @@ -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 @@ -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 diff --git a/package-parser/package_parser/processing/migration/annotations/__init__.py b/package-parser/package_parser/processing/migration/annotations/__init__.py index c79d44bb8..6344d48ba 100644 --- a/package-parser/package_parser/processing/migration/annotations/__init__.py +++ b/package-parser/package_parser/processing/migration/annotations/__init__.py @@ -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 diff --git a/package-parser/package_parser/processing/migration/annotations/_migrate_enum_annotation.py b/package-parser/package_parser/processing/migration/annotations/_migrate_enum_annotation.py index 9301f7329..19c8c687b 100644 --- a/package-parser/package_parser/processing/migration/annotations/_migrate_enum_annotation.py +++ b/package-parser/package_parser/processing/migration/annotations/_migrate_enum_annotation.py @@ -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, ) ] @@ -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, @@ -127,8 +132,8 @@ def migrate_enum_annotation( TodoAnnotation( parameter.id, authors, - [], - "", + enum_annotation.reviewers, + enum_annotation.comment, EnumReviewResult.UNSURE, migrate_text, ) diff --git a/package-parser/package_parser/processing/migration/annotations/_migrate_rename_annotation.py b/package-parser/package_parser/processing/migration/annotations/_migrate_rename_annotation.py index bad401591..e5c51b51f 100644 --- a/package-parser/package_parser/processing/migration/annotations/_migrate_rename_annotation.py +++ b/package-parser/package_parser/processing/migration/annotations/_migrate_rename_annotation.py @@ -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 diff --git a/package-parser/package_parser/processing/migration/annotations/_migrate_todo_annotation.py b/package-parser/package_parser/processing/migration/annotations/_migrate_todo_annotation.py new file mode 100644 index 000000000..985d3851b --- /dev/null +++ b/package-parser/package_parser/processing/migration/annotations/_migrate_todo_annotation.py @@ -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 diff --git a/package-parser/tests/processing/migration/annotations/test_rename_migration.py b/package-parser/tests/processing/migration/annotations/test_rename_migration.py index 000578109..4beeb144f 100644 --- a/package-parser/tests/processing/migration/annotations/test_rename_migration.py +++ b/package-parser/tests/processing/migration/annotations/test_rename_migration.py @@ -43,7 +43,7 @@ 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=[], @@ -51,7 +51,7 @@ def migrate_rename_annotation_data_one_to_one_mapping() -> Tuple[ reviewResult=EnumReviewResult.NONE, newName="TestE", ) - annotationsv2 = RenameAnnotation( + annotationv2 = RenameAnnotation( target="test/test.TestB", authors=["testauthor", migration_author], reviewers=[], @@ -59,7 +59,7 @@ def migrate_rename_annotation_data_one_to_one_mapping() -> Tuple[ 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[ @@ -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[ @@ -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], ) diff --git a/package-parser/tests/processing/migration/annotations/test_todo_migration.py b/package-parser/tests/processing/migration/annotations/test_todo_migration.py new file mode 100644 index 000000000..9c3725a77 --- /dev/null +++ b/package-parser/tests/processing/migration/annotations/test_todo_migration.py @@ -0,0 +1,217 @@ +from typing import Tuple + +from package_parser.processing.annotations.model import ( + AbstractAnnotation, + EnumReviewResult, + TodoAnnotation, +) +from package_parser.processing.api.model import ( + Class, + ClassDocumentation, + Parameter, + ParameterAssignment, + ParameterDocumentation, +) +from package_parser.processing.migration import ManyToManyMapping +from package_parser.processing.migration.annotations import migration_author +from package_parser.processing.migration.model import ( + Mapping, + OneToManyMapping, + OneToOneMapping, +) + + +def migrate_todo_annotation_data_one_to_one_mapping() -> Tuple[ + Mapping, AbstractAnnotation, list[AbstractAnnotation] +]: + parameterv1 = Parameter( + id_="test/test.todo.test1.Test", + name="Test1", + qname="test.todo.test1.Test", + default_value=None, + assigned_by=ParameterAssignment.POSITION_OR_NAME, + is_public=True, + documentation=ParameterDocumentation("str", "", ""), + ) + parameterv2 = Parameter( + id_="test/test.todo.test1.Test", + name="Test", + qname="test.todo.test1.Test", + default_value=None, + assigned_by=ParameterAssignment.POSITION_OR_NAME, + is_public=True, + documentation=ParameterDocumentation("str", "", ""), + ) + mappings = OneToOneMapping(1.0, parameterv1, parameterv2) + annotationsv1 = TodoAnnotation( + target="test/test.todo.test1.Test", + authors=["testauthor"], + reviewers=[], + comment="", + reviewResult=EnumReviewResult.NONE, + newTodo="todo", + ) + annotationsv2 = TodoAnnotation( + target="test/test.todo.test1.Test", + authors=["testauthor", migration_author], + reviewers=[], + comment="", + reviewResult=EnumReviewResult.NONE, + newTodo="todo", + ) + return mappings, annotationsv1, [annotationsv2] + + +def migrate_todo_annotation_data_one_to_many_mapping() -> Tuple[ + Mapping, + AbstractAnnotation, + list[AbstractAnnotation], +]: + parameterv1 = Parameter( + id_="test/test.todo.test2.Test", + name="Test", + qname="test.todo.test1.Test", + default_value=None, + assigned_by=ParameterAssignment.POSITION_OR_NAME, + is_public=True, + documentation=ParameterDocumentation("str", "", ""), + ) + parameterv2_a = Parameter( + id_="test/test.todo.test2.TestA", + name="TestA", + qname="test.todo.test2.TestA", + default_value=None, + assigned_by=ParameterAssignment.POSITION_OR_NAME, + is_public=True, + documentation=ParameterDocumentation("str", "", ""), + ) + parameterv2_b = Parameter( + id_="test/test.todo.test2.TestB", + name="TestB", + qname="test.todo.test2.TestB", + default_value=None, + assigned_by=ParameterAssignment.POSITION_OR_NAME, + is_public=True, + documentation=ParameterDocumentation("str", "", ""), + ) + mappings = OneToManyMapping(1.0, parameterv1, [parameterv2_a, parameterv2_b]) + annotationsv1 = TodoAnnotation( + target="test/test.todo.test2.Test", + authors=["testauthor"], + reviewers=[], + comment="", + reviewResult=EnumReviewResult.NONE, + newTodo="todo", + ) + annotationsv2_a = TodoAnnotation( + target="test/test.todo.test2.TestA", + authors=["testauthor", migration_author], + reviewers=[], + comment="", + reviewResult=EnumReviewResult.NONE, + newTodo="todo", + ) + annotationsv2_b = TodoAnnotation( + target="test/test.todo.test2.TestB", + authors=["testauthor", migration_author], + reviewers=[], + comment="", + reviewResult=EnumReviewResult.NONE, + newTodo="todo", + ) + return mappings, annotationsv1, [annotationsv2_a, annotationsv2_b] + + +def migrate_todo_annotation_data_many_to_many_mapping() -> Tuple[ + Mapping, AbstractAnnotation, list[AbstractAnnotation] +]: + parameterv1_a = Parameter( + id_="test/test.todo.test3.TestA", + name="TestA", + qname="test.todo.test3.TestA", + default_value=None, + assigned_by=ParameterAssignment.POSITION_OR_NAME, + is_public=True, + documentation=ParameterDocumentation("str", "", ""), + ) + parameterv1_b = Parameter( + id_="test/test.todo.test3.TestB", + name="TestB", + qname="test.todo.test3.TestB", + default_value=None, + assigned_by=ParameterAssignment.POSITION_OR_NAME, + is_public=True, + documentation=ParameterDocumentation("str", "", ""), + ) + parameterv2_a = Parameter( + id_="test/test.todo.test3.NewTestA", + name="NewTestA", + qname="test.todo.test3.NewTestA", + default_value=None, + assigned_by=ParameterAssignment.POSITION_OR_NAME, + is_public=True, + documentation=ParameterDocumentation("str", "", ""), + ) + parameterv2_b = Parameter( + id_="test/test.todo.test3.NewTestB", + name="NewTestB", + qname="test.todo.test3.NewTestB", + default_value=None, + assigned_by=ParameterAssignment.POSITION_OR_NAME, + is_public=True, + documentation=ParameterDocumentation("str", "", ""), + ) + classv2 = Class( + id_="test/test.todo.test3.TestClass", + qname="test.todo.test3.TestClass", + decorators=[], + superclasses=[], + is_public=True, + reexported_by=[], + documentation=ClassDocumentation("", ""), + code="", + instance_attributes=[], + ) + mappings = ManyToManyMapping( + 1.0, [parameterv1_a, parameterv1_b], [parameterv2_a, parameterv2_b, classv2] + ) + annotationv1 = TodoAnnotation( + target="test/test.todo.test3.TestA", + authors=["testauthor"], + reviewers=[], + comment="", + reviewResult=EnumReviewResult.NONE, + newTodo="todo", + ) + annotationv2_a = TodoAnnotation( + target="test/test.todo.test3.NewTestA", + authors=["testauthor", migration_author], + reviewers=[], + comment="", + reviewResult=EnumReviewResult.NONE, + newTodo="todo", + ) + annotationv2_b = TodoAnnotation( + target="test/test.todo.test3.NewTestB", + authors=["testauthor", migration_author], + reviewers=[], + comment="", + reviewResult=EnumReviewResult.NONE, + newTodo="todo", + ) + annotationv2_class = TodoAnnotation( + target="test/test.todo.test3.TestClass", + authors=["testauthor", migration_author], + reviewers=[], + comment="", + reviewResult=EnumReviewResult.UNSURE, + newTodo="The @Todo Annotation with the todo 'todo' from the " + "previous version was at 'test/test.todo.test3.TestA' " + "and the possible alternatives in the new version of " + "the api are: NewTestA, NewTestB, TestClass", + ) + return ( + mappings, + annotationv1, + [annotationv2_a, annotationv2_b, annotationv2_class], + ) diff --git a/package-parser/tests/processing/migration/test_migration.py b/package-parser/tests/processing/migration/test_migration.py index f38d6e279..360021a62 100644 --- a/package-parser/tests/processing/migration/test_migration.py +++ b/package-parser/tests/processing/migration/test_migration.py @@ -14,11 +14,19 @@ migrate_rename_annotation_data_one_to_many_mapping__with_changed_new_name, migrate_rename_annotation_data_one_to_one_mapping, ) +from tests.processing.migration.annotations.test_todo_migration import ( + migrate_todo_annotation_data_many_to_many_mapping, + migrate_todo_annotation_data_one_to_many_mapping, + migrate_todo_annotation_data_one_to_one_mapping, +) test_data = [ migrate_rename_annotation_data_one_to_many_mapping__with_changed_new_name(), migrate_rename_annotation_data_one_to_one_mapping(), migrate_rename_annotation_data_one_to_many_mapping(), + migrate_todo_annotation_data_one_to_one_mapping(), + migrate_todo_annotation_data_one_to_many_mapping(), + migrate_todo_annotation_data_many_to_many_mapping(), migrate_enum_annotation_data_one_to_one_mapping(), migrate_enum_annotation_data_one_to_many_mapping(), migrate_enum_annotation_data_one_to_many_mapping__only_one_relevant_mapping(),