You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by bt...@apache.org on 2021/04/10 15:36:34 UTC
[incubator-nuttx] branch master updated: Lint Python code with
flake8 and isort
This is an automated email from the ASF dual-hosted git repository.
btashton pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new 15932fa Lint Python code with flake8 and isort
15932fa is described below
commit 15932fa9eaf67a04ffb8f7b88ae2096e4b5b79f9
Author: Christian Clauss <cc...@me.com>
AuthorDate: Fri Apr 9 18:35:47 2021 +0200
Lint Python code with flake8 and isort
---
.github/linters/setup.cfg | 9 +++++++++
.github/workflows/lint.yml | 10 ++++++++--
Documentation/conf.py | 2 +-
tools/discover.py | 3 +--
tools/flash_writer.py | 34 ++++++++++++++++------------------
tools/ide_exporter.py | 9 +++++----
tools/licensing/apachize.py | 6 +++---
tools/licensing/check.py | 11 ++++++-----
tools/lwl/ocdconsole.py | 27 +++++++++++++++------------
tools/parsecallstack.py | 2 +-
10 files changed, 65 insertions(+), 48 deletions(-)
diff --git a/.github/linters/setup.cfg b/.github/linters/setup.cfg
new file mode 100644
index 0000000..9c18e21
--- /dev/null
+++ b/.github/linters/setup.cfg
@@ -0,0 +1,9 @@
+[flake8]
+ignore = W503,W605
+max-complexity = 27
+max-line-length = 125
+show-source = True
+statistics = True
+
+[isort]
+profile = black
diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml
index 135dca5..3997672 100644
--- a/.github/workflows/lint.yml
+++ b/.github/workflows/lint.yml
@@ -10,9 +10,15 @@ jobs:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- - name: YAML Lint
+ - run: mkdir super-linter.report
+ - name: Lint
uses: github/super-linter@v3
env:
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VALIDATE_ALL_CODEBASE: false
- VALIDATE_YAML: true
VALIDATE_PYTHON_BLACK: true
+ VALIDATE_PYTHON_FLAKE8: true
+ PYTHON_FLAKE8_CONFIG_FILE: setup.cfg
+ VALIDATE_PYTHON_ISORT: true
+ PYTHON_ISORT_CONFIG_FILE: setup.cfg
+ VALIDATE_YAML: true
diff --git a/Documentation/conf.py b/Documentation/conf.py
index d101774..d485278 100644
--- a/Documentation/conf.py
+++ b/Documentation/conf.py
@@ -75,7 +75,7 @@ templates_path = ["_templates"]
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
# list of documentation versions to offer (besides latest). this will be
-# overriden by command line option but we can provide a sane default
+# overridden by command line option but we can provide a sane default
# this way
html_context = dict()
diff --git a/tools/discover.py b/tools/discover.py
index b7c8193..140ca01 100755
--- a/tools/discover.py
+++ b/tools/discover.py
@@ -20,8 +20,7 @@
############################################################################
import array
-import time
-from socket import *
+from socket import AF_INET, SO_BROADCAST, SOCK_DGRAM, SOL_SOCKET, socket, timeout
PORT = 96
diff --git a/tools/flash_writer.py b/tools/flash_writer.py
index ac5c35e..e77184b 100755
--- a/tools/flash_writer.py
+++ b/tools/flash_writer.py
@@ -16,18 +16,15 @@
# License for the specific language governing permissions and limitations
# under the License.
-import time
-import sys
-import os
-import struct
-import glob
-import fnmatch
-import errno
-import telnetlib
import argparse
-import shutil
-import subprocess
+import errno
+import os
import re
+import subprocess
+import sys
+import telnetlib
+import time
+
import xmodem
import_serial_module = True
@@ -44,7 +41,7 @@ else:
try:
import serial
-except:
+except ImportError:
import_serial_module = False
# supported environment various
@@ -57,6 +54,7 @@ PROTOCOL_TELNET = 1
MAX_DOT_COUNT = 70
+
# configure parameters and default value
class ConfigArgs:
PROTOCOL_TYPE = None
@@ -216,12 +214,12 @@ class ConfigArgsLoader:
ConfigArgs.PKGUPD_NAME = args.pkgupd_name
# Get serial port or telnet server ip etc
- if args.serial_protocol == True:
+ if args.serial_protocol is True:
ConfigArgs.PROTOCOL_TYPE = PROTOCOL_SERIAL
- elif args.telnet_protocol == True:
+ elif args.telnet_protocol is True:
ConfigArgs.PROTOCOL_TYPE = PROTOCOL_TELNET
- if ConfigArgs.PROTOCOL_TYPE == None:
+ if ConfigArgs.PROTOCOL_TYPE is None:
proto = os.environ.get("CXD56_PROTOCOL")
if proto is not None:
if "s" in proto:
@@ -229,7 +227,7 @@ class ConfigArgsLoader:
elif "t" in proto:
ConfigArgs.PROTOCOL_TYPE = PROTOCOL_TELNET
- if ConfigArgs.PROTOCOL_TYPE == None:
+ if ConfigArgs.PROTOCOL_TYPE is None:
ConfigArgs.PROTOCOL_TYPE = PROTOCOL_SERIAL
if ConfigArgs.PROTOCOL_TYPE == PROTOCOL_SERIAL:
@@ -582,7 +580,7 @@ def main():
try:
config_loader = ConfigArgsLoader()
config_loader.update_config()
- except:
+ except Exception:
return errno.EINVAL
# Wait to reset the board
@@ -599,7 +597,7 @@ def main():
do_wait_reset = False
bootrom_msg = writer.cancel_autoboot()
- if ConfigArgs.WAIT_RESET == False and do_wait_reset == True:
+ if ConfigArgs.WAIT_RESET is False and do_wait_reset is True:
rx = writer.recv()
time.sleep(1)
for i in range(3):
@@ -615,7 +613,7 @@ def main():
# Wait to reset the board
print("Please press RESET button on target board")
sys.stdout.flush()
- bootrom_msg = writer.cancel_autoboot()
+ bootrom_msg = writer.cancel_autoboot() # noqa: F841 unused variable
# Remove files
if ConfigArgs.ERASE_NAME:
diff --git a/tools/ide_exporter.py b/tools/ide_exporter.py
index c0886d7..4864bf9 100755
--- a/tools/ide_exporter.py
+++ b/tools/ide_exporter.py
@@ -37,14 +37,15 @@
#
############################################################################
+import argparse
import os
-import subprocess
import re
+import subprocess
import sys
-import argparse
-from lxml import etree as ET
from copy import deepcopy
+from lxml import etree as ET
+
HELP = """
ide_exporter.pyis a tool for generation nuttx iar/keil workspace
usage: ide_exporter.py [-h] [-v] [-o OUT_DIR] [-d]
@@ -178,7 +179,7 @@ def get_common_dir(dir_list):
"""Get common parent directory of a given directory list"""
com_dir = dir_list[0]
found = False
- while found == False:
+ while not found:
found = True
com_dir = os.path.split(com_dir)[0]
for directory in dir_list:
diff --git a/tools/licensing/apachize.py b/tools/licensing/apachize.py
index a86a6ce..a4454ef 100755
--- a/tools/licensing/apachize.py
+++ b/tools/licensing/apachize.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python3
-import re
import os
+import re
import sys
apache = r"""
@@ -40,11 +40,11 @@ if len(sys.argv) != 2:
print("Usage: ./apachize.py <file>", file=sys.stderr)
print(
"This will replace the license header of the passed file to that of Apache 2.0 and print it to stdout",
- file=sys.sterr,
+ file=sys.stderr,
)
sys.exit(2)
-if not "TOPDIR" in os.environ:
+if "TOPDIR" not in os.environ:
print(
"Please define the TOPDIR environment variable to the full path to nuttx/ root",
file=sys.stderr,
diff --git a/tools/licensing/check.py b/tools/licensing/check.py
index 837c48b..ee8f242 100755
--- a/tools/licensing/check.py
+++ b/tools/licensing/check.py
@@ -19,13 +19,14 @@
#
############################################################################
+import getopt
import json
-import sys
+import os
import re
import subprocess
-import getopt
+import sys
+
import termcolor
-import os
committers_json = None
non_commiters_json = None
@@ -56,7 +57,7 @@ def get_file(blob):
return subprocess.check_output(
["git", "cat-file", "-p", blob], stderr=subprocess.DEVNULL
).decode()
- except subprocess.CalledProcessError as err:
+ except subprocess.CalledProcessError:
return None
@@ -277,7 +278,7 @@ try:
os.path.dirname(os.path.abspath(__file__)) + "/icla-info_noid.json", "r"
) as file:
non_committers_json = json.load(file)
-except:
+except Exception:
print(
"Could not open CLA JSON files, please read README.md for download instructions"
)
diff --git a/tools/lwl/ocdconsole.py b/tools/lwl/ocdconsole.py
index cfabfcf..333c12f 100755
--- a/tools/lwl/ocdconsole.py
+++ b/tools/lwl/ocdconsole.py
@@ -59,6 +59,18 @@
# linker file) and referencing them directly.
#
+import os
+import socket
+import time
+
+if os.name == "nt":
+ import msvcrt
+else:
+ import select
+ import sys
+ import termios
+ import tty
+
LWL_ACTIVESHIFT = 31
LWL_DNSENSESHIFT = 30
LWL_UPSENSESHIFT = 29
@@ -81,15 +93,6 @@ LWL_PORT_CONSOLE = 1
baseaddr = 0x20000000
length = 0x8000
-import time
-import socket
-import os
-
-if os.name == "nt":
- import msvcrt
-else:
- import sys, select, termios, tty
-
def kbhit():
"""Returns True if a keypress is waiting to be read in stdin, False otherwise."""
@@ -176,10 +179,10 @@ class oocd:
def testInterface(self):
self.mdwText = "ocd_mdw"
- if self.readVariable(baseaddr) != None:
+ if self.readVariable(baseaddr) is not None:
return
self.mdwText = "mdw"
- if self.readVariable(baseaddr) != None:
+ if self.readVariable(baseaddr) is not None:
return
raise ConnectionRefusedError
@@ -284,7 +287,7 @@ if __name__ == "__main__":
print("\r==Link Lost\r")
raise e
- except (BrokenPipeError, ConnectionRefusedError, ConnectionResetError) as e:
+ except (BrokenPipeError, ConnectionRefusedError, ConnectionResetError):
time.sleep(1)
continue
finally:
diff --git a/tools/parsecallstack.py b/tools/parsecallstack.py
index 821e215..a88f744 100755
--- a/tools/parsecallstack.py
+++ b/tools/parsecallstack.py
@@ -17,8 +17,8 @@
# under the License.
#
-import os
import argparse
+import os
def parse_args():