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
46 commits
Select commit Hold shift + click to select a range
2bd9255
separate not very similar annotations
Aclrian Dec 29, 2022
12053ad
Merge branch 'main' into 1162-save-migrated-annotations
Aclrian Dec 29, 2022
faa364e
error fixing
Aclrian Dec 29, 2022
bb22a9d
create todo annotations only with none as review result
Aclrian Dec 30, 2022
0013d84
fix linter errors
Aclrian Dec 30, 2022
d295fb2
fix linter errors
Aclrian Dec 30, 2022
fcdbd3b
style: apply automated linter fixes
Aclrian Dec 30, 2022
02507ac
improve `@value` annotation migration
Aclrian Dec 30, 2022
77021f6
fix linter errors
Aclrian Dec 30, 2022
89b343c
style: apply automated linter fixes
Aclrian Dec 30, 2022
26f7d39
change value annotation migartion and improved get_migration_text
Aclrian Dec 31, 2022
5134d14
fix linter errors
Aclrian Dec 31, 2022
e392345
style: apply automated linter fixes
Aclrian Dec 31, 2022
570d129
draft for removing duplicated annotations
Aclrian Dec 31, 2022
648a12e
fix linter errors
Aclrian Dec 31, 2022
5d8023f
style: apply automated linter fixes
Aclrian Jan 1, 2023
8d18bd5
remove duplicates
Aclrian Jan 2, 2023
e2254e9
style: apply automated linter fixes
Aclrian Jan 2, 2023
f9fdbb1
fix errors
Aclrian Jan 2, 2023
ded3f29
Merge branch 'main' into 1162-save-migrated-annotations
Aclrian Jan 2, 2023
7f1613a
add tests for duplicates
Aclrian Jan 2, 2023
7badaa6
fix linter errors
Aclrian Jan 2, 2023
2aae7dd
style: apply automated linter fixes
Aclrian Jan 2, 2023
25064eb
Merge branch 'main' into 1162-save-migrated-annotations
Aclrian Jan 2, 2023
5db5439
that takes long time
Aclrian Jan 3, 2023
ee19f12
Squashed commit of the following:
Aclrian Jan 3, 2023
1b4822a
Revert "Squashed commit of the following:"
Aclrian Jan 3, 2023
17c3ab3
Merge branch 'main' into 1162-save-migrated-annotations
Aclrian Jan 3, 2023
bc39202
add test data
Aclrian Jan 3, 2023
df4b9cf
add smoke test for migration
Aclrian Jan 3, 2023
ed8e0b0
fix linter errrors
Aclrian Jan 3, 2023
f2923a0
fix linter errrors
Aclrian Jan 3, 2023
77519a2
Merge branch '1162-save-migrated-annotations' of https://github.com/l…
Aclrian Jan 3, 2023
b202525
style: apply automated linter fixes
Aclrian Jan 3, 2023
32815dd
improve enum and boundary annotatrion migration
Aclrian Jan 3, 2023
9a821ab
fix linter errors
Aclrian Jan 3, 2023
e638716
style: apply automated linter fixes
Aclrian Jan 3, 2023
f4dda40
fix else/elif/continue confusion
Aclrian Jan 3, 2023
c9e7388
Merge branch '1162-save-migrated-annotations' of https://github.com/l…
Aclrian Jan 3, 2023
14add76
some refactoring
Aclrian Jan 4, 2023
9b9ad84
further refactoring and fixing tests
Aclrian Jan 4, 2023
bc728f9
fix linter errors
Aclrian Jan 4, 2023
d9b100b
style: apply automated linter fixes
Aclrian Jan 4, 2023
c4393fe
migrate not unsure annotations if both types of the elements are None
Aclrian Jan 5, 2023
bc9a761
fix linter errors
Aclrian Jan 5, 2023
bbde0b4
style: apply automated linter fixes
Aclrian Jan 5, 2023
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
3 changes: 3 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ jobs:
- name: Smoke test (all)
run: poetry run parse-package all -p package_parser -s package_parser -c package_parser -o out

- name: Smoke test (migration)
run: poetry run parse-package migrate -a1 tests/data/migration/apiv1_data.json -a2 tests/data/migration/apiv2_data.json -a tests/data/migration/annotationv1.json -o out

# Requires installation of pytest and pytest-cov
- name: Test with pytest
run: poetry run pytest --doctest-modules
21 changes: 18 additions & 3 deletions package-parser/package_parser/cli/_run_migrate.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
from pathlib import Path

from package_parser.processing.migration import migrate_annotations
from package_parser.processing.migration import Migration
from package_parser.processing.migration.model import APIMapping, SimpleDiffer

