Skip to content

Commit

Permalink
[pylint] Fix undefined variable to thrift types
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
csordasmarton committed Nov 27, 2019
1 parent b8bb8b9 commit b49ee86
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 25 deletions.
17 changes: 10 additions & 7 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions analyzer/tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 9 additions & 9 deletions web/tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion web/tests/functional/db_cleanup/test_db_cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion web/tests/functional/report_viewer_api/test_report_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion web/tests/functional/review_status/test_review_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion web/tests/functional/suppress/test_suppress_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b49ee86

Please sign in to comment.