mirror of
https://github.com/opencv/opencv.git
synced 2025-07-30 01:06:38 +08:00
Using Pylint Tool to Test the python tutorial codes
* Adding CMake script to check if pylint is installed * Adding Pylint config file (to choose the tests that are enabled) * Adding CMake script to samples/python/tutorial_code Testing: bad-indentation, mixed-indentation, unnecessary-semicolon, unused-variable
This commit is contained in:
parent
9c14a2f0aa
commit
b7fa6d84bc
27
cmake/FindPylint.cmake
Normal file
27
cmake/FindPylint.cmake
Normal file
@ -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)
|
@ -43,6 +43,10 @@ Generate documentation {#tutorial_documentation_generate}
|
||||
make doxygen
|
||||
@endcode
|
||||
- Open <i>doc/doxygen/html/index.html</i> 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}
|
||||
------------------
|
||||
|
@ -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)
|
||||
|
23
samples/python/tutorial_code/CMakeLists.txt
Normal file
23
samples/python/tutorial_code/CMakeLists.txt
Normal file
@ -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()
|
16
samples/python/tutorial_code/pylintrc
Normal file
16
samples/python/tutorial_code/pylintrc
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user