from ._read_and_write_file import (
Expand All @@ -22,5 +23,19 @@ def _run_migrate_command(
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)
migration = Migration(annotationsv1, mappings)
migration.migrate_annotations()
migrated_annotations_file = Path(
os.path.join(out_dir_path, "migrated_annotationsv" + apiv2.version + ".json")
)
unsure_migrated_annotations_file = Path(
os.path.join(
out_dir_path, "unsure_migrated_annotationsv" + apiv2.version + ".json"
)
)
_write_annotations_file(
migration.migrated_annotation_store, migrated_annotations_file
)
_write_annotations_file(
migration.unsure_migrated_annotation_store, unsure_migrated_annotations_file
)
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from ._are_semantic_equal import are_semantic_equal
from ._generate_annotations import generate_annotations
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
from package_parser.processing.annotations.model import (
AbstractAnnotation,
BoundaryAnnotation,
CalledAfterAnnotation,
ConstantAnnotation,
DescriptionAnnotation,
EnumAnnotation,
ExpertAnnotation,
GroupAnnotation,
MoveAnnotation,
OmittedAnnotation,
OptionalAnnotation,
RemoveAnnotation,
RenameAnnotation,
RequiredAnnotation,
TodoAnnotation,
ValueAnnotation,
)


def are_semantic_equal(
annotation_a: AbstractAnnotation, annotation_b: AbstractAnnotation
) -> bool:
if (
annotation_a.target == annotation_b.target
and isinstance(annotation_a, type(annotation_b))
and isinstance(annotation_b, type(annotation_a))
):
if isinstance(annotation_a, BoundaryAnnotation) and isinstance(
annotation_b, BoundaryAnnotation
):
return annotation_a.interval == annotation_b.interval
if isinstance(annotation_a, CalledAfterAnnotation) and isinstance(
annotation_b, CalledAfterAnnotation
):
return annotation_a.calledAfterName == annotation_b.calledAfterName
if isinstance(annotation_a, DescriptionAnnotation) and isinstance(
annotation_b, DescriptionAnnotation
):
return annotation_a.newDescription == annotation_b.newDescription
if (
isinstance(annotation_a, EnumAnnotation)
and isinstance(annotation_b, EnumAnnotation)
and annotation_a.enumName == annotation_b.enumName
and len(annotation_a.pairs) == len(annotation_a.pairs)
):
list_a = sorted(list(annotation_a.pairs), key=lambda x: x.stringValue)
list_b = sorted(list(annotation_b.pairs), key=lambda x: x.stringValue)
for i in range(len(annotation_a.pairs)):
if (
list_a[i].stringValue != list_b[i].stringValue
or list_a[i].instanceName != list_b[i].instanceName
):
return False
return True
if isinstance(annotation_a, ExpertAnnotation) and isinstance(
annotation_b, ExpertAnnotation
):
return True
if isinstance(annotation_a, GroupAnnotation) and isinstance(
annotation_b, GroupAnnotation
):
return annotation_a.groupName == annotation_b.groupName and set(
annotation_a.parameters
) == set(annotation_b.parameters)
if isinstance(annotation_a, MoveAnnotation) and isinstance(
annotation_b, MoveAnnotation
):
return annotation_a.destination == annotation_b.destination
if isinstance(annotation_a, RemoveAnnotation) and isinstance(
annotation_b, RemoveAnnotation
):
return True
if isinstance(annotation_a, RenameAnnotation) and isinstance(
annotation_b, RenameAnnotation
):
return annotation_a.newName == annotation_b.newName
if isinstance(annotation_a, TodoAnnotation) and isinstance(
annotation_b, TodoAnnotation
):
return annotation_a.newTodo == annotation_b.newTodo
if (
isinstance(annotation_a, ValueAnnotation)
and isinstance(annotation_b, ValueAnnotation)
and annotation_a.variant == annotation_b.variant
):
if isinstance(annotation_a, ConstantAnnotation) and isinstance(
annotation_b, ConstantAnnotation
):
return (
annotation_a.defaultValue == annotation_b.defaultValue
and annotation_a.defaultValueType == annotation_b.defaultValueType
)
if isinstance(annotation_a, OptionalAnnotation) and isinstance(
annotation_b, OptionalAnnotation
):
return (
annotation_a.defaultValue == annotation_b.defaultValue
and annotation_a.defaultValueType == annotation_b.defaultValueType
)
if isinstance(annotation_a, OmittedAnnotation) and isinstance(
annotation_b, OmittedAnnotation
):
return True
if isinstance(annotation_a, RequiredAnnotation) and isinstance(
annotation_b, RequiredAnnotation
):
return True
return False
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,18 @@ def from_json(json: Any) -> Interval:
json["upperLimitType"],
)

def __eq__(self, other: Any) -> bool:
return (
isinstance(other, Interval)
and self.isDiscrete == other.isDiscrete
and self.lowerIntervalLimit == other.lowerIntervalLimit
and isinstance(self.lowerIntervalLimit, type(self.lowerIntervalLimit))
and self.lowerLimitType == other.lowerLimitType
and self.upperIntervalLimit == other.upperIntervalLimit
and isinstance(self.upperIntervalLimit, type(self.upperIntervalLimit))
and self.upperLimitType == self.upperLimitType
)


@dataclass
class BoundaryAnnotation(AbstractAnnotation):
Expand Down Expand Up @@ -122,6 +134,13 @@ def to_json(self) -> dict:
def from_json(json: Any) -> EnumPair:
return EnumPair(json["stringValue"], json["instanceName"])

def __eq__(self, other: Any) -> bool:
return (
isinstance(other, EnumPair)
and self.stringValue == other.stringValue
and self.instanceName == other.instanceName
)


@dataclass
class EnumAnnotation(AbstractAnnotation):
Expand Down Expand Up @@ -311,7 +330,9 @@ class ParameterInfo:
value: str
value_type: str

def __init__(self, parameter_type, value="", value_type=""):
def __init__(
self, parameter_type: ParameterType, value: str = "", value_type: str = ""
) -> None:
self.type = parameter_type
self.value = value
self.value_type = value_type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
SimpleDiffer,
)

from ._migrate import migrate_annotations
from ._migrate import Migration
Loading