Lint Python code with flake8 and isort

This commit is contained in:
Christian Clauss 2021-04-09 18:35:47 +02:00 committed by Brennan Ashton
parent 2b309349fe
commit 15932fa9ea
10 changed files with 67 additions and 50 deletions

9
.github/linters/setup.cfg vendored Normal file
View File

@ -0,0 +1,9 @@
[flake8]
ignore = W503,W605
max-complexity = 27
max-line-length = 125
show-source = True
statistics = True
[isort]
profile = black

View File

@ -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

View File

@ -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()

View File

@ -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

View File

@ -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:

View File

@ -37,14 +37,15 @@
#
############################################################################
import os
import subprocess
import re
import sys
import argparse
from lxml import etree as ET
import os
import re
import subprocess
import sys
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:

View File

@ -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,

View File

@ -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"
)

View File

@ -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:

View File

@ -17,8 +17,8 @@
# under the License.
#
import os
import argparse
import os
def parse_args():