From b49ee86ae8ad769aaa83728f9d8bc5c78e4e3498 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rton=20Csord=C3=A1s?= Date: Wed, 27 Nov 2019 11:01:38 +0100 Subject: [PATCH] [pylint] Fix undefined variable to thrift types - We run pylint on analyzer/web directory separately and we give the same `--rcfile` option to both command. This configuration file contains an `init-hook` setting where we add multiple directories to the `sys.path`. Unfortunatelly these paths will be added relative to the directory where the pylint command will be executed. To solve this problem we will set the `PYLINTRC` environment variable instead of using the `--rcfile` option. In the init-hook we can get this variable, get the directory where this file can be found and add absolute paths instead of relatives to the sys.path. - Add `thrift` target as a dependency of pylint command in web module. - Fix undefined variable errors reported by pylint. --- .pylintrc | 17 ++++++++++------- Makefile | 2 +- analyzer/tests/Makefile | 4 ++-- web/tests/Makefile | 18 +++++++++--------- .../functional/db_cleanup/test_db_cleanup.py | 2 +- .../detection_status/test_detection_status.py | 2 +- .../report_viewer_api/test_report_counting.py | 3 ++- .../report_viewer_api/test_report_filter.py | 3 ++- .../review_status/test_review_status.py | 2 +- .../suppress/test_suppress_generation.py | 2 +- 10 files changed, 30 insertions(+), 25 deletions(-) diff --git a/.pylintrc b/.pylintrc index 9d6636a962..b7fa66bb6a 100644 --- a/.pylintrc +++ b/.pylintrc @@ -5,13 +5,16 @@ # Python code to execute, usually for sys.path manipulation such as # pygtk.require(). -init-hook='import sys; - sys.path.append("build/thrift/v6/gen-py"); - sys.path.append("tools/plist_to_html"); - sys.path.append("analyzer"); - sys.path.append("web"); - sys.path.append("web/client"); - sys.path.append("web/server");' +init-hook='import os, sys, pylint; + + root_dir = os.path.basename(pylint.config.PYLINTRC); + + sys.path.append(os.path.join(root_dir, "tools/plist_to_html")); + sys.path.append(os.path.join(root_dir, "analyzer")); + sys.path.append(os.path.join(root_dir, "web")); + sys.path.append(os.path.join(root_dir, "web/build/thrift/v6/gen-py")); + sys.path.append(os.path.join(root_dir, "web/client")); + sys.path.append(os.path.join(root_dir, "web/server"));' # Add files or directories to the blacklist. They should be base names, not # paths. diff --git a/Makefile b/Makefile index 27c477c73a..833db2de76 100644 --- a/Makefile +++ b/Makefile @@ -163,7 +163,7 @@ PYLINT_CMD = $(MAKE) -C $(CC_ANALYZER) pylint && \ --rcfile=$(ROOT)/.pylintrc pylint: - $(PYLINT_CMD) + PYLINTRC=$(ROOT)/.pylintrc $(PYLINT_CMD) pylint_in_env: venv_dev $(ACTIVATE_DEV_VENV) && $(PYLINT_CMD) diff --git a/analyzer/tests/Makefile b/analyzer/tests/Makefile index 053e6d4f2e..4412bdfb04 100644 --- a/analyzer/tests/Makefile +++ b/analyzer/tests/Makefile @@ -20,8 +20,8 @@ pycodestyle: pycodestyle_in_env: venv_dev $(ACTIVATE_DEV_VENV) && $(PYCODESTYLE_TEST_CMD) -PYLINT_TEST_CMD = pylint ./bin/** ./codechecker_analyzer ./tests/** \ - --rcfile=$(ROOT)/.pylintrc +PYLINT_TEST_CMD = PYLINTRC=$(ROOT)/.pylintrc \ + pylint ./bin/** ./codechecker_analyzer ./tests/** pylint: $(PYLINT_TEST_CMD) diff --git a/web/tests/Makefile b/web/tests/Makefile index b8395a0084..826dac96ff 100644 --- a/web/tests/Makefile +++ b/web/tests/Makefile @@ -39,17 +39,17 @@ pycodestyle: pycodestyle_in_env: venv_dev $(ACTIVATE_DEV_VENV) && $(PYCODESTYLE_TEST_CMD) -PYLINT_TEST_CMD = pylint ./bin/** \ - ./codechecker_web \ - ./client/bin/** ./client/codechecker_client \ - ./server/bin/** ./server/codechecker_server ./server/tests/unit \ - ./tests/functional ./tests/libtest ./tests/tools \ - --rcfile=$(ROOT)/.pylintrc +PYLINT_TEST_CMD = PYLINTRC=$(ROOT)/.pylintrc \ + pylint ./bin/** \ + ./codechecker_web \ + ./client/bin/** ./client/codechecker_client \ + ./server/bin/** ./server/codechecker_server ./server/tests/unit \ + ./tests/functional ./tests/libtest ./tests/tools -pylint: - $(PYLINT_TEST_CMD) +pylint: thrift + $(PYLINT_TEST_CMD) -pylint_in_env: +pylint_in_env: thrift $(ACTIVATE_DEV_VENV) && $(PYLINT_TEST_CMD) CODECHECKER_CMD = $(BUILD_DIR)/CodeChecker/bin/CodeChecker diff --git a/web/tests/functional/db_cleanup/test_db_cleanup.py b/web/tests/functional/db_cleanup/test_db_cleanup.py index 10ee1575d0..7c76c76472 100644 --- a/web/tests/functional/db_cleanup/test_db_cleanup.py +++ b/web/tests/functional/db_cleanup/test_db_cleanup.py @@ -18,7 +18,7 @@ import unittest from shutil import copyfile, rmtree -from codeCheckerDBAccess_v6.ttypes import * +from codeCheckerDBAccess_v6.ttypes import RunFilter, Severity from libtest import codechecker from libtest import env diff --git a/web/tests/functional/detection_status/test_detection_status.py b/web/tests/functional/detection_status/test_detection_status.py index eb17380d2f..16d4acace0 100644 --- a/web/tests/functional/detection_status/test_detection_status.py +++ b/web/tests/functional/detection_status/test_detection_status.py @@ -13,7 +13,7 @@ import os import unittest -from codeCheckerDBAccess_v6.ttypes import * +from codeCheckerDBAccess_v6.ttypes import DetectionStatus, Encoding from libtest import codechecker from libtest import env diff --git a/web/tests/functional/report_viewer_api/test_report_counting.py b/web/tests/functional/report_viewer_api/test_report_counting.py index 5dda20e915..b8967fac3e 100644 --- a/web/tests/functional/report_viewer_api/test_report_counting.py +++ b/web/tests/functional/report_viewer_api/test_report_counting.py @@ -16,7 +16,8 @@ import os import unittest -from codeCheckerDBAccess_v6.ttypes import * +from codeCheckerDBAccess_v6.ttypes import DetectionStatus, ReportFilter, \ + ReviewStatus, Severity from libtest import env diff --git a/web/tests/functional/report_viewer_api/test_report_filter.py b/web/tests/functional/report_viewer_api/test_report_filter.py index 217e16a78c..c064ff7e14 100644 --- a/web/tests/functional/report_viewer_api/test_report_filter.py +++ b/web/tests/functional/report_viewer_api/test_report_filter.py @@ -15,7 +15,8 @@ import os import unittest -from codeCheckerDBAccess_v6.ttypes import * +from codeCheckerDBAccess_v6.ttypes import BugPathLengthRange, ReportFilter, \ + ReviewStatus, Severity from libtest import env diff --git a/web/tests/functional/review_status/test_review_status.py b/web/tests/functional/review_status/test_review_status.py index 839742dfaf..4b81c3701b 100644 --- a/web/tests/functional/review_status/test_review_status.py +++ b/web/tests/functional/review_status/test_review_status.py @@ -14,7 +14,7 @@ import os import unittest -from codeCheckerDBAccess_v6.ttypes import * +from codeCheckerDBAccess_v6.ttypes import ReviewStatus from libtest import env from libtest.thrift_client_to_db import get_all_run_results diff --git a/web/tests/functional/suppress/test_suppress_generation.py b/web/tests/functional/suppress/test_suppress_generation.py index 6e337648e8..a1062c04d1 100644 --- a/web/tests/functional/suppress/test_suppress_generation.py +++ b/web/tests/functional/suppress/test_suppress_generation.py @@ -18,7 +18,7 @@ from subprocess import CalledProcessError import unittest -from codeCheckerDBAccess_v6.ttypes import * +from codeCheckerDBAccess_v6.ttypes import ReviewStatus from libtest import env from libtest import codechecker