Skip to content

Commit a050a47

Browse files
feat: return runtime versions used by the application with a doctor hook (#35)
Co-authored-by: William Bergamin <wbergamin@salesforce.com>
1 parent 58bf832 commit a050a47

5 files changed

Lines changed: 52 additions & 1 deletion

File tree

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,12 @@ The CLI will always use the version of the `python-slack-hooks` that is specifie
3333

3434
### Supported Hooks
3535

36-
The hooks currently supported for use within the Slack CLI include `check-update`, `get-hooks`, `get-manifest`, and `start`:
36+
The hooks currently supported for use within the Slack CLI include `check-update`, `doctor`, `get-hooks`, `get-manifest`, and `start`:
3737

3838
| Hook Name | CLI Command | File | Description |
3939
| --- | --- | --- | --- |
4040
| `check-update` | `slack update` | [check_update.py](./slack_cli_hooks/hooks/check_update.py) | Checks the project's Slack dependencies to determine whether or not any libraries need to be updated. |
41+
| `doctor` | `slack doctor` | [doctor.py](./slack_cli_hooks/hooks/doctor.py) | Returns runtime versions and other system dependencies required by the application. |
4142
| `get-hooks` | All | [get_hooks.py](./slack_cli_hooks/hooks/get_hooks.py) | Fetches the list of available hooks for the CLI from this repository. |
4243
| `get-manifest` | `slack manifest` | [get_manifest.py](./slack_cli_hooks/hooks/get_manifest.py) | Converts a `manifest.json` file into a valid manifest JSON payload. |
4344
| `start` | `slack run` | [start.py](./slack_cli_hooks/hooks/start.py) | While developing locally, the CLI manages a socket connection with Slack's backend and utilizes this hook for events received via this connection. |

slack_cli_hooks/hooks/doctor.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env python
2+
import json
3+
import platform
4+
5+
from slack_cli_hooks.protocol import (
6+
Protocol,
7+
build_protocol,
8+
)
9+
10+
PROTOCOL: Protocol
11+
12+
13+
doctor_payload = {
14+
"versions": [
15+
{
16+
"name": "python",
17+
"current": platform.python_version(),
18+
},
19+
{
20+
"name": "implementation",
21+
"current": platform.python_implementation(),
22+
},
23+
{
24+
"name": "compiler",
25+
"current": platform.python_compiler(),
26+
},
27+
],
28+
}
29+
30+
if __name__ == "__main__":
31+
PROTOCOL = build_protocol()
32+
PROTOCOL.respond(json.dumps(doctor_payload))

slack_cli_hooks/hooks/get_hooks.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"get-manifest": f"{EXEC} -m slack_cli_hooks.hooks.get_manifest",
1717
"start": f"{EXEC} -X dev -m slack_cli_hooks.hooks.start",
1818
"check-update": f"{EXEC} -m slack_cli_hooks.hooks.check_update",
19+
"doctor": f"{EXEC} -m slack_cli_hooks.hooks.doctor",
1920
},
2021
"config": {
2122
"watch": {"filter-regex": "(^manifest\\.json$)", "paths": ["."]},
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import platform
2+
3+
from slack_cli_hooks.hooks.doctor import doctor_payload
4+
5+
6+
class TestDoctor:
7+
def test_versions(self):
8+
versions = doctor_payload.get("versions")
9+
assert versions is not None
10+
11+
assert versions[0].get("name") == "python"
12+
assert versions[0].get("current") == platform.python_version()
13+
assert versions[1].get("name") == "implementation"
14+
assert versions[1].get("current") == platform.python_implementation()
15+
assert versions[2].get("name") == "compiler"
16+
assert versions[2].get("current") == platform.python_compiler()

tests/slack_cli_hooks/hooks/test_get_hooks.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ def test_hooks_payload(self):
99
assert "slack_cli_hooks.hooks.get_manifest" in hooks["get-manifest"]
1010
assert "slack_cli_hooks.hooks.start" in hooks["start"]
1111
assert "slack_cli_hooks.hooks.check_update" in hooks["check-update"]
12+
assert "slack_cli_hooks.hooks.doctor" in hooks["doctor"]
1213

1314
def test_hooks_payload_config(self):
1415
config = hooks_payload["config"]

0 commit comments

Comments
 (0)