diff --git a/ament_cmake_flake8/cmake/ament_cmake_flake8_lint_hook.cmake b/ament_cmake_flake8/cmake/ament_cmake_flake8_lint_hook.cmake index 086c0644..83e5c53a 100644 --- a/ament_cmake_flake8/cmake/ament_cmake_flake8_lint_hook.cmake +++ b/ament_cmake_flake8/cmake/ament_cmake_flake8_lint_hook.cmake @@ -15,5 +15,6 @@ file(GLOB_RECURSE _python_files FOLLOW_SYMLINKS "*.py") if(_python_files) message(STATUS "Added test 'flake8' to check Python code syntax and style conventions") - ament_flake8() + message(STATUS "Configured 'flake8' exclude dirs and/or files: ${AMENT_LINT_AUTO_FILE_EXCLUDE}") + ament_flake8(EXCLUDE ${AMENT_LINT_AUTO_FILE_EXCLUDE}) endif() diff --git a/ament_cmake_flake8/cmake/ament_flake8.cmake b/ament_cmake_flake8/cmake/ament_flake8.cmake index 83260ae8..9dd986c5 100644 --- a/ament_cmake_flake8/cmake/ament_flake8.cmake +++ b/ament_cmake_flake8/cmake/ament_flake8.cmake @@ -31,13 +31,15 @@ # :param MAX_LINE_LENGTH: override the maximum line length, # the default is defined in ament_flake8 # :type MAX_LINE_LENGTH: integer +# :param EXCLUDE: an optional list of exclude directories or files for flake8 +# :type EXCLUDE: list # :param ARGN: the files or directories to check # :type ARGN: list of strings # # @public # function(ament_flake8) - cmake_parse_arguments(ARG "" "MAX_LINE_LENGTH;TESTNAME;CONFIG_FILE" "" ${ARGN}) + cmake_parse_arguments(ARG "" "EXCLUDE;MAX_LINE_LENGTH;TESTNAME;CONFIG_FILE" "" ${ARGN}) if(NOT ARG_TESTNAME) set(ARG_TESTNAME "flake8") endif() @@ -57,6 +59,10 @@ function(ament_flake8) if(ARG_MAX_LINE_LENGTH) list(APPEND cmd "--linelength" "${ARG_MAX_LINE_LENGTH}") endif() + if(ARG_EXCLUDE) + list(APPEND cmd "--exclude" "${ARG_EXCLUDE}") + endif() + list(APPEND cmd ${ARG_UNPARSED_ARGUMENTS}) file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/ament_flake8") diff --git a/ament_lint_auto/doc/index.rst b/ament_lint_auto/doc/index.rst index 7470c77e..4cf25bc7 100644 --- a/ament_lint_auto/doc/index.rst +++ b/ament_lint_auto/doc/index.rst @@ -47,7 +47,7 @@ in CMake ament packages. How to exclude files with ament_lint_auto? ------------------------------------------ -Linter hooks conform to the ament_lint_auto convention of excluding files +Linter hooks shall conform to the ament_lint_auto convention of excluding files specified in the CMake list variable `AMENT_LINT_AUTO_FILE_EXCLUDE`. As such, the CMake snippet from above can be modified to exclude files across all linters with one addition. @@ -62,3 +62,22 @@ all linters with one addition. set(AMENT_LINT_AUTO_FILE_EXCLUDE /path/to/ignored_file ...) ament_lint_auto_find_test_dependencies() endif() + +For a more specific example, this excludes all python files matching a pattern using globbing. +Multiple expressions can be combined on multiple lines. +It might be a good idea to issue a warning to developers that linting is disabled +if you plan to enable it at some point. + +.. code:: cmake + + file(GLOB_RECURSE AMENT_LINT_AUTO_FILE_EXCLUDE + # Exclude all the python files in src directory + src/*.py + # Exclude all the c++ implementation files in test directory + test/*.cpp + ) + message(AUTHOR_WARNING + "Ament lint auto tests are disabled on the following: " + ${AMENT_LINT_AUTO_FILE_EXCLUDE} + ) +