1 if(COMMAND ocv_pylint_add_target)
5 find_package(Pylint QUIET)
6 if(NOT PYLINT_FOUND OR NOT PYLINT_EXECUTABLE)
7 include("${CMAKE_CURRENT_LIST_DIR}/FindPylint.cmake")
11 macro(ocv_pylint_add_target) # dummy
16 macro(ocv_pylint_cleanup)
17 foreach(__id ${PYLINT_TARGET_ID})
19 PYLINT_TARGET_${__id}_CWD
20 PYLINT_TARGET_${__id}_TARGET
21 PYLINT_TARGET_${__id}_RCFILE
22 PYLINT_TARGET_${__id}_OPTIONS
25 ocv_clear_vars(PYLINT_TARGET_ID)
29 macro(ocv_pylint_add_target)
30 cmake_parse_arguments(__pylint "" "CWD;TARGET;RCFILE;" "OPTIONS" ${ARGN})
31 if(__pylint_UNPARSED_ARGUMENTS)
32 message(WARNING "Unsupported arguments: ${__pylint_UNPARSED_ARGUMENTS}
33 (keep versions of opencv/opencv_contrib synchronized)
36 ocv_assert(__pylint_TARGET)
37 set(__cwd ${__pylint_CWD})
38 if(__cwd STREQUAL "default")
39 get_filename_component(__cwd "${__pylint_TARGET}" DIRECTORY)
41 set(__rcfile ${__pylint_RCFILE})
42 if(NOT __rcfile AND NOT __pylint_OPTIONS)
44 set(__path "${__cwd}")
46 get_filename_component(__path "${__pylint_TARGET}" DIRECTORY)
48 while(__path MATCHES "^${CMAKE_SOURCE_DIR}")
49 if(EXISTS "${__path}/pylintrc")
50 set(__rcfile "${__path}/pylintrc")
53 if(EXISTS "${__path}/.pylintrc")
54 set(__rcfile "${__path}/.pylintrc")
57 get_filename_component(__path "${__path}" DIRECTORY)
60 set(__rcfile "${CMAKE_BINARY_DIR}/pylintrc")
64 list(LENGTH PYLINT_TARGET_ID __id)
65 list(APPEND PYLINT_TARGET_ID ${__id})
66 set(PYLINT_TARGET_ID "${PYLINT_TARGET_ID}" CACHE INTERNAL "")
67 set(PYLINT_TARGET_${__id}_CWD "${__cwd}" CACHE INTERNAL "")
68 set(PYLINT_TARGET_${__id}_TARGET "${__pylint_TARGET}" CACHE INTERNAL "")
69 set(PYLINT_TARGET_${__id}_RCFILE "${__rcfile}" CACHE INTERNAL "")
70 set(PYLINT_TARGET_${__id}_OPTIONS "${__pylint_options}" CACHE INTERNAL "")
73 macro(ocv_pylint_add_directory_recurse __path)
74 file(GLOB_RECURSE __python_scripts ${__path}/*.py)
75 list(LENGTH __python_scripts __total)
77 message(WARNING "Pylint: Python files are not found: ${__path}")
79 foreach(__script ${__python_scripts})
80 ocv_pylint_add_target(TARGET ${__script} ${ARGN})
84 macro(ocv_pylint_add_directory __path)
85 file(GLOB __python_scripts ${__path}/*.py)
86 list(LENGTH __python_scripts __total)
88 message(WARNING "Pylint: Python files are not found: ${__path}")
90 foreach(__script ${__python_scripts})
91 ocv_pylint_add_target(TARGET ${__script} ${ARGN})
95 function(ocv_pylint_finalize)
100 file(COPY "${CMAKE_SOURCE_DIR}/platforms/scripts/pylintrc" DESTINATION "${CMAKE_BINARY_DIR}")
102 set(PYLINT_CONFIG_SCRIPT "")
103 ocv_cmake_script_append_var(PYLINT_CONFIG_SCRIPT
108 foreach(__id ${PYLINT_TARGET_ID})
109 ocv_cmake_script_append_var(PYLINT_CONFIG_SCRIPT
110 PYLINT_TARGET_${__id}_CWD
111 PYLINT_TARGET_${__id}_TARGET
112 PYLINT_TARGET_${__id}_RCFILE
113 PYLINT_TARGET_${__id}_OPTIONS
115 list(APPEND __sources ${PYLINT_TARGET_${__id}_TARGET} ${PYLINT_TARGET_${__id}_RCFILE})
117 list(REMOVE_DUPLICATES __sources)
119 list(LENGTH PYLINT_TARGET_ID __total)
120 set(PYLINT_TOTAL_TARGETS "${__total}" CACHE INTERNAL "")
121 message(STATUS "Pylint: registered ${__total} targets. Build 'check_pylint' target to run checks (\"cmake --build . --target check_pylint\" or \"make check_pylint\")")
122 configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/pylint.cmake.in" "${CMAKE_BINARY_DIR}/pylint.cmake" @ONLY)
124 add_custom_target(check_pylint
125 COMMAND ${CMAKE_COMMAND} -P "${CMAKE_BINARY_DIR}/pylint.cmake"
126 COMMENT "Running pylint"