You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by ka...@apache.org on 2021/01/20 17:44:34 UTC

[airflow] branch v1-10-stable updated: Created CustomExecutorsRequireFullPathRule class (#13678)

This is an automated email from the ASF dual-hosted git repository.

kaxilnaik pushed a commit to branch v1-10-stable
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/v1-10-stable by this push:
     new fb84ebe  Created CustomExecutorsRequireFullPathRule class (#13678)
fb84ebe is described below

commit fb84ebe9372c593c6a74872bd3118fdd250e0867
Author: Dr. Dennis Akpenyi <de...@gmail.com>
AuthorDate: Wed Jan 20 18:44:21 2021 +0100

    Created CustomExecutorsRequireFullPathRule class (#13678)
    
    closes: #11053
---
 .../custom_executors_require_full_path_rule.py     | 43 ++++++++++++++++++
 ...test_custom_executors_require_full_path_rule.py | 53 ++++++++++++++++++++++
 2 files changed, 96 insertions(+)

diff --git a/airflow/upgrade/rules/custom_executors_require_full_path_rule.py b/airflow/upgrade/rules/custom_executors_require_full_path_rule.py
new file mode 100644
index 0000000..af19543
--- /dev/null
+++ b/airflow/upgrade/rules/custom_executors_require_full_path_rule.py
@@ -0,0 +1,43 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+from airflow.upgrade.rules.base_rule import BaseRule
+
+
+class CustomExecutorsRequireFullPathRule(BaseRule):
+    """
+    CustomExecutorsRequireFullPathRule class to ease upgrade to Airflow 2.0
+    """
+    title = "Custom Executors now require full path"
+    description = """\
+In Airflow-2.0, loading custom executors via plugins is no longer required.
+To load a custom executor, you have to provide a full path to the the custom executor module.
+                  """
+
+    def check(self):
+        from airflow.plugins_manager import executors_modules
+        if executors_modules:
+            return (
+                "Deprecation Warning: Found Custom Executor imported via a plugin."
+                "From Airflow 2.0, you should use regular Python Modules to import Custom Executor."
+                "You should provide a full path to the the custom executor module."
+                "See the link below for more details:"
+                "https://github.com/apache/airflow/blob/2.0.0/"
+                "UPDATING.md#custom-executors-is-loaded-using-full-import-path \n"
+                "Following Executors were imported using Plugins: \n"
+                "{}".format(executors_modules)
+            )
diff --git a/tests/upgrade/rules/test_custom_executors_require_full_path_rule.py b/tests/upgrade/rules/test_custom_executors_require_full_path_rule.py
new file mode 100644
index 0000000..f1674ea
--- /dev/null
+++ b/tests/upgrade/rules/test_custom_executors_require_full_path_rule.py
@@ -0,0 +1,53 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+from unittest import TestCase
+
+from airflow.upgrade.rules.custom_executors_require_full_path_rule import CustomExecutorsRequireFullPathRule
+from tests.compat import patch
+
+
+class TestCustomExecutorsRequireFullPath(TestCase):
+    @patch('airflow.plugins_manager.executors_modules',
+           ["my_plugin.MyCustomExecutor", "my_acme.executors.MyCustomExecutor"])
+    def test_invalid_check(self):
+        rule = CustomExecutorsRequireFullPathRule()
+
+        assert isinstance(rule.title, str)
+        assert isinstance(rule.description, str)
+
+        msg = (
+            "Deprecation Warning: Found Custom Executor imported via a plugin."
+            "From Airflow 2.0, you should use regular Python Modules to import Custom Executor."
+            "You should provide a full path to the the custom executor module."
+            "See the link below for more details:"
+            "https://github.com/apache/airflow/blob/2.0.0/"
+            "UPDATING.md#custom-executors-is-loaded-using-full-import-path \n"
+            "Following Executors were imported using Plugins: \n"
+            "['my_plugin.MyCustomExecutor', 'my_acme.executors.MyCustomExecutor']"
+        )
+
+        assert msg == rule.check()
+
+    @patch('airflow.plugins_manager.executors_modules', [])
+    def test_check(self):
+        rule = CustomExecutorsRequireFullPathRule()
+
+        assert isinstance(rule.title, str)
+        assert isinstance(rule.description, str)
+
+        assert rule.check() is None