Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions .github/workflows/code_formatting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ jobs:
# Pin to ubuntu-22.04 to get the correct version of uncrustify.
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- uses: actions/checkout@v7
- uses: actions/setup-python@v7
- name: Install packages
run: source tools/ci.sh && ci_code_formatting_setup
- name: Run code formatting
Expand All @@ -23,8 +23,7 @@ jobs:
code-spelling:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- uses: actions/checkout@v7
- name: Install packages
run: source tools/ci.sh && ci_code_spell_setup
- name: Run spell checker
Expand Down
12 changes: 12 additions & 0 deletions .github/workflows/ruff.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: Python code lint and formatting with ruff

on: [push, pull_request]

jobs:
ruff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- run: pipx install ruff
- run: ruff check --output-format=github .
- run: ruff format --diff .
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
host:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v7
with:
submodules: true
- name: Install packages
Expand All @@ -21,7 +21,7 @@ jobs:
qemu:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v7
with:
submodules: true
- name: Install packages
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/tests_clang.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
host:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v7
with:
submodules: true
- name: Install packages
Expand All @@ -21,7 +21,7 @@ jobs:
qemu:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v7
with:
submodules: true
- name: Install packages
Expand Down
27 changes: 27 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[tool.codespell]
skip = """
./.git,\
./lib,\
"""

[tool.ruff]
# Exclude third-party code from linting and formatting
extend-exclude = [
"lib",
]
line-length = 99
target-version = "py38"

[tool.ruff.lint]
extend-select = [
"C9",
"PLC",
"W292",
]
ignore = [
"UP031",
"BLE001",
"S110",
"PLR1730",
]
mccabe.max-complexity = 40
2 changes: 1 addition & 1 deletion tests/hardware/thru_device.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# HaLow throughput soak: associate, then cycle TCP/UDP up+down until the budget runs out.
# Buffers are fixed size -- nothing here is sized by anything off the wire.
import network
import socket
import time

import halow_config as cfg
import network

HOST = "192.168.0.137"
TCP_PORT = 9001
Expand Down
19 changes: 11 additions & 8 deletions tests/hardware/thru_file.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# Drop-tolerant HaLow throughput: writes cumulative results to /flash/hres.txt
# after every cycle, so a mid-run USB/CDC drop still leaves the numbers on the device.
import network, socket, time
import socket
import time

import halow_config as cfg
import network

HOST = "192.168.0.137"
TCP_PORT = 9001
Expand Down Expand Up @@ -71,12 +74,11 @@ def udp_run(d):

