Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

health: move away from setup.py #1623

Merged
merged 1 commit into from
Dec 23, 2024
Merged
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
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/01_question.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ sw_vers && uname -v # or `ver`

#### Steps to reproduce:

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

1.
2.
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/04_bug.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ sw_vers && uname -v # or `ver`

#### Steps to reproduce:

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

1.
2.
Expand Down
2 changes: 1 addition & 1 deletion .github/issue_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ sw_vers && uname -v # or `ver`

#### Steps to reproduce:

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

1.
2.
Expand Down
13 changes: 6 additions & 7 deletions .github/workflows/ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,21 @@ jobs:
pip install -U pip setuptools wheel
pip install -r requirements/testing.txt
pip install -r requirements/optional.txt
- name: Run codegen
run: |
python setup.py codegen
- name: Run validation (black/flake8/pytest)
run: |
python setup.py validate
black --check slack/ slack_sdk/ tests/ integration_tests/
flake8 slack/ slack_sdk/
PYTHONPATH=$PWD:$PYTHONPATH pytest --cov-report=xml --cov=slack_sdk/ tests/
- name: Run tests for SQLAlchemy v1.4 (backward-compatibility)
run: |
# Install v1.4 for testing
pip install "SQLAlchemy>=1.4,<2"
python setup.py unit_tests --test-target tests/slack_sdk/oauth/installation_store/test_sqlalchemy.py && \
python setup.py unit_tests --test-target tests/slack_sdk/oauth/state_store/test_sqlalchemy.py
PYTHONPATH=$PWD:$PYTHONPATH pytest tests/slack_sdk/oauth/installation_store/test_sqlalchemy.py
PYTHONPATH=$PWD:$PYTHONPATH pytest tests/slack_sdk/oauth/state_store/test_sqlalchemy.py
- name: Run codecov (only with latest supported version)
if: startsWith(matrix.python-version, '3.13')
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
# python setup.py validate generates the coverage file
# Run validation generates the coverage file
files: ./coverage.xml
2 changes: 1 addition & 1 deletion integration_tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ def is_not_specified() -> bool:
module = inspect.getmodule(frame[0])
filepath: str = module.__file__

