I'm trying to integrate checking my code using pyflakes
into a building process. I've defined the following target in my Makefile
:
pyflakes:
find $(APPLICATION_DIRECTORY) -iname "*.py" -exec pyflakes "{}" \;
The problem is that find
returns 0
every time even if there are code issues (pyflakes
returns not 0
) and make
succeeds. Ideally, I want to run the check on every source file and stop make
if at least one of -exec
failed. Is there a way to achieve this?
I assume there is no way to make find
return exit code of -exec
.
What should work is piping to xargs
:
find $(APPLICATION_DIRECTORY) -iname "*.py" |xargs -I file pyflakes file
You can just pipe the output of find to your own processing loop and exit when pyflakes returns an exit status other than 0.
find . -iname '*.jpg' | \
while read line ; do
pyflakes "$line"
res=$?
if [ $res -ne 0 ] ; then
exit $res
fi
done
Make it end the find process by
pyflakes:
find $(APPLICATION_DIRECTORY) -iname "*.py" -exec bash -c 'pyflakes {}; if [[ $$? != 0 ]]; then kill -INT $$PPID;fi' \;
This is what goes into the makefile, it is not a script file, if you wonder about the syntax.
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