Skip to content

Commit 093bb99

Browse files
carlescufijhedberg
authored andcommitted
scripts: compliance: Harden the execution of npx
Instead of relying on various exceptions that can happen when one tries to execute a program that is not installed in the system (typically FileNotFoundError but sometimes PermissionError), use shutil.which() to ensure the npx executable is available before running it. Signed-off-by: Carles Cufi <[email protected]>
1 parent cd8e773 commit 093bb99

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

scripts/ci/check_compliance.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -496,12 +496,15 @@ class DevicetreeLintingCheck(ComplianceTest):
496496
"""
497497
name = "DevicetreeLinting"
498498
doc = "See https://docs.zephyrproject.org/latest/contribute/style/devicetree.html for more details."
499+
NPX_EXECUTABLE = "npx"
499500

500501
def ensure_npx(self) -> bool:
502+
if not shutil.which(self.NPX_EXECUTABLE):
503+
return False
501504
try:
502505
# --no prevents npx from fetching from registry
503506
subprocess.run(
504-
["npx", "--no", 'dts-linter', "--", "--version"],
507+
[self.NPX_EXECUTABLE, "--no", 'dts-linter', "--", "--version"],
505508
stdout=subprocess.DEVNULL,
506509
stderr=subprocess.DEVNULL,
507510
check=True,
@@ -510,9 +513,6 @@ def ensure_npx(self) -> bool:
510513
return True
511514
except subprocess.CalledProcessError:
512515
return False
513-
except FileNotFoundError:
514-
# npx itself not installed
515-
return False
516516

517517
def _parse_json_output(self, cmd, cwd=None):
518518
"""Run command and parse single JSON output with issues array"""

0 commit comments

Comments
 (0)