Skip to content

Commit c581297

Browse files
kylebonnicijhedberg
authored andcommitted
Compliance check: no dts-linter installed
This PR fixes incorrect error message when dts-linter is not installed and provide a proper message instead of: `Failed to parse dts-linter JSON output: ...` Signed-off-by: Kyle Bonnici <[email protected]>
1 parent d3bae1d commit c581297

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

scripts/ci/check_compliance.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,23 @@ class DevicetreeLintingCheck(ComplianceTest):
497497
name = "DevicetreeLinting"
498498
doc = "See https://docs.zephyrproject.org/latest/contribute/style/devicetree.html for more details."
499499

500+
def ensure_npx(self) -> bool:
501+
try:
502+
# --no prevents npx from fetching from registry
503+
subprocess.run(
504+
["npx", "--no", 'dts-linter', "--", "--version"],
505+
stdout=subprocess.DEVNULL,
506+
stderr=subprocess.DEVNULL,
507+
check=True,
508+
text=True
509+
)
510+
return True
511+
except subprocess.CalledProcessError:
512+
return False
513+
except FileNotFoundError:
514+
# npx itself not installed
515+
return False
516+
500517
def _parse_json_output(self, cmd, cwd=None):
501518
"""Run command and parse single JSON output with issues array"""
502519
result = subprocess.run(
@@ -524,6 +541,11 @@ def run(self):
524541
if file.endswith((".dts", ".dtsi", ".overlay"))
525542
]
526543

544+
if not self.ensure_npx():
545+
self.skip(
546+
'dts-linter not installed. To run this check, '
547+
'install Node.js and then run [npm ci] command inside ZEPHYR_BASE'
548+
)
527549
if not dts_files:
528550
self.skip('No DTS')
529551

@@ -574,7 +596,7 @@ def run(self):
574596
self.failure(f"dts-linter found issues:\n{stderr_output}")
575597
else:
576598
self.failure("dts-linter failed with no output. "
577-
"Make sure you install Node.JS and then run npm ci inside ZEPHYR_BASE")
599+
"Make sure you install Node.js and then run npm ci inside ZEPHYR_BASE")
578600
except RuntimeError as ex:
579601
self.failure(f"{ex}")
580602

0 commit comments

Comments
 (0)