aboutsummaryrefslogtreecommitdiff
path: root/xmake.lua
diff options
context:
space:
mode:
Diffstat (limited to 'xmake.lua')
-rw-r--r--xmake.lua27
1 files changed, 26 insertions, 1 deletions
diff --git a/xmake.lua b/xmake.lua
index a84253082..5b4b3958c 100644
--- a/xmake.lua
+++ b/xmake.lua
@@ -571,7 +571,32 @@ task("precommit")
description = "Run required pre-commit steps (clang-format, etc)",
}
on_run(function ()
- print(os.exec("python -m pre_commit run --all-files"))
+ -- pre-commit can be installed as a standalone executable (e.g. via pipx,
+ -- Homebrew, or system packages) or as a Python module. We prefer the
+ -- standalone binary because it works regardless of which Python name the
+ -- system exposes. If it isn't in PATH we fall back to invoking it as a
+ -- module, trying "python" first since some systems only have that, and
+ -- "python3" otherwise.
+ local cmd
+ try {
+ function()
+ os.exec("pre-commit --version")
+ cmd = "pre-commit run --all-files"
+ end,
+ catch { function() end }
+ }
+ if not cmd then
+ local python = "python3"
+ try {
+ function()
+ os.exec("python --version")
+ python = "python"
+ end,
+ catch { function() end }
+ }
+ cmd = python .. " -m pre_commit run --all-files"
+ end
+ print(os.exec(cmd))
end)
task("sln")