Skip to content

Commit 7b04d01

Browse files
chore: move away from setup.py (#1623)
1 parent 241db14 commit 7b04d01

File tree

15 files changed

+137
-264
lines changed

15 files changed

+137
-264
lines changed

.github/ISSUE_TEMPLATE/01_question.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ sw_vers && uname -v # or `ver`
3030

3131
#### Steps to reproduce:
3232

33-
(Share the commands to run, source code, and project settings (e.g., setup.py))
33+
(Share the commands to run, source code, and project settings (e.g., pyproject.toml))
3434

3535
1.
3636
2.

.github/ISSUE_TEMPLATE/04_bug.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ sw_vers && uname -v # or `ver`
3030

3131
#### Steps to reproduce:
3232

33-
(Share the commands to run, source code, and project settings (e.g., setup.py))
33+
(Share the commands to run, source code, and project settings (e.g., pyproject.toml))
3434

3535
1.
3636
2.

.github/issue_template.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ sw_vers && uname -v # or `ver`
2222

2323
#### Steps to reproduce:
2424

25-
(Share the commands to run, source code, and project settings (e.g., setup.py))
25+
(Share the commands to run, source code, and project settings (e.g., pyproject.toml))
2626

2727
1.
2828
2.

.github/workflows/ci-build.yml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,21 @@ jobs:
3939
pip install -U pip setuptools wheel
4040
pip install -r requirements/testing.txt
4141
pip install -r requirements/optional.txt
42-
- name: Run codegen
43-
run: |
44-
python setup.py codegen
4542
- name: Run validation (black/flake8/pytest)
4643
run: |
47-
python setup.py validate
44+
black --check slack/ slack_sdk/ tests/ integration_tests/
45+
flake8 slack/ slack_sdk/
46+
PYTHONPATH=$PWD:$PYTHONPATH pytest --cov-report=xml --cov=slack_sdk/ tests/
4847
- name: Run tests for SQLAlchemy v1.4 (backward-compatibility)
4948
run: |
5049
# Install v1.4 for testing
5150
pip install "SQLAlchemy>=1.4,<2"
52-
python setup.py unit_tests --test-target tests/slack_sdk/oauth/installation_store/test_sqlalchemy.py && \
53-
python setup.py unit_tests --test-target tests/slack_sdk/oauth/state_store/test_sqlalchemy.py
51+
PYTHONPATH=$PWD:$PYTHONPATH pytest tests/slack_sdk/oauth/installation_store/test_sqlalchemy.py
52+
PYTHONPATH=$PWD:$PYTHONPATH pytest tests/slack_sdk/oauth/state_store/test_sqlalchemy.py
5453
- name: Run codecov (only with latest supported version)
5554
if: startsWith(matrix.python-version, '3.13')
5655
uses: codecov/codecov-action@v5
5756
with:
5857
token: ${{ secrets.CODECOV_TOKEN }}
59-
# python setup.py validate generates the coverage file
58+
# Run validation generates the coverage file
6059
files: ./coverage.xml

integration_tests/helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ def is_not_specified() -> bool:
2121
module = inspect.getmodule(frame[0])
2222
filepath: str = module.__file__
2323

24-
# python setup.py integration_tests --test-target=web/test_issue_560.py
24+
# ./scripts/run_integration_tests.sh web/test_issue_560.py
2525
test_target: str = sys.argv[1] # e.g., web/test_issue_560.py
2626
return not test_target or not filepath.endswith(test_target)

integration_tests/web/test_issue_1143.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class TestWebClient(unittest.TestCase):
1212
"""Runs integration tests with real Slack API
1313
1414
export SLACK_SDK_TEST_BOT_TOKEN=xoxb-xxx
15-
python setup.py run_integration_tests --test-target integration_tests/web/test_issue_1143.py
15+
./scripts/run_integration_tests.sh integration_tests/web/test_issue_1143.py
1616
1717
https://github.com/slackapi/python-slack-sdk/issues/1143
1818
"""

integration_tests/web/test_issue_770.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class TestWebClient(unittest.TestCase):
1616
1717
export SLACK_SDK_TEST_BOT_TOKEN=xoxb-xxx
1818
export SLACK_SDK_TEST_WEB_TEST_CHANNEL_ID=C111
19-
python setup.py run_integration_tests --test-target integration_tests/web/test_issue_770.py
19+
./scripts/run_integration_tests.sh integration_tests/web/test_issue_770.py
2020
2121
https://github.com/slackapi/python-slack-sdk/issues/770
2222
"""

scripts/codegen.py

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
import sys
2+
import argparse
3+
4+
parser = argparse.ArgumentParser()
5+
parser.add_argument("-p", "--path", help="Path to the project source code.", type=str)
6+
if len(sys.argv) == 1:
7+
parser.print_help(sys.stderr)
8+
sys.exit(1)
9+
args = parser.parse_args()
10+
11+
header = (
12+
"# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"
13+
"#\n"
14+
"# *** DO NOT EDIT THIS FILE ***\n"
15+
"#\n"
16+
"# 1) Modify slack_sdk/web/client.py\n"
17+
"# 2) Run `python scripts/codegen.py`\n"
18+
"# 3) Run `black slack_sdk/`\n"
19+
"#\n"
20+
"# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"
21+
"\n"
22+
)
23+
24+
with open(f"{args.path}/slack_sdk/web/client.py", "r") as original:
25+
source = original.read()
26+
import re
27+
28+
async_source = header + source
29+
async_source = re.sub(" def ", " async def ", async_source)
30+
async_source = re.sub("from asyncio import Future\n", "", async_source)
31+
async_source = re.sub(r"return self.api_call\(", "return await self.api_call(", async_source)
32+
async_source = re.sub("-> SlackResponse", "-> AsyncSlackResponse", async_source)
33+
async_source = re.sub(
34+
"from .base_client import BaseClient, SlackResponse",
35+
"from .async_base_client import AsyncBaseClient, AsyncSlackResponse",
36+
async_source,
37+
)
38+
# from slack_sdk import WebClient
39+
async_source = re.sub(
40+
r"class WebClient\(BaseClient\):",
41+
"class AsyncWebClient(AsyncBaseClient):",
42+
async_source,
43+
)
44+
async_source = re.sub(
45+
"from slack_sdk import WebClient",
46+
"from slack_sdk.web.async_client import AsyncWebClient",
47+
async_source,
48+
)
49+
async_source = re.sub(r"= WebClient\(", "= AsyncWebClient(", async_source)
50+
async_source = re.sub(
51+
r" self.files_getUploadURLExternal\(",
52+
" await self.files_getUploadURLExternal(",
53+
async_source,
54+
)
55+
async_source = re.sub(
56+
r" self._upload_file\(",
57+
" await self._upload_file(",
58+
async_source,
59+
)
60+
async_source = re.sub(
61+
r" self.files_completeUploadExternal\(",
62+
" await self.files_completeUploadExternal(",
63+
async_source,
64+
)
65+
async_source = re.sub(
66+
r" self.files_info\(",
67+
" await self.files_info(",
68+
async_source,
69+
)
70+
async_source = re.sub(
71+
"_attach_full_file_metadata",
72+
"_attach_full_file_metadata_async",
73+
async_source,
74+
)
75+
async_source = re.sub(
76+
r" _attach_full_file_metadata_async\(",
77+
" await _attach_full_file_metadata_async(",
78+
async_source,
79+
)
80+
with open(f"{args.path}/slack_sdk/web/async_client.py", "w") as output:
81+
output.write(async_source)
82+
83+
legacy_source = header + "from asyncio import Future\n" + source
84+
legacy_source = re.sub("-> SlackResponse", "-> Union[Future, SlackResponse]", legacy_source)
85+
legacy_source = re.sub(
86+
"from .base_client import BaseClient, SlackResponse",
87+
"from .legacy_base_client import LegacyBaseClient, SlackResponse",
88+
legacy_source,
89+
)
90+
legacy_source = re.sub(
91+
r"class WebClient\(BaseClient\):",
92+
"class LegacyWebClient(LegacyBaseClient):",
93+
legacy_source,
94+
)
95+
legacy_source = re.sub(
96+
"from slack_sdk import WebClient",
97+
"from slack_sdk.web.legacy_client import LegacyWebClient",
98+
legacy_source,
99+
)
100+
legacy_source = re.sub(r"= WebClient\(", "= LegacyWebClient(", legacy_source)
101+
with open(f"{args.path}/slack_sdk/web/legacy_client.py", "w") as output:
102+
output.write(legacy_source)

scripts/run_integration_tests.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ pip install -U pip
1212
pip install -r requirements/testing.txt \
1313
-r requirements/optional.txt
1414

15-
python setup.py codegen
15+
echo "Generating code ..." && python scripts/codegen.py --path .
16+
echo "Running black (code formatter) ..." && black slack_sdk/
1617

17-
test_target="${1:-integration_tests/}"
18-
python setup.py integration_tests --test-target $test_target
18+
test_target="${1:-tests/integration_tests/}"
19+
PYTHONPATH=$PWD:$PYTHONPATH pytest $test_target

scripts/run_unit_tests.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ pip install -U pip
1212
pip install -r requirements/testing.txt \
1313
-r requirements/optional.txt
1414

15-
python setup.py codegen
15+
echo "Generating code ..." && python scripts/codegen.py --path .
16+
echo "Running black (code formatter) ..." && black slack_sdk/
1617

1718
test_target="${1:-tests/}"
18-
python setup.py unit_tests --test-target $test_target
19+
PYTHONPATH=$PWD:$PYTHONPATH pytest $test_target

0 commit comments

Comments
 (0)