Skip to content

Commit 557681b

Browse files
committed
chore: autogenerate the async chat stream helper
1 parent fe40900 commit 557681b

3 files changed

Lines changed: 39 additions & 2 deletions

File tree

‎scripts/codegen.py‎

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
"from .async_base_client import AsyncBaseClient, AsyncSlackResponse",
3636
async_source,
3737
)
38-
# from slack_sdk import WebClient
3938
async_source = re.sub(
4039
r"class WebClient\(BaseClient\):",
4140
"class AsyncWebClient(AsyncBaseClient):",
@@ -122,3 +121,31 @@
122121
legacy_source = re.sub(r"= WebClient\(", "= LegacyWebClient(", legacy_source)
123122
with open(f"{args.path}/slack_sdk/web/legacy_client.py", "w") as output:
124123
output.write(legacy_source)
124+
125+
with open(f"{args.path}/slack_sdk/web/chat_stream.py", "r") as original:
126+
source = original.read()
127+
import re
128+
129+
async_source = header + source
130+
async_source = re.sub(
131+
"from slack_sdk.web.slack_response import SlackResponse",
132+
"from slack_sdk.web.async_slack_response import AsyncSlackResponse",
133+
async_source,
134+
)
135+
async_source = re.sub(
136+
r"from slack_sdk import WebClient",
137+
"from slack_sdk.web.async_client import AsyncWebClient",
138+
async_source,
139+
)
140+
async_source = re.sub("class ChatStream", "class AsyncChatStream", async_source)
141+
async_source = re.sub('"WebClient"', '"AsyncWebClient"', async_source)
142+
async_source = re.sub(r"Optional\[SlackResponse\]", "Optional[AsyncSlackResponse]", async_source)
143+
async_source = re.sub(r"SlackResponse ", "AsyncSlackResponse ", async_source)
144+
async_source = re.sub(r"SlackResponse:", "AsyncSlackResponse:", async_source)
145+
async_source = re.sub(r"def append\(", "async def append(", async_source)
146+
async_source = re.sub(r"def stop\(", "async def stop(", async_source)
147+
async_source = re.sub(r"def _flush_buffer\(", "async def _flush_buffer(", async_source)
148+
async_source = re.sub("self._client.chat_", "await self._client.chat_", async_source)
149+
async_source = re.sub("self._flush_buffer", "await self._flush_buffer", async_source)
150+
with open(f"{args.path}/slack_sdk/web/async_chat_stream.py", "w") as output:
151+
output.write(async_source)

‎slack_sdk/web/async_chat_stream.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2+
#
3+
# *** DO NOT EDIT THIS FILE ***
4+
#
5+
# 1) Modify slack_sdk/web/client.py
6+
# 2) Run `python scripts/codegen.py`
7+
# 3) Run `black slack_sdk/`
8+
#
9+
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10+
111
import json
212
import logging
313
from typing import TYPE_CHECKING, Dict, Optional, Sequence, Union

‎slack_sdk/web/chat_stream.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from slack_sdk.web.slack_response import SlackResponse
99

1010
if TYPE_CHECKING:
11-
from slack_sdk.web.client import WebClient
11+
from slack_sdk import WebClient
1212

1313

1414
class ChatStream:

0 commit comments

Comments
 (0)