Skip to content

Commit 01d9f1a

Browse files
committed
Add lint scripts to scripts/ and update CI to use them
- Add scripts/cpplint.py for C++ style checking - Add scripts/check_license.sh for license header verification - Update workflow to use scripts from repo instead of image - Update lint image tag to 2026-01-05-90f182d5d748 Signed-off-by: cdunning <cdunning@nvidia.com>
1 parent 3912dda commit 01d9f1a

3 files changed

Lines changed: 93 additions & 4 deletions

File tree

.github/workflows/ci.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
runs-on: ubuntu-latest
2222
timeout-minutes: 10
2323
container:
24-
image: ghcr.io/nvidia/cutile-python/lint:2025-12-06-4cb7d16e4c20
24+
image: ghcr.io/nvidia/cutile-python/lint:2026-01-05-90f182d5d748
2525
steps:
2626
- name: Checkout repository
2727
uses: actions/checkout@v6
@@ -30,10 +30,10 @@ jobs:
3030
run: flake8
3131

3232
- name: Run cpplint
33-
run: python3 ci/cpplint.py
33+
run: python scripts/cpplint.py
3434

3535
- name: Check license headers (REUSE)
36-
run: ci/scripts/check_license.sh
36+
run: scripts/check_license.sh
3737

3838
- name: Check inline samples are up to date
39-
run: python3 test/tools/inline_samples.py --check
39+
run: python test/tools/inline_samples.py --check

scripts/check_license.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
# SPDX-FileCopyrightText: Copyright (c) <2025> NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3+
#
4+
# SPDX-License-Identifier: Apache-2.0
5+
6+
ignore_files=("src/cuda/tile/VERSION")
7+
outputs=$(reuse lint --lines | grep -v ${ignore_files[@]/#/-e })
8+
if [ -n "$outputs" ]; then
9+
echo -e "License check failed\n${outputs}"
10+
exit 1
11+
fi
12+

scripts/cpplint.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#!/usr/bin/env python3
2+
# SPDX-FileCopyrightText: Copyright (c) <2025> NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3+
#
4+
# SPDX-License-Identifier: Apache-2.0
5+
6+
import os
7+
import sys
8+
9+
file_extensions = [
10+
".h",
11+
".hpp",
12+
".hh",
13+
".c",
14+
".C",
15+
".cpp",
16+
".cxx",
17+
".cc",
18+
".pyx",
19+
".pxd",
20+
]
21+
max_line_len = 100
22+
23+
24+
def should_lint(filename: str):
25+
return any(filename.endswith(x) for x in file_extensions)
26+
27+
28+
def lint(paths):
29+
num_errors = 0
30+
num_files = 0
31+
32+
def report_error(message: str):
33+
nonlocal num_errors
34+
print(f"{full_name[len(path) + 1:]}:{i + 1}: {message}", file=sys.stderr)
35+
num_errors += 1
36+
37+
for path in paths:
38+
for root, dirs, files in os.walk(path):
39+
for filename in files:
40+
if not should_lint(filename):
41+
continue
42+
full_name = os.path.join(root, filename)
43+
with open(full_name, "r") as f:
44+
for i, line in enumerate(f):
45+
if "noqa" in line:
46+
continue
47+
if "SPDX" in line:
48+
continue
49+
50+
length = len(line)
51+
if line.endswith("\n"):
52+
length -= 1
53+
if length > max_line_len:
54+
report_error(
55+
f"Line is longer than {max_line_len} characters"
56+
)
57+
if length > 0 and line[length - 1].isspace():
58+
report_error("Trailing whitespace at the end of the line")
59+
num_files += 1
60+
61+
if num_errors > 0:
62+
print(f"Found {num_errors} errors", file=sys.stderr)
63+
sys.exit(1)
64+
elif num_files == 0:
65+
print("No input files found!", file=sys.stderr)
66+
sys.exit(2)
67+
else:
68+
print(f"Checked {num_files} files, all OK")
69+
70+
71+
if __name__ == "__main__":
72+
script_dir = os.path.dirname(__file__)
73+
project_root = os.getcwd()
74+
dirs = ["cext", "torch_cext", "src"]
75+
paths = [os.path.join(project_root, d) for d in dirs]
76+
lint(paths)
77+

0 commit comments

Comments
 (0)