cmake: fix pylint/flake8 detection, update flake8 exclude

This commit is contained in:
Alexander Alekhin 2021-01-29 16:59:13 +00:00
parent ebd91459f2
commit e448f4f6ef
3 changed files with 26 additions and 9 deletions

View File

@ -727,8 +727,15 @@ if(ENABLE_FLAKE8 AND PYTHON_DEFAULT_AVAILABLE)
include("${CMAKE_CURRENT_LIST_DIR}/cmake/FindFlake8.cmake")
endif()
if(FLAKE8_FOUND)
list(APPEND OPENCV_FLAKE8_EXCLUDES ".git" "__pycache__" "config.py" "*.config.py" "config-*.py")
list(APPEND OPENCV_FLAKE8_EXCLUDES "svgfig.py") # 3rdparty
if(NOT PYTHON3_VERSION_STRING VERSION_GREATER 3.6)
# Python 3.6+ (PEP 526): variable annotations (type hints)
list(APPEND OPENCV_FLAKE8_EXCLUDES "samples/dnn/dnn_model_runner/dnn_conversion/common/test/configs")
endif()
string(REPLACE ";" "," OPENCV_FLAKE8_EXCLUDES_STR "${OPENCV_FLAKE8_EXCLUDES}")
add_custom_target(check_flake8
COMMAND "${FLAKE8_EXECUTABLE}" . --count --select=E9,E901,E999,F821,F822,F823 --show-source --statistics --exclude='.git,__pycache__,*.config.py,svgfig.py'
COMMAND "${FLAKE8_EXECUTABLE}" . --count --select=E9,E901,E999,F821,F822,F823 --show-source --statistics --exclude='${OPENCV_FLAKE8_EXCLUDES_STR}'
WORKING_DIRECTORY "${OpenCV_SOURCE_DIR}"
COMMENT "Running flake8"
)

View File

@ -12,9 +12,11 @@
find_host_program(FLAKE8_EXECUTABLE flake8 PATHS /usr/bin)
if(FLAKE8_EXECUTABLE)
execute_process(COMMAND ${FLAKE8_EXECUTABLE} --version OUTPUT_VARIABLE FLAKE8_VERSION_RAW ERROR_QUIET)
if(FLAKE8_VERSION_RAW MATCHES "^([0-9\\.]+[0-9])")
if(FLAKE8_EXECUTABLE AND NOT DEFINED FLAKE8_VERSION)
execute_process(COMMAND ${FLAKE8_EXECUTABLE} --version RESULT_VARIABLE _result OUTPUT_VARIABLE FLAKE8_VERSION_RAW)
if(NOT _result EQUAL 0)
ocv_clear_vars(FLAKE8_EXECUTABLE FLAKE8_VERSION)
elseif(FLAKE8_VERSION_RAW MATCHES "^([0-9\\.]+[0-9])")
set(FLAKE8_VERSION "${CMAKE_MATCH_1}")
else()
set(FLAKE8_VERSION "unknown")
@ -22,6 +24,9 @@ if(FLAKE8_EXECUTABLE)
endif()
include(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Flake8 DEFAULT_MSG FLAKE8_EXECUTABLE)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Flake8
REQUIRED_VARS FLAKE8_EXECUTABLE
VERSION_VAR FLAKE8_VERSION
)
mark_as_advanced(FLAKE8_EXECUTABLE FLAKE8_VERSION)

View File

@ -12,9 +12,11 @@
find_host_program(PYLINT_EXECUTABLE pylint PATHS /usr/bin)
if(PYLINT_EXECUTABLE)
execute_process(COMMAND ${PYLINT_EXECUTABLE} --version OUTPUT_VARIABLE PYLINT_VERSION_RAW ERROR_QUIET)
if(PYLINT_VERSION_RAW MATCHES "pylint([^,]*) ([0-9\\.]+[0-9])")
if(PYLINT_EXECUTABLE AND NOT DEFINED PYLINT_VERSION)
execute_process(COMMAND ${PYLINT_EXECUTABLE} --version RESULT_VARIABLE _result OUTPUT_VARIABLE PYLINT_VERSION_RAW)
if(NOT _result EQUAL 0)
ocv_clear_vars(PYLINT_EXECUTABLE PYLINT_VERSION)
elseif(PYLINT_VERSION_RAW MATCHES "pylint([^,]*) ([0-9\\.]+[0-9])")
set(PYLINT_VERSION "${CMAKE_MATCH_2}")
else()
set(PYLINT_VERSION "unknown")
@ -22,6 +24,9 @@ if(PYLINT_EXECUTABLE)
endif()
include(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Pylint DEFAULT_MSG PYLINT_EXECUTABLE)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Pylint
REQUIRED_VARS PYLINT_EXECUTABLE
VERSION_VAR PYLINT_VERSION
)
mark_as_advanced(PYLINT_EXECUTABLE PYLINT_VERSION)