11#!/usr/bin/env python
22import os
3- import subprocess
4- import sys
53from glob import glob
64from os .path import splitext , basename
75
1513
1614here = os .path .abspath (os .path .dirname (__file__ ))
1715
18- codegen_dependencies = [
19- "black==19.10b0" ,
20- ]
21-
2216test_dependencies = [
2317 "pytest>=5,<6" ,
2418 "pytest-asyncio<1" , # for async
2519 "aiohttp>=3,<4" , # for async
20+ "black==19.10b0" ,
2621]
2722
28-
29- class CodegenCommand (setuptools .Command ):
30- user_options = []
31-
32- @staticmethod
33- def status (s ):
34- """Prints things in bold."""
35- print ("\033 [1m{0}\033 [0m" .format (s ))
36-
37- def initialize_options (self ):
38- pass
39-
40- def finalize_options (self ):
41- pass
42-
43- def _run (self , s , command ):
44- try :
45- self .status (s + "\n " + " " .join (command ))
46- subprocess .check_call (command )
47- except subprocess .CalledProcessError as error :
48- sys .exit (error .returncode )
49-
50- def run (self ):
51- self ._run ("Installing required dependencies ..." ,
52- [sys .executable , "-m" , "pip" , "install" ] + codegen_dependencies )
53-
54- header = "# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n " \
55- "#\n " \
56- "# *** DO NOT EDIT THIS FILE ***\n " \
57- "#\n " \
58- "# 1) Modify slack/web/client.py\n " \
59- "# 2) Run `python setup.py codegen`\n " \
60- "#\n " \
61- "# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n " \
62- "\n "
63- with open ("./src/slack_sdk/web/client.py" , "r" ) as original :
64- source = original .read ()
65- import re
66- async_source = header + source
67- async_source = re .sub (" def " , " async def " , async_source )
68- async_source = re .sub ("from asyncio import Future\n " , "" , async_source )
69- async_source = re .sub ("return self.api_call\(" , "return await self.api_call(" , async_source )
70- async_source = re .sub ("-> SlackResponse" , "-> AsyncSlackResponse" , async_source )
71- async_source = re .sub (
72- "from .base_client import BaseClient, SlackResponse" ,
73- "from .async_base_client import AsyncBaseClient, AsyncSlackResponse" , async_source )
74- # from slack_sdk import WebClient
75- async_source = re .sub (
76- "class WebClient\(BaseClient\):" ,
77- "class AsyncWebClient(AsyncBaseClient):" , async_source )
78- async_source = re .sub (
79- "from slack_sdk import WebClient" ,
80- "from slack_sdk.web.async_client import AsyncWebClient" , async_source )
81- async_source = re .sub (
82- "= WebClient\(" ,
83- "= AsyncWebClient(" , async_source )
84- with open ('./src/slack_sdk/web/async_client.py' , 'w' ) as output :
85- output .write (async_source )
86-
87- legacy_source = header + "from asyncio import Future\n " + source
88- legacy_source = re .sub ("-> SlackResponse" , "-> Union[Future, SlackResponse]" , legacy_source )
89- legacy_source = re .sub (
90- "from .base_client import BaseClient, SlackResponse" ,
91- "from .legacy_base_client import LegacyBaseClient, SlackResponse" , legacy_source )
92- legacy_source = re .sub (
93- "class WebClient\(BaseClient\):" ,
94- "class LegacyWebClient(LegacyBaseClient):" , legacy_source )
95- legacy_source = re .sub (
96- "from slack_sdk import WebClient" ,
97- "from slack_sdk.web.legacy_client import LegacyWebClient" , legacy_source )
98- legacy_source = re .sub (
99- "= WebClient\(" ,
100- "= LegacyWebClient(" , legacy_source )
101- with open ('./src/slack_sdk/web/legacy_client.py' , 'w' ) as output :
102- output .write (legacy_source )
103-
104- self ._run ("Running black (code formatter) ... " ,
105- [sys .executable , "-m" , "black" , f"{ here } /src" ])
106-
107-
10823setuptools .setup (
10924 name = "slack_bolt" ,
11025 version = __version__ ,
@@ -120,7 +35,9 @@ def run(self):
12035 setup_requires = ["pytest-runner==5.2" ],
12136 # python setup.py test
12237 tests_require = test_dependencies ,
123- install_requires = [],
38+ install_requires = [
39+ "slack_sdk==3.0.0a1" ,
40+ ],
12441 extras_require = {
12542 # pip install -e ".[testing]"
12643 # python -m pytest tests/scenario_tests/test_async_events.py
@@ -153,7 +70,4 @@ def run(self):
15370 "Operating System :: OS Independent" ,
15471 ],
15572 python_requires = '>=3.6' ,
156- cmdclass = {
157- "codegen" : CodegenCommand ,
158- },
15973)
0 commit comments