Skip to content

get_migration_text

Source code in library_analyzer/processing/migration/annotations/_get_migration_text.py
def get_migration_text(
    annotation: AbstractAnnotation,
    mapping: Mapping,
    for_todo_annotation: bool = False,
    additional_information: Any = None,
) -> str:
    class_name = str(annotation.__class__.__name__)
    if class_name.endswith("Annotation"):
        class_name = class_name[:-10]
    if issubclass(type(annotation), ValueAnnotation):
        class_name = "Value"
    migrate_text = (
        "The @" + class_name + " Annotation" + _get_further_information(annotation)
    )
    migrate_text += (
        " from the previous version was at '"
        + annotation.target
        + "' and the possible alternatives in the new version of the api are: "
        + _list_api_elements(mapping.get_apiv2_elements())
    )
    if additional_information is not None and isinstance(additional_information, list):
        functions = [
            function
            for function in additional_information
            if isinstance(function, Function)
        ]
        if len(functions) > 0:
            migrate_text += (
                " and the possible replacements (" + _list_api_elements(functions) + ")"
            )

        parameters = [
            parameter
            for parameter in additional_information
            if isinstance(parameter, Parameter)
        ]
        if len(parameters) > 0:
            migrate_text += (
                " and the possible replacements ("
                + _list_api_elements(parameters)
                + ")"
            )
    migration_text = migrate_text
    if for_todo_annotation:
        return migration_text
    if len(annotation.comment) == 0:
        return migration_text
    return annotation.comment + "\n" + migration_text