Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ Below is an example `/slack.json` file that overrides the default `start`:
```json
{
"hooks": {
"get-hooks": "python3 -m slack_cli_hooks.hooks.get_hooks",
"start": "python3 app.py"
"get-hooks": "python -m slack_cli_hooks.hooks.get_hooks",
"start": "python app.py"
}
}
```
Expand Down
5 changes: 4 additions & 1 deletion slack_cli_hooks/hooks/get_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
PROTOCOL: Protocol

# Wrap sys.executable in quotes to prevent execution failures if a white space is present in the absolute python path
EXEC = f"'{sys.executable}'" or "python3"
if sys.executable:
EXEC = f"& '{sys.executable}'" if sys.platform == "win32" else f"'{sys.executable}'"
else:
EXEC = "python"


hooks_payload = {
Expand Down
20 changes: 20 additions & 0 deletions tests/slack_cli_hooks/hooks/test_get_hooks.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,27 @@
import importlib
import sys
from unittest.mock import patch

from slack_cli_hooks.hooks import get_hooks
from slack_cli_hooks.hooks.get_hooks import hooks_payload


class TestGetHooks:
def test_exec_uses_sys_executable(self):
with patch.object(sys, "executable", "/usr/bin/python3"), patch.object(sys, "platform", "linux"):
importlib.reload(get_hooks)
assert get_hooks.EXEC == "'/usr/bin/python3'"

def test_exec_uses_call_operator_on_windows(self):
with patch.object(sys, "executable", "C:\\Python\\python.exe"), patch.object(sys, "platform", "win32"):
importlib.reload(get_hooks)
assert get_hooks.EXEC == "& 'C:\\Python\\python.exe'"

def test_exec_falls_back_to_python_when_sys_executable_is_empty(self):
with patch.object(sys, "executable", ""):
importlib.reload(get_hooks)
assert get_hooks.EXEC == "python"

def test_hooks_payload(self):
hooks = hooks_payload["hooks"]

Expand Down