I'm using Cmake to go through all the .py files inside a directory and detect errors and check coding standards using Pylint.
Is there a way for me to check if Pylint is installed using cmake? Would this code be OS independent (for example for Ubuntu and Windows)?
You should create a FindPylint.cmake file and include()
its directory. Then run find_package(Pylint REQUIRED)
.
FindPylint.cmake:
execute_process(
COMMAND pylint --version
OUTPUT_VARIABLE pylint_out
RESULT_VARIABLE pylint_error
ERROR_VARIABLE pylint_suppress)
if (NOT pylint_error)
string(REGEX MATCH "pylint .\..\.." pylint_version_string "${pylint_out}")
string(SUBSTRING "${pylint_version_string}" 7 5 pylint_version)
endif ()
if (pylint_version)
set(PYLINT_FOUND 1
CACHE INTERNAL "Pylint version ${pylint_version} found")
endif ()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Pylint REQUIRED_VARS pylint_version
VERSION_VAR pylint_version)
Some explanation:
No config file found, using default configuration
, so we suppress it by ignoring the pylint_suppress
variable.pylint
output has more than just the version, so we need to do some regex/string handling. CACHE INTERNAL
variable is not strictly necessary, but could come in handy later to check if Pylint was found.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With