digitalsimboja commented on a change in pull request #14400:
URL: https://github.com/apache/airflow/pull/14400#discussion_r588970002



##########
File path: airflow/upgrade/rules/fix_conf_not_importable_from_airflow.py
##########
@@ -0,0 +1,64 @@
+
+# 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
+from airflow import conf
+from airflow.utils.dag_processing import list_py_file_paths
+
+
+class ProperlyImportConfFromAirflow(BaseRule):
+    """
+      ProperlyImportConfFromAirflow class to ensure proper import of conf to 
work in Airflow 2.0
+      """
+    title = "Ensure Users Properly Import conf from Airflow"
+    description = """\
+    In Airflow-2.0, it's not possible to import `conf` from airflow by using 
`import conf from airflow`
+    To ensure your code works in Airflow 2.0, you should use `from 
airflow.configuration import conf`.
+                      """
+
+    wrong_conf_import = "from airflow import conf"
+    proper_conf_import = "from airflow.configuration import conf"
+
+    def _conf_import_info(self, file_path, line_number):
+        return "Warning: In Airflow 2.0, it's not possible to import `conf` by 
using `{}`. " \
+               "To ensure your code works in Airflow 2.0, you should use 
`{}`." \
+               " Affected file: {} (line {})".format(
+                self.wrong_conf_import, self.proper_conf_import, file_path, 
line_number
+                )

Review comment:
       Yes that is correct. I will go ahead and return only the affected file 
and line in this section. Thanks




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to