def write(acc, cyc, assoc, conn, rssi):
try:
f = open("/flash/hres.txt", "w")
f.write("assoc_ms %d cycles %d connected %s rssi %s\n" % (assoc, cyc, conn, rssi))
for k in sorted(acc):
sm, c, mx, mn = acc[k]
f.write("RESULT %-9s mean=%d min=%d max=%d n=%d\n" % (k, sm // c, mn, mx, c))
f.close()
with open("/flash/hres.txt", "w") as f:
f.write("assoc_ms %d cycles %d connected %s rssi %s\n" % (assoc, cyc, conn, rssi))
for k in sorted(acc):
sm, c, mx, mn = acc[k]
f.write("RESULT %-9s mean=%d min=%d max=%d n=%d\n" % (k, sm // c, mn, mx, c))
except Exception as e:
print("write err", e)

Expand All @@ -89,7 +91,8 @@ def write(acc, cyc, assoc, conn, rssi):
w.connect(cfg.SSID, cfg.KEY)
while not w.isconnected():
if time.ticks_diff(time.ticks_ms(), t0) > 30000:
open("/flash/hres.txt", "w").write("assoc FAILED\n")
with open("/flash/hres.txt", "w") as f:
f.write("assoc FAILED\n")
raise SystemExit
time.sleep_ms(100)
assoc = time.ticks_diff(time.ticks_ms(), t0)
Expand Down
3 changes: 1 addition & 2 deletions tools/ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ function ci_code_spell_setup {
}

function ci_code_spell_run {
# src/ and tests/ arrive with the driver; spell-check whatever is present.
codespell README.md $(test -d src && echo src) $(test -d tests && echo tests)
codespell
}

########################################################################################
Expand Down
37 changes: 9 additions & 28 deletions tools/codeformat.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@
# C
"src/**/*.[ch]",
"tests/**/*.[ch]",
# Python
"tests/**/*.py",
"tools/**/*.py",
]

EXCLUSIONS = []
Expand All @@ -54,7 +51,6 @@
".c",
".h",
)
PY_EXTS = (".py",)


def list_files(paths, exclusions=None, prefix=""):
Expand All @@ -74,6 +70,7 @@ def fixup_c(filename):
# Write out file with fixups.
with open(filename, "w", newline="") as f:
dedent_stack = []
l_prev = None
while lines:
# Get next line.
l = lines.pop(0)
Expand Down Expand Up @@ -119,8 +116,6 @@ def fixup_c(filename):

def main():
cmd_parser = argparse.ArgumentParser(description="Auto-format C and Python files.")
cmd_parser.add_argument("-c", action="store_true", help="Format C code only")
cmd_parser.add_argument("-p", action="store_true", help="Format Python code only")
cmd_parser.add_argument("-v", action="store_true", help="Enable verbose output")
cmd_parser.add_argument(
"-f",
Expand All @@ -130,10 +125,6 @@ def main():
cmd_parser.add_argument("files", nargs="*", help="Run on specific globs")
args = cmd_parser.parse_args()

# Setting only one of -c or -p disables the other. If both or neither are set, then do both.
format_c = args.c or not args.p
format_py = args.p or not args.c

# Expand the globs passed on the command line, or use the default globs above.
files = []
if args.files:
Expand All @@ -142,11 +133,11 @@ def main():
# Filter against the default list of files. This is a little fiddly
# because we need to apply both the inclusion globs given in PATHS
# as well as the EXCLUSIONS, and use absolute paths
files = set(os.path.abspath(f) for f in files)
files = {os.path.abspath(f) for f in files}
all_files = set(list_files(PATHS, EXCLUSIONS, TOP))
if args.v: # In verbose mode, log any files we're skipping
for f in files - all_files:
print("Not checking: {}".format(f))
print(f"Not checking: {f}")
files = list(files & all_files)
else:
files = list_files(PATHS, EXCLUSIONS, TOP)
Expand All @@ -166,22 +157,12 @@ def batch(cmd, files, N=200):
subprocess.check_call(cmd + file_args)

# Format C files with uncrustify.
if format_c:
command = ["uncrustify", "-c", UNCRUSTIFY_CFG, "-lC", "--no-backup"]
if not args.v:
command.append("-q")
batch(command, lang_files(C_EXTS))
for file in lang_files(C_EXTS):
fixup_c(file)

# Format Python files with black.
if format_py:
command = ["black", "--fast", "--line-length=99"]
if args.v:
command.append("-v")
else:
command.append("-q")
batch(command, lang_files(PY_EXTS))
command = ["uncrustify", "-c", UNCRUSTIFY_CFG, "-lC", "--no-backup"]
if not args.v:
command.append("-q")
batch(command, lang_files(C_EXTS))
for file in lang_files(C_EXTS):
fixup_c(file)


if __name__ == "__main__":
Expand Down
14 changes: 7 additions & 7 deletions tools/uncrustify.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -1326,7 +1326,7 @@ indent_using_block = true # true/false
# 2: When the `:` is a continuation, indent it under `?`
indent_ternary_operator = 0 # unsigned number

# Whether to indent the statments inside ternary operator.
# Whether to indent the statements inside ternary operator.
indent_inside_ternary_operator = false # true/false

# If true, the indentation of the chunks after a `return` sequence will be set at return indentation column.
Expand Down Expand Up @@ -1782,7 +1782,7 @@ nl_func_call_args_multi_line = false # true/false
# different lines.
nl_func_call_end_multi_line = false # true/false

# Whether to respect nl_func_call_XXX option incase of closure args.
# Whether to respect nl_func_call_XXX option in case of closure args.
nl_func_call_args_multi_line_ignore_closures = false # true/false

# Whether to add a newline after '<' of a template parameter list.
Expand Down Expand Up @@ -2573,7 +2573,7 @@ align_oc_decl_colon = false # true/false

# (OC) Whether to not align parameters in an Objectve-C message call if first
# colon is not on next line of the message call (the same way Xcode does
# aligment)
# alignment)
align_oc_msg_colon_xcode_like = false # true/false

#
Expand Down Expand Up @@ -2919,28 +2919,28 @@ pp_define_at_level = false # true/false
pp_ignore_define_body = false # true/false

# Whether to indent case statements between #if, #else, and #endif.
# Only applies to the indent of the preprocesser that the case statements
# Only applies to the indent of the preprocessor that the case statements
# directly inside of.
#
# Default: true
pp_indent_case = true # true/false

# Whether to indent whole function definitions between #if, #else, and #endif.
# Only applies to the indent of the preprocesser that the function definition
# Only applies to the indent of the preprocessor that the function definition
# is directly inside of.
#
# Default: true
pp_indent_func_def = true # true/false

# Whether to indent extern C blocks between #if, #else, and #endif.
# Only applies to the indent of the preprocesser that the extern block is
# Only applies to the indent of the preprocessor that the extern block is
# directly inside of.
#
# Default: true
pp_indent_extern = true # true/false

# Whether to indent braces directly inside #if, #else, and #endif.
# Only applies to the indent of the preprocesser that the braces are directly
# Only applies to the indent of the preprocessor that the braces are directly
# inside of.
#
# Default: true
Expand Down
Loading