forked from nuttx/nuttx-update
Lint Python code with flake8 and isort
This commit is contained in:
parent
2b309349fe
commit
15932fa9ea
10 changed files with 67 additions and 50 deletions
9
.github/linters/setup.cfg
vendored
Normal file
9
.github/linters/setup.cfg
vendored
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
[flake8]
|
||||||
|
ignore = W503,W605
|
||||||
|
max-complexity = 27
|
||||||
|
max-line-length = 125
|
||||||
|
show-source = True
|
||||||
|
statistics = True
|
||||||
|
|
||||||
|
[isort]
|
||||||
|
profile = black
|
10
.github/workflows/lint.yml
vendored
10
.github/workflows/lint.yml
vendored
|
@ -10,9 +10,15 @@ jobs:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
- name: YAML Lint
|
- run: mkdir super-linter.report
|
||||||
|
- name: Lint
|
||||||
uses: github/super-linter@v3
|
uses: github/super-linter@v3
|
||||||
env:
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
VALIDATE_ALL_CODEBASE: false
|
VALIDATE_ALL_CODEBASE: false
|
||||||
VALIDATE_YAML: true
|
|
||||||
VALIDATE_PYTHON_BLACK: 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
|
||||||
|
|
|
@ -75,7 +75,7 @@ templates_path = ["_templates"]
|
||||||
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
|
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
|
||||||
|
|
||||||
# list of documentation versions to offer (besides latest). this will be
|
# 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
|
# this way
|
||||||
|
|
||||||
html_context = dict()
|
html_context = dict()
|
||||||
|
|
|
@ -20,8 +20,7 @@
|
||||||
############################################################################
|
############################################################################
|
||||||
|
|
||||||
import array
|
import array
|
||||||
import time
|
from socket import AF_INET, SO_BROADCAST, SOCK_DGRAM, SOL_SOCKET, socket, timeout
|
||||||
from socket import *
|
|
||||||
|
|
||||||
PORT = 96
|
PORT = 96
|
||||||
|
|
||||||
|
|
|
@ -16,18 +16,15 @@
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import time
|
|
||||||
import sys
|
|
||||||
import os
|
|
||||||
import struct
|
|
||||||
import glob
|
|
||||||
import fnmatch
|
|
||||||
import errno
|
|
||||||
import telnetlib
|
|
||||||
import argparse
|
import argparse
|
||||||
import shutil
|
import errno
|
||||||
import subprocess
|
import os
|
||||||
import re
|
import re
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
import telnetlib
|
||||||
|
import time
|
||||||
|
|
||||||
import xmodem
|
import xmodem
|
||||||
|
|
||||||
import_serial_module = True
|
import_serial_module = True
|
||||||
|
@ -44,7 +41,7 @@ else:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import serial
|
import serial
|
||||||
except:
|
except ImportError:
|
||||||
import_serial_module = False
|
import_serial_module = False
|
||||||
|
|
||||||
# supported environment various
|
# supported environment various
|
||||||
|
@ -57,6 +54,7 @@ PROTOCOL_TELNET = 1
|
||||||
|
|
||||||
MAX_DOT_COUNT = 70
|
MAX_DOT_COUNT = 70
|
||||||
|
|
||||||
|
|
||||||
# configure parameters and default value
|
# configure parameters and default value
|
||||||
class ConfigArgs:
|
class ConfigArgs:
|
||||||
PROTOCOL_TYPE = None
|
PROTOCOL_TYPE = None
|
||||||
|
@ -216,12 +214,12 @@ class ConfigArgsLoader:
|
||||||
ConfigArgs.PKGUPD_NAME = args.pkgupd_name
|
ConfigArgs.PKGUPD_NAME = args.pkgupd_name
|
||||||
|
|
||||||
# Get serial port or telnet server ip etc
|
# Get serial port or telnet server ip etc
|
||||||
if args.serial_protocol == True:
|
if args.serial_protocol is True:
|
||||||
ConfigArgs.PROTOCOL_TYPE = PROTOCOL_SERIAL
|
ConfigArgs.PROTOCOL_TYPE = PROTOCOL_SERIAL
|
||||||
elif args.telnet_protocol == True:
|
elif args.telnet_protocol is True:
|
||||||
ConfigArgs.PROTOCOL_TYPE = PROTOCOL_TELNET
|
ConfigArgs.PROTOCOL_TYPE = PROTOCOL_TELNET
|
||||||
|
|
||||||
if ConfigArgs.PROTOCOL_TYPE == None:
|
if ConfigArgs.PROTOCOL_TYPE is None:
|
||||||
proto = os.environ.get("CXD56_PROTOCOL")
|
proto = os.environ.get("CXD56_PROTOCOL")
|
||||||
if proto is not None:
|
if proto is not None:
|
||||||
if "s" in proto:
|
if "s" in proto:
|
||||||
|
@ -229,7 +227,7 @@ class ConfigArgsLoader:
|
||||||
elif "t" in proto:
|
elif "t" in proto:
|
||||||
ConfigArgs.PROTOCOL_TYPE = PROTOCOL_TELNET
|
ConfigArgs.PROTOCOL_TYPE = PROTOCOL_TELNET
|
||||||
|
|
||||||
if ConfigArgs.PROTOCOL_TYPE == None:
|
if ConfigArgs.PROTOCOL_TYPE is None:
|
||||||
ConfigArgs.PROTOCOL_TYPE = PROTOCOL_SERIAL
|
ConfigArgs.PROTOCOL_TYPE = PROTOCOL_SERIAL
|
||||||
|
|
||||||
if ConfigArgs.PROTOCOL_TYPE == PROTOCOL_SERIAL:
|
if ConfigArgs.PROTOCOL_TYPE == PROTOCOL_SERIAL:
|
||||||
|
@ -582,7 +580,7 @@ def main():
|
||||||
try:
|
try:
|
||||||
config_loader = ConfigArgsLoader()
|
config_loader = ConfigArgsLoader()
|
||||||
config_loader.update_config()
|
config_loader.update_config()
|
||||||
except:
|
except Exception:
|
||||||
return errno.EINVAL
|
return errno.EINVAL
|
||||||
|
|
||||||
# Wait to reset the board
|
# Wait to reset the board
|
||||||
|
@ -599,7 +597,7 @@ def main():
|
||||||
do_wait_reset = False
|
do_wait_reset = False
|
||||||
bootrom_msg = writer.cancel_autoboot()
|
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()
|
rx = writer.recv()
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
for i in range(3):
|
for i in range(3):
|
||||||
|
@ -615,7 +613,7 @@ def main():
|
||||||
# Wait to reset the board
|
# Wait to reset the board
|
||||||
print("Please press RESET button on target board")
|
print("Please press RESET button on target board")
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
bootrom_msg = writer.cancel_autoboot()
|
bootrom_msg = writer.cancel_autoboot() # noqa: F841 unused variable
|
||||||
|
|
||||||
# Remove files
|
# Remove files
|
||||||
if ConfigArgs.ERASE_NAME:
|
if ConfigArgs.ERASE_NAME:
|
||||||
|
|
|
@ -37,14 +37,15 @@
|
||||||
#
|
#
|
||||||
############################################################################
|
############################################################################
|
||||||
|
|
||||||
import os
|
|
||||||
import subprocess
|
|
||||||
import re
|
|
||||||
import sys
|
|
||||||
import argparse
|
import argparse
|
||||||
from lxml import etree as ET
|
import os
|
||||||
|
import re
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
|
|
||||||
|
from lxml import etree as ET
|
||||||
|
|
||||||
HELP = """
|
HELP = """
|
||||||
ide_exporter.pyis a tool for generation nuttx iar/keil workspace
|
ide_exporter.pyis a tool for generation nuttx iar/keil workspace
|
||||||
usage: ide_exporter.py [-h] [-v] [-o OUT_DIR] [-d]
|
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"""
|
"""Get common parent directory of a given directory list"""
|
||||||
com_dir = dir_list[0]
|
com_dir = dir_list[0]
|
||||||
found = False
|
found = False
|
||||||
while found == False:
|
while not found:
|
||||||
found = True
|
found = True
|
||||||
com_dir = os.path.split(com_dir)[0]
|
com_dir = os.path.split(com_dir)[0]
|
||||||
for directory in dir_list:
|
for directory in dir_list:
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import re
|
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
apache = r"""
|
apache = r"""
|
||||||
|
@ -40,11 +40,11 @@ if len(sys.argv) != 2:
|
||||||
print("Usage: ./apachize.py <file>", file=sys.stderr)
|
print("Usage: ./apachize.py <file>", file=sys.stderr)
|
||||||
print(
|
print(
|
||||||
"This will replace the license header of the passed file to that of Apache 2.0 and print it to stdout",
|
"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)
|
sys.exit(2)
|
||||||
|
|
||||||
if not "TOPDIR" in os.environ:
|
if "TOPDIR" not in os.environ:
|
||||||
print(
|
print(
|
||||||
"Please define the TOPDIR environment variable to the full path to nuttx/ root",
|
"Please define the TOPDIR environment variable to the full path to nuttx/ root",
|
||||||
file=sys.stderr,
|
file=sys.stderr,
|
||||||
|
|
|
@ -19,13 +19,14 @@
|
||||||
#
|
#
|
||||||
############################################################################
|
############################################################################
|
||||||
|
|
||||||
|
import getopt
|
||||||
import json
|
import json
|
||||||
import sys
|
import os
|
||||||
import re
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
import getopt
|
import sys
|
||||||
|
|
||||||
import termcolor
|
import termcolor
|
||||||
import os
|
|
||||||
|
|
||||||
committers_json = None
|
committers_json = None
|
||||||
non_commiters_json = None
|
non_commiters_json = None
|
||||||
|
@ -56,7 +57,7 @@ def get_file(blob):
|
||||||
return subprocess.check_output(
|
return subprocess.check_output(
|
||||||
["git", "cat-file", "-p", blob], stderr=subprocess.DEVNULL
|
["git", "cat-file", "-p", blob], stderr=subprocess.DEVNULL
|
||||||
).decode()
|
).decode()
|
||||||
except subprocess.CalledProcessError as err:
|
except subprocess.CalledProcessError:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
@ -277,7 +278,7 @@ try:
|
||||||
os.path.dirname(os.path.abspath(__file__)) + "/icla-info_noid.json", "r"
|
os.path.dirname(os.path.abspath(__file__)) + "/icla-info_noid.json", "r"
|
||||||
) as file:
|
) as file:
|
||||||
non_committers_json = json.load(file)
|
non_committers_json = json.load(file)
|
||||||
except:
|
except Exception:
|
||||||
print(
|
print(
|
||||||
"Could not open CLA JSON files, please read README.md for download instructions"
|
"Could not open CLA JSON files, please read README.md for download instructions"
|
||||||
)
|
)
|
||||||
|
|
|
@ -59,6 +59,18 @@
|
||||||
# linker file) and referencing them directly.
|
# 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_ACTIVESHIFT = 31
|
||||||
LWL_DNSENSESHIFT = 30
|
LWL_DNSENSESHIFT = 30
|
||||||
LWL_UPSENSESHIFT = 29
|
LWL_UPSENSESHIFT = 29
|
||||||
|
@ -81,15 +93,6 @@ LWL_PORT_CONSOLE = 1
|
||||||
baseaddr = 0x20000000
|
baseaddr = 0x20000000
|
||||||
length = 0x8000
|
length = 0x8000
|
||||||
|
|
||||||
import time
|
|
||||||
import socket
|
|
||||||
import os
|
|
||||||
|
|
||||||
if os.name == "nt":
|
|
||||||
import msvcrt
|
|
||||||
else:
|
|
||||||
import sys, select, termios, tty
|
|
||||||
|
|
||||||
|
|
||||||
def kbhit():
|
def kbhit():
|
||||||
"""Returns True if a keypress is waiting to be read in stdin, False otherwise."""
|
"""Returns True if a keypress is waiting to be read in stdin, False otherwise."""
|
||||||
|
@ -176,10 +179,10 @@ class oocd:
|
||||||
|
|
||||||
def testInterface(self):
|
def testInterface(self):
|
||||||
self.mdwText = "ocd_mdw"
|
self.mdwText = "ocd_mdw"
|
||||||
if self.readVariable(baseaddr) != None:
|
if self.readVariable(baseaddr) is not None:
|
||||||
return
|
return
|
||||||
self.mdwText = "mdw"
|
self.mdwText = "mdw"
|
||||||
if self.readVariable(baseaddr) != None:
|
if self.readVariable(baseaddr) is not None:
|
||||||
return
|
return
|
||||||
raise ConnectionRefusedError
|
raise ConnectionRefusedError
|
||||||
|
|
||||||
|
@ -284,7 +287,7 @@ if __name__ == "__main__":
|
||||||
print("\r==Link Lost\r")
|
print("\r==Link Lost\r")
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
except (BrokenPipeError, ConnectionRefusedError, ConnectionResetError) as e:
|
except (BrokenPipeError, ConnectionRefusedError, ConnectionResetError):
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
continue
|
continue
|
||||||
finally:
|
finally:
|
||||||
|
|
|
@ -17,8 +17,8 @@
|
||||||
# under the License.
|
# under the License.
|
||||||
#
|
#
|
||||||
|
|
||||||
import os
|
|
||||||
import argparse
|
import argparse
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
def parse_args():
|
def parse_args():
|
||||||
|
|
Loading…
Reference in a new issue