diff --git a/cmake/FindPylint.cmake b/cmake/FindPylint.cmake new file mode 100644 index 0000000000..a8b870fe20 --- /dev/null +++ b/cmake/FindPylint.cmake @@ -0,0 +1,27 @@ +# - Find Pylint +# Find the Pylint executable and extract the version number +# +# OUTPUT Variables +# +# PYLINT_FOUND +# True if the pylint package was found +# PYLINT_EXECUTABLE +# The pylint executable location +# PYLINT_VERSION +# A string denoting the version of pylint that has been found + +find_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) + string(REGEX REPLACE "^pylint ([0-9]+.[0-9]+.[0-9]+),.*" "\\1" PYLINT_VERSION ${PYLINT_VERSION_RAW}) + else() + set(PYLINT_VERSION "unknown") + endif() +endif() + +include(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(Pylint DEFAULT_MSG PYLINT_EXECUTABLE) + +mark_as_advanced(PYLINT_EXECUTABLE PYLINT_VERSION) diff --git a/doc/tutorials/introduction/documenting_opencv/documentation_tutorial.markdown b/doc/tutorials/introduction/documenting_opencv/documentation_tutorial.markdown index c51d7bef36..7549ea9dad 100644 --- a/doc/tutorials/introduction/documenting_opencv/documentation_tutorial.markdown +++ b/doc/tutorials/introduction/documenting_opencv/documentation_tutorial.markdown @@ -43,6 +43,10 @@ Generate documentation {#tutorial_documentation_generate} make doxygen @endcode - Open doc/doxygen/html/index.html file in your favorite browser +- Test your python code: + @code{.sh} + make run_pylint_on_tutorials + @endcode Quick start {#tutorial_documentation_quick_start} =========== @@ -600,7 +604,8 @@ Document the function {#tutorial_documentation_steps_fun} 6. _Optional_: describe return value of the function using the _returns_ command. 7. _Optional_: add "See also" section with links to similar functions or classes 8. _Optional_: add bibliographic reference if any. -9. Generate doxygen documentation and verify results. +9. Test your code. (Python: "make run_pylint_on_tutorials") +10. Generate doxygen documentation and verify results. Write the tutorial {#tutorial_documentation_steps_tutorial} ------------------ diff --git a/samples/CMakeLists.txt b/samples/CMakeLists.txt index 1ce0489f1a..06cdae364b 100644 --- a/samples/CMakeLists.txt +++ b/samples/CMakeLists.txt @@ -12,6 +12,7 @@ if(NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_LIST_DIR) add_subdirectory(cpp) add_subdirectory(java/tutorial_code) +add_subdirectory(python/tutorial_code) add_subdirectory(dnn) add_subdirectory(gpu) add_subdirectory(tapi) diff --git a/samples/python/tutorial_code/CMakeLists.txt b/samples/python/tutorial_code/CMakeLists.txt new file mode 100644 index 0000000000..c456ffc7e9 --- /dev/null +++ b/samples/python/tutorial_code/CMakeLists.txt @@ -0,0 +1,23 @@ +# ---------------------------------------------------------------------------- +# CMake file to run pylint on the tutorial python files. +# +# ---------------------------------------------------------------------------- +include(${CMAKE_SOURCE_DIR}/cmake/FindPylint.cmake) + +project(run_pylint_on_tutorials) + +if(PYLINT_FOUND) + message(STATUS "pylint version: ${PYLINT_VERSION}") + set(curdir "${CMAKE_CURRENT_SOURCE_DIR}") + file(GLOB_RECURSE PYTHON_SCRIPTS ${curdir}/*.py) + add_custom_target("${PROJECT_NAME}") + + foreach(SCRIPT ${PYTHON_SCRIPTS}) + get_filename_component(SCRIPT_NAME ${SCRIPT} NAME_WE) + add_custom_command(TARGET "${PROJECT_NAME}" + COMMAND ${PYLINT_EXECUTABLE} ${SCRIPT} + --rcfile=${curdir}/pylintrc + COMMENT "Running pylint on : ${SCRIPT_NAME}.py" + ) + endforeach() +endif() diff --git a/samples/python/tutorial_code/pylintrc b/samples/python/tutorial_code/pylintrc new file mode 100644 index 0000000000..35c4a34a96 --- /dev/null +++ b/samples/python/tutorial_code/pylintrc @@ -0,0 +1,16 @@ +[MESSAGES CONTROL] + +# Disable all to choose the Tests one by one +disable=all + +# Tests +enable=bad-indentation, # Used when an unexpected number of indentation’s tabulations or spaces has been found. + mixed-indentation, # Used when there are some mixed tabs and spaces in a module. + unnecessary-semicolon, # Used when a statement is ended by a semi-colon (”;”), which isn’t necessary. + unused-variable # Used when a variable is defined but not used. (Use _var to ignore var). + + +[REPORTS] + +# Activate the evaluation score. +score=no