Skip to content
This repository was archived by the owner on Jan 19, 2025. It is now read-only.

Commit c00bea6

Browse files
authored
feat: migrate @value annotation (#1148)
Closes #1145. ### Summary of Changes - add migration for `@value` annotations to another version, with the possibilities: - If the variant of the annotation is omitted and both parameter have the same value, the annotation will be migrated as expected. If the type is different, the annotation will be marked as unsure. - If the variant of the annotation is required and the parameter from apiv2 has a default value of the same type, the annotation will be migrated as expected. - If the variant is optional or constant and the type of the parameter from apiv2 is known and the type of the parameters match, an annotation will be migrated as expected. If the type is unknown, the annotation will be marked as unsure. ### Testing Instructions run the migrate command or view and run the `test_migration.py` file Co-authored-by: Aclrian <[email protected]>
1 parent 1987206 commit c00bea6

File tree

9 files changed

+1255
-20
lines changed

9 files changed

+1255
-20
lines changed

package-parser/package_parser/processing/migration/_migrate.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
migrate_enum_annotation,
1111
migrate_rename_annotation,
1212
migrate_todo_annotation,
13+
migrate_value_annotation,
1314
)
1415
from package_parser.processing.migration.model import Mapping
1516

@@ -56,4 +57,10 @@ def migrate_annotations(
5657
for annotation in migrate_todo_annotation(todo_annotation, mapping):
5758
migrated_annotation_store.add_annotation(annotation)
5859

60+
for value_annotation in annotationsv1.valueAnnotations:
61+
mapping = _get_mapping_from_annotation(value_annotation, mappings)
62+
if mapping is not None:
63+
for annotation in migrate_value_annotation(value_annotation, mapping):
64+
migrated_annotation_store.add_annotation(annotation)
65+
5966
return migrated_annotation_store

package-parser/package_parser/processing/migration/annotations/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
from ._migrate_enum_annotation import migrate_enum_annotation
44
from ._migrate_rename_annotation import migrate_rename_annotation
55
from ._migrate_todo_annotation import migrate_todo_annotation
6+
from ._migrate_value_annotation import migrate_value_annotation

package-parser/package_parser/processing/migration/annotations/_migrate_boundary_annotation.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,23 @@ def migrate_boundary_annotation(
103103
) = _contains_number_and_is_discrete(parameter.type)
104104
if parameter.type is None:
105105
boundary_annotation.reviewResult = EnumReviewResult.UNSURE
106+
boundary_annotation.comment = (
107+
migrate_text
108+
if len(boundary_annotation.comment) == 0
109+
else boundary_annotation.comment + "\n" + migrate_text
110+
)
106111
return [boundary_annotation]
107112
if parameter_expects_number:
108113
if (
109114
parameter_type_is_discrete
110115
is not boundary_annotation.interval.isDiscrete
111116
):
112117
boundary_annotation.reviewResult = EnumReviewResult.UNSURE
118+
boundary_annotation.comment = (
119+
migrate_text
120+
if len(boundary_annotation.comment) == 0
121+
else boundary_annotation.comment + "\n" + migrate_text
122+
)
113123
boundary_annotation.interval = (
114124
migrate_interval_to_fit_parameter_type(
115125
boundary_annotation.interval, parameter_type_is_discrete
@@ -154,7 +164,9 @@ def migrate_boundary_annotation(
154164
parameter.id,
155165
authors,
156166
boundary_annotation.reviewers,
157-
boundary_annotation.comment,
167+
migrate_text
168+
if len(boundary_annotation.comment) == 0
169+
else boundary_annotation.comment + "\n" + migrate_text,
158170
EnumReviewResult.UNSURE,
159171
migrate_interval_to_fit_parameter_type(
160172
boundary_annotation.interval,
@@ -168,7 +180,9 @@ def migrate_boundary_annotation(
168180
parameter.id,
169181
authors,
170182
boundary_annotation.reviewers,
171-
boundary_annotation.comment,
183+
migrate_text
184+
if len(boundary_annotation.comment) == 0
185+
else boundary_annotation.comment + "\n" + migrate_text,
172186
EnumReviewResult.UNSURE,
173187
boundary_annotation.interval,
174188
)

package-parser/package_parser/processing/migration/annotations/_migrate_enum_annotation.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ def migrate_enum_annotation(
9393
return []
9494
else:
9595
enum_annotation.reviewResult = EnumReviewResult.UNSURE
96+
enum_annotation.comment = (
97+
migrate_text
98+
if len(enum_annotation.comment) == 0
99+
else enum_annotation.comment + "\n" + migrate_text
100+
)
96101
enum_annotation.target = parameter.id
97102
return [enum_annotation]
98103
return [

package-parser/package_parser/processing/migration/annotations/_migrate_rename_annotation.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,11 @@ def migrate_rename_annotation(
5252
):
5353
rename_annotation.target = element.id
5454
rename_annotation.reviewResult = EnumReviewResult.UNSURE
55-
if len(rename_annotation.comment) > 0:
56-
rename_annotation.comment += "\n"
57-
rename_annotation.comment += migrate_text
55+
rename_annotation.comment = (
56+
migrate_text
57+
if len(rename_annotation.comment) == 0
58+
else rename_annotation.comment + "\n" + migrate_text
59+
)
5860
return [rename_annotation]
5961
todo_annotations.append(
6062
TodoAnnotation(

0 commit comments

Comments
 (0)