Repository: stfc/PSyclone

Issue:
Create dynamop3 compatibility layer
Recently all lfric transformations have been renamed from using `Dynamo0p3` to using `LFRic` as prefix. Since this breaks all LFRic builds, we need to create a (temporary) compatibility layer that provides the old names with a deprecation warning.

Discussion:

Solution patch:
diff --git a/src/psyclone/transformations.py b/src/psyclone/transformations.py
index 3a0d902ae..17289d969 100644
--- a/src/psyclone/transformations.py
+++ b/src/psyclone/transformations.py
@@ -3129,6 +3129,28 @@ class KernelImportsToArguments(Transformation):
             node.modified = True
 
 
+# Create a compatibility layer for all existing Dynamo0p3 transformation
+# names. These are just derived classes from the new name which print
+# a deprecation message when creating an instance
+for name in ["OMPParallelLoopTrans",
+             "OMPLoopTrans",
+             "ColourTrans",
+             "RedundantComputationTrans",
+             "AsyncHaloExchangeTrans",
+             "KernelConstTrans"]:
+    class_string = f"""
+class Dynamo0p3{name}(LFRic{name}):
+
+    def __new__(cls):
+        print("Deprecation warning: the script uses the legacy name "
+              "'Dynamo0p3{name}', please use new name "
+              "'LFRic{name}' instead.")
+        return super().__new__(cls)
+        """
+    # pylint: disable=exec-used
+    exec(class_string)
+
+
 # For Sphinx AutoAPI documentation generation
 __all__ = [
    "ACCEnterDataTrans",


Test patch:
diff --git a/src/psyclone/tests/domain/lfric/transformations/lfric_transformations_test.py b/src/psyclone/tests/domain/lfric/transformations/lfric_transformations_test.py
index 5caa2a1d1..a787d4b84 100644
--- a/src/psyclone/tests/domain/lfric/transformations/lfric_transformations_test.py
+++ b/src/psyclone/tests/domain/lfric/transformations/lfric_transformations_test.py
@@ -7991,3 +7991,29 @@ def test_colour_trans_tiled_continuous_writer_intergrid(dist_mem):
     # TODO #2623: To compile it needs an up-to-date lfric infrastructure with
     # the new tile-colouring methods
     # assert LFRicBuild(tmpdir).code_compiles(psy)
+
+
+def test_deprecated_names(capsys):
+    '''
+    Check that the old Dynamo0p3-based transformation names are still
+    accepted, but will print a deprecation message when they are
+    instantiated.
+    '''
+
+    # Since these names are deprecated, they are imported in this one test
+    # only, to make it easier to remove them later all at once
+    # pylint: disable=no-name-in-module, import-outside-toplevel
+    from psyclone.transformations import (
+        Dynamo0p3OMPParallelLoopTrans, Dynamo0p3OMPLoopTrans,
+        Dynamo0p3ColourTrans, Dynamo0p3RedundantComputationTrans,
+        Dynamo0p3AsyncHaloExchangeTrans)
+    for trans_cls in [Dynamo0p3OMPParallelLoopTrans, Dynamo0p3OMPLoopTrans,
+                      Dynamo0p3ColourTrans, Dynamo0p3RedundantComputationTrans,
+                      Dynamo0p3AsyncHaloExchangeTrans]:
+        old_name = trans_cls.__name__
+        new_name = old_name.replace("Dynamo0p3", "LFRic")
+        _ = trans_cls()
+        out, _ = capsys.readouterr()
+        assert (f"Deprecation warning: the script uses the legacy name "
+                f"'{old_name}', please use new name "
+                f"'{new_name}' instead.") in out