Integrate python coder linter during build
This MR implements the option to run an arbitrary additional script during the python module installation. Typically this would be used to run a Python code linter (e.g. flake8
) during the build of the package:
atlas_install_python_modules( python/*.py
POST_BUILD_CMD /path/to/script )
The script is run after the bytecode compilation stage and passed the same list of files.
In addition, there is a new cmake variable ATLAS_PYTHON_CHECKER
, which if set, will be used as the default POST_BUILD_CMD
. This would ultimately be set to the new flake8_atlas
script, a wrapper around flake8
that can also be configured to only run the check on files with certain content (e.g. "ComponentAccumulator").
An example output:
cmake -DATLAS_PYTHON_CHECKER=/scratch/fwinkl/atlasexternals/External/flake8_atlas/bin/flake8_atlas ../atlasexternals/Projects/AthenaExternals
make
flake8_atlas: Package build succeeded
[ 90%] Built target Package_flake8_atlas
[ 90%] Built target PyTestPythonBytecodeInstall
[100%] PyTest: Package build succeeded
PyTest: Package build succeeded
[100%] Built target Package_PyTest
/scratch/fwinkl/atlasexternals/PyTest/python/test.py:1:1: warning: F401 'os' imported but unused
import os
^
/scratch/fwinkl/atlasexternals/PyTest/python/test.py:2:1: warning: ATL233: Python 3.x incompatible use of non function-like print statement
print "Hello"
^
[100%] Built target PyTestPythonCodeCheck
The warnings are formatted in the same way as gcc warnings and hence should be picked up by our various build/nightly displays.
For a given project (e.g. Athena
) the python checker can be enabled globally in its CMakeLists.txt
file:
# Configure some external tools:
set( ATLAS_PYTHON_CHECKER "flake8_atlas --select ATL,F,E7,E9,W6 --filterFiles ComponentAccumulator"
CACHE STRING "Python checker command to run during Python module compilation" FORCE )