You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2019/05/05 19:24:28 UTC

[GitHub] [airflow] potiuk commented on a change in pull request #5238: [AIRFLOW-4364] Add Pylint to CI

potiuk commented on a change in pull request #5238: [AIRFLOW-4364] Add Pylint to CI
URL: https://github.com/apache/airflow/pull/5238#discussion_r281034413
 
 

 ##########
 File path: scripts/ci/ci_pylint.py
 ##########
 @@ -0,0 +1,104 @@
+# 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.
+
+"""This script runs Pylint and filters out only the changed lines."""
+# TODO remove this script once the complete Airflow codebase is Pylint compatible.
+
+import os
+import re
+import subprocess
+import sys
+from io import StringIO
+
+from collections import defaultdict
+from pathlib import Path
+
+from pylint import lint
+from pylint.reporters.text import ColorizedTextReporter
+
+# Get Python files to run Pylint against.
+# Git command from https://github.com/sk-/git-lint/blob/master/gitlint/git.py
+git_modified_files_cmd = "git status --porcelain --untracked-files=all --ignore-submodules=all".split()
+status_lines = subprocess.check_output(git_modified_files_cmd).decode("utf-8").splitlines()
+accepted_modes = ["M", "A", "AM", "MM", "??"]
+accepted_modes_regex = "|".join([re.escape(mode) for mode in accepted_modes])
+regex = r"\s?({0})\s*(?P<filename>.+)$".format(accepted_modes_regex)
+py_files_to_check = set()
+for line in status_lines:
+    regex_match = re.match(regex, line)
+    filename = regex_match.group("filename")
+    if filename.endswith(".py"):
+        py_files_to_check.add(filename)
+
+# Get lines to run Pylint against.
+# Note: check unstaged lines! So use this script in combination with ci_pylint.sh.
+filename_lines = defaultdict(list)
+for filename in py_files_to_check:
+    git_blame_cmd = "git blame --porcelain {0}".format(filename).split()
+    try:
+        with open(os.devnull, "w") as devnull:
+            blame_lines = subprocess.check_output(git_blame_cmd, stderr=devnull).decode("utf-8").splitlines()
+    except Exception:  # pylint: disable=broad-except
+        # Raised if new file -> no history. Set linenumbers to None.
+        filename_lines[filename] = None
+        continue
+
+    # We only check lines starting with 40 zeros. Therefore run this script only from ci_pylint.sh
 
 Review comment:
   I had to figure out that 40 zeros means "not-yet-committed". Maybe we should mention that this is the intention

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services