mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-02-22 07:44:03 -04:00
Tools: add script to check Python files for flake8-cleanliness
This commit is contained in:
parent
8019cc160a
commit
3c83d52e52
@ -91,7 +91,7 @@ fi
|
||||
|
||||
# Lists of packages to install
|
||||
BASE_PKGS="build-essential ccache g++ gawk git make wget"
|
||||
PYTHON_PKGS="future lxml pymavlink MAVProxy pexpect"
|
||||
PYTHON_PKGS="future lxml pymavlink MAVProxy pexpect flake8"
|
||||
# add some Python packages required for commonly-used MAVProxy modules and hex file generation:
|
||||
if [[ $SKIP_AP_EXT_ENV -ne 1 ]]; then
|
||||
PYTHON_PKGS="$PYTHON_PKGS pygame intelhex"
|
||||
|
@ -259,6 +259,12 @@ for t in $CI_BUILD_TARGET; do
|
||||
continue
|
||||
fi
|
||||
|
||||
if [ "$t" == "python-cleanliness" ]; then
|
||||
echo "Checking Python code cleanliness"
|
||||
./Tools/scripts/run_flake8.py
|
||||
continue
|
||||
fi
|
||||
|
||||
if [ "$t" == "configure-all" ]; then
|
||||
echo "Checking configure of all boards"
|
||||
./Tools/scripts/configure_all.py
|
||||
|
53
Tools/scripts/run_flake8.py
Executable file
53
Tools/scripts/run_flake8.py
Executable file
@ -0,0 +1,53 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
Runs flake8 over Python files which contain a marker indicating
|
||||
they are clean, ensures that they actually are
|
||||
|
||||
AP_FLAKE8_CLEAN
|
||||
"""
|
||||
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
import argparse
|
||||
|
||||
os.environ['PYTHONUNBUFFERED'] = '1'
|
||||
|
||||
|
||||
class Flake8Checker(object):
|
||||
def __init__(self):
|
||||
self.retcode = 0
|
||||
|
||||
def progress(self, string):
|
||||
print("****** %s" % (string,))
|
||||
|
||||
def check(self, filepath):
|
||||
self.progress("Checking (%s)" % filepath)
|
||||
retcode = subprocess.call(["flake8", filepath])
|
||||
if retcode != 0:
|
||||
self.progress("File (%s) failed with retcode (%s)" %
|
||||
(filepath, retcode))
|
||||
self.retcode = 1
|
||||
|
||||
def run(self):
|
||||
for (dirpath, dirnames, filenames) in os.walk("Tools"):
|
||||
for filename in filenames:
|
||||
if os.path.splitext(filename)[1] != ".py":
|
||||
continue
|
||||
filepath = os.path.join(dirpath, filename)
|
||||
content = open(filepath).read()
|
||||
if "AP_FLAKE8_CLEAN" not in content:
|
||||
continue
|
||||
self.check(filepath)
|
||||
return self.retcode
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser(description='Check all Python files for flake8 cleanliness')
|
||||
# parser.add_argument('--build', action='store_true', default=False, help='build as well as configure')
|
||||
args = parser.parse_args()
|
||||
|
||||
checker = Flake8Checker()
|
||||
sys.exit(checker.run())
|
Loading…
Reference in New Issue
Block a user