# python setup.py integration_tests --test-target=web/test_issue_560.py
# ./scripts/run_integration_tests.sh web/test_issue_560.py
test_target: str = sys.argv[1] # e.g., web/test_issue_560.py
return not test_target or not filepath.endswith(test_target)
2 changes: 1 addition & 1 deletion integration_tests/web/test_issue_1143.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class TestWebClient(unittest.TestCase):
"""Runs integration tests with real Slack API
export SLACK_SDK_TEST_BOT_TOKEN=xoxb-xxx
python setup.py run_integration_tests --test-target integration_tests/web/test_issue_1143.py
./scripts/run_integration_tests.sh integration_tests/web/test_issue_1143.py
https://github.com/slackapi/python-slack-sdk/issues/1143
"""
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/web/test_issue_770.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class TestWebClient(unittest.TestCase):
export SLACK_SDK_TEST_BOT_TOKEN=xoxb-xxx
export SLACK_SDK_TEST_WEB_TEST_CHANNEL_ID=C111
python setup.py run_integration_tests --test-target integration_tests/web/test_issue_770.py
./scripts/run_integration_tests.sh integration_tests/web/test_issue_770.py
https://github.com/slackapi/python-slack-sdk/issues/770
"""
Expand Down
102 changes: 102 additions & 0 deletions scripts/codegen.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import sys
import argparse

parser = argparse.ArgumentParser()
parser.add_argument("-p", "--path", help="Path to the project source code.", type=str)
if len(sys.argv) == 1:
parser.print_help(sys.stderr)
sys.exit(1)
args = parser.parse_args()

header = (
"# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"
"#\n"
"# *** DO NOT EDIT THIS FILE ***\n"
"#\n"
"# 1) Modify slack_sdk/web/client.py\n"
"# 2) Run `python scripts/codegen.py`\n"
"# 3) Run `black slack_sdk/`\n"
"#\n"
"# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"
"\n"
)

with open(f"{args.path}/slack_sdk/web/client.py", "r") as original:
source = original.read()
import re

async_source = header + source
async_source = re.sub(" def ", " async def ", async_source)
async_source = re.sub("from asyncio import Future\n", "", async_source)
async_source = re.sub(r"return self.api_call\(", "return await self.api_call(", async_source)
async_source = re.sub("-> SlackResponse", "-> AsyncSlackResponse", async_source)
async_source = re.sub(
"from .base_client import BaseClient, SlackResponse",
"from .async_base_client import AsyncBaseClient, AsyncSlackResponse",
async_source,
)
# from slack_sdk import WebClient
async_source = re.sub(
r"class WebClient\(BaseClient\):",
"class AsyncWebClient(AsyncBaseClient):",
async_source,
)
async_source = re.sub(
"from slack_sdk import WebClient",
"from slack_sdk.web.async_client import AsyncWebClient",
async_source,
)
async_source = re.sub(r"= WebClient\(", "= AsyncWebClient(", async_source)
async_source = re.sub(
r" self.files_getUploadURLExternal\(",
" await self.files_getUploadURLExternal(",
async_source,
)
async_source = re.sub(
r" self._upload_file\(",
" await self._upload_file(",
async_source,
)
async_source = re.sub(
r" self.files_completeUploadExternal\(",
" await self.files_completeUploadExternal(",
async_source,
)
async_source = re.sub(
r" self.files_info\(",
" await self.files_info(",
async_source,
)
async_source = re.sub(
"_attach_full_file_metadata",
"_attach_full_file_metadata_async",
async_source,
)
async_source = re.sub(
r" _attach_full_file_metadata_async\(",
" await _attach_full_file_metadata_async(",
async_source,
)
with open(f"{args.path}/slack_sdk/web/async_client.py", "w") as output:
output.write(async_source)

legacy_source = header + "from asyncio import Future\n" + source
legacy_source = re.sub("-> SlackResponse", "-> Union[Future, SlackResponse]", legacy_source)
legacy_source = re.sub(
"from .base_client import BaseClient, SlackResponse",
"from .legacy_base_client import LegacyBaseClient, SlackResponse",
legacy_source,
)
legacy_source = re.sub(
r"class WebClient\(BaseClient\):",
"class LegacyWebClient(LegacyBaseClient):",
legacy_source,
)
legacy_source = re.sub(
"from slack_sdk import WebClient",
"from slack_sdk.web.legacy_client import LegacyWebClient",
legacy_source,
)
legacy_source = re.sub(r"= WebClient\(", "= LegacyWebClient(", legacy_source)
with open(f"{args.path}/slack_sdk/web/legacy_client.py", "w") as output:
output.write(legacy_source)
7 changes: 4 additions & 3 deletions scripts/run_integration_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ pip install -U pip
pip install -r requirements/testing.txt \
-r requirements/optional.txt

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

test_target="${1:-integration_tests/}"
python setup.py integration_tests --test-target $test_target
test_target="${1:-tests/integration_tests/}"
PYTHONPATH=$PWD:$PYTHONPATH pytest $test_target
5 changes: 3 additions & 2 deletions scripts/run_unit_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ pip install -U pip
pip install -r requirements/testing.txt \
-r requirements/optional.txt

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

test_target="${1:-tests/}"
python setup.py unit_tests --test-target $test_target
PYTHONPATH=$PWD:$PYTHONPATH pytest $test_target
13 changes: 10 additions & 3 deletions scripts/run_validation.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/bash
# ./scripts/run_validation.sh
# all: ./scripts/run_validation.sh
# single: ./scripts/run_validation.sh tests/slack_sdk_async/web/test_web_client_coverage.py

set -e

Expand All @@ -10,5 +11,11 @@ pip install -U pip setuptools wheel
pip install -r requirements/testing.txt \
-r requirements/optional.txt

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

black --check slack/ slack_sdk/ tests/ integration_tests/
flake8 slack/ slack_sdk/

test_target="${1:-tests/}"
PYTHONPATH=$PWD:$PYTHONPATH pytest --cov-report=xml --cov=slack_sdk/ $test_target
Loading
Loading