Skip to content

Commit 8cf28c2

Browse files
zimegClaude
andcommitted
fix: use existing executable or unversioned python
Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
1 parent b53cab3 commit 8cf28c2

3 files changed

Lines changed: 18 additions & 3 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ Below is an example `/slack.json` file that overrides the default `start`:
5757
```json
5858
{
5959
"hooks": {
60-
"get-hooks": "python3 -m slack_cli_hooks.hooks.get_hooks",
61-
"start": "python3 app.py"
60+
"get-hooks": "python -m slack_cli_hooks.hooks.get_hooks",
61+
"start": "python app.py"
6262
}
6363
}
6464
```

slack_cli_hooks/hooks/get_hooks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
PROTOCOL: Protocol
88

99
# Wrap sys.executable in quotes to prevent execution failures if a white space is present in the absolute python path
10-
EXEC = f"'{sys.executable}'" or "python3"
10+
EXEC = f"'{sys.executable}'" if sys.executable else "python"
1111

1212

1313
hooks_payload = {

tests/slack_cli_hooks/hooks/test_get_hooks.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,22 @@
1+
import importlib
2+
import sys
3+
from unittest.mock import patch
4+
5+
from slack_cli_hooks.hooks import get_hooks
16
from slack_cli_hooks.hooks.get_hooks import hooks_payload
27

38

49
class TestGetHooks:
10+
def test_exec_uses_sys_executable(self):
11+
with patch.object(sys, "executable", "/usr/bin/python3"):
12+
importlib.reload(get_hooks)
13+
assert get_hooks.EXEC == "'/usr/bin/python3'"
14+
15+
def test_exec_falls_back_to_python_when_sys_executable_is_empty(self):
16+
with patch.object(sys, "executable", ""):
17+
importlib.reload(get_hooks)
18+
assert get_hooks.EXEC == "python"
19+
520
def test_hooks_payload(self):
621
hooks = hooks_payload["hooks"]
722

0 commit comments

Comments
 (0)