Skip to content

Commit

Permalink
Update setup.py and apply black formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
seratch committed Apr 22, 2022
1 parent c464e37 commit 1a7115f
Showing 1 changed file with 78 additions and 39 deletions.
117 changes: 78 additions & 39 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,17 @@
with codecs.open(os.path.join(here, "README.md"), encoding="utf-8") as readme:
long_description = readme.read()

tests_require = ["pytest>=5,<6", "pytest-cov>=2,<3", "codecov>=2,<3", "flake8>=3,<4", "black", "psutil"]
tests_require = [
"pytest>=5,<6",
"pytest-cov>=2,<3",
"codecov>=2,<3",
"flake8>=3,<4",
"black",
"psutil",
]

needs_pytest = {'pytest', 'test', 'ptr'}.intersection(sys.argv)
pytest_runner = ['pytest-runner'] if needs_pytest else []
needs_pytest = {"pytest", "test", "ptr"}.intersection(sys.argv)
pytest_runner = ["pytest-runner"] if needs_pytest else []


class BaseCommand(Command):
Expand Down Expand Up @@ -88,9 +95,9 @@ class ValidateCommand(BaseCommand):
description = "Run Python static code analyzer (flake8), formatter (black) and unit tests (pytest)."

user_options = [
('unit-test-target=', 'i', 'tests/{unit-test-target}'),
('utt=', 'i', 'tests/{utt}'),
('test-target=', 'i', 'tests/{test-target}')
("unit-test-target=", "i", "tests/{unit-test-target}"),
("utt=", "i", "tests/{utt}"),
("test-target=", "i", "tests/{test-target}"),
]

def initialize_options(self):
Expand All @@ -102,27 +109,37 @@ def run(self):
with open("./slack/web/client.py", "r") as original:
source = original.read()
import re
async_source = "# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n" \
"#\n" \
"# *** DO NOT EDIT THIS FILE ***\n" \
"#\n" \
"# 1) Modify slack/web/client.py\n" \
"# 2) Run `python setup.py validate`\n" \
"#\n" \
"# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n" \
"\n" \
+ source

async_source = (
"# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"
"#\n"
"# *** DO NOT EDIT THIS FILE ***\n"
"#\n"
"# 1) Modify slack/web/client.py\n"
"# 2) Run `python setup.py validate`\n"
"#\n"
"# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"
"\n" + 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("return self.api_call\(", "return await self.api_call(", async_source)
async_source = re.sub("Union\[Future, SlackResponse\]", "AsyncSlackResponse", async_source)
async_source = re.sub(
"return self.api_call\(", "return await self.api_call(", async_source
)
async_source = re.sub(
"Union\[Future, SlackResponse\]", "AsyncSlackResponse", async_source
)
async_source = re.sub(
"from slack.web.base_client import BaseClient, SlackResponse",
"from slack.web.async_base_client import AsyncBaseClient, AsyncSlackResponse", async_source)
"from slack.web.async_base_client import AsyncBaseClient, AsyncSlackResponse",
async_source,
)
async_source = re.sub(
"class WebClient\(BaseClient\):",
"class AsyncWebClient(AsyncBaseClient):", async_source)
with open('./slack/web/async_client.py', 'w') as output:
"class AsyncWebClient(AsyncBaseClient):",
async_source,
)
with open("./slack/web/async_client.py", "w") as output:
output.write(async_source)

self._run(
Expand All @@ -132,7 +149,9 @@ def run(self):
self._run("Running black…", [sys.executable, "-m", "black", f"{here}/slack"])
self._run("Running flake8…", [sys.executable, "-m", "flake8", f"{here}/slack"])

target = (self.utt or self.unit_test_target or self.test_target).replace("tests/", "")
target = (self.utt or self.unit_test_target or self.test_target).replace(
"tests/", ""
)
self._run(
"Running pytest…",
[
Expand All @@ -152,9 +171,13 @@ class RunIntegrationTestsCommand(BaseCommand):
description = "Run integration tests (pytest)."

user_options = [
('integration-test-target=', 'i', 'integration_tests/{integration-test-target}'),
('itt=', 'i', 'integration_tests/{itt}'),
('test-target=', 'i', 'integration_tests/{test-target}')
(
"integration-test-target=",
"i",
"integration_tests/{integration-test-target}",
),
("itt=", "i", "integration_tests/{itt}"),
("test-target=", "i", "integration_tests/{test-target}"),
]

def initialize_options(self):
Expand All @@ -163,7 +186,9 @@ def initialize_options(self):
self.test_target = ""

def run(self):
target = (self.itt or self.integration_test_target or self.test_target).replace("integration_tests/", "")
target = (self.itt or self.integration_test_target or self.test_target).replace(
"integration_tests/", ""
)
self._run(
"Running pytest…",
[
Expand All @@ -183,11 +208,15 @@ class RunAllTestsCommand(ValidateCommand):
description = ValidateCommand.description + "\nRun integration tests (pytest)."

user_options = [
('unit-test-target=', 'i', 'tests/{unit-test-target}'),
('utt=', 'i', 'tests/{utt}'),
('integration-test-target=', 'i', 'integration_tests/{integration-test-target}'),
('itt=', 'i', 'integration_tests/{itt}'),
('test-target=', 'i', 'integration_tests/{test-target}')
("unit-test-target=", "i", "tests/{unit-test-target}"),
("utt=", "i", "tests/{utt}"),
(
"integration-test-target=",
"i",
"integration_tests/{integration-test-target}",
),
("itt=", "i", "integration_tests/{itt}"),
("test-target=", "i", "integration_tests/{test-target}"),
]

def initialize_options(self):
Expand All @@ -199,7 +228,9 @@ def initialize_options(self):

def run(self):
ValidateCommand.run(self)
target = (self.itt or self.integration_test_target or self.test_target).replace("integration_tests/", "")
target = (self.itt or self.integration_test_target or self.test_target).replace(
"integration_tests/", ""
)
self._run(
"Running pytest…",
[
Expand All @@ -216,11 +247,12 @@ def run(self):
setup(
name="slackclient",
version=__version__,
description="Slack API clients for Web API and RTM API",
description="Slack API clients for Web API and RTM API (Legacy) - "
+ "Please use https://pypi.org/project/slack-sdk/ instead.",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/slackapi/python-slackclient",
author="Slack Technologies, Inc.",
url="https://github.com/slackapi/python-slack-sdk",
author="Slack Technologies, LLC",
author_email="opensource@slack.com",
python_requires=">=3.6.0",
include_package_data=True,
Expand All @@ -237,14 +269,21 @@ def run(self):
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
],
keywords="slack slack-web slack-rtm chat chatbots bots chatops",
packages=find_packages(
exclude=["docs", "docs-src", "integration_tests", "tests", "tests.*", "tutorial"]
exclude=[
"docs",
"docs-src",
"integration_tests",
"tests",
"tests.*",
"tutorial",
]
),
install_requires=[
"aiohttp>3.5.2,<4.0.0" # TODO: move to extras_require in v3
],
install_requires=["aiohttp>3.5.2,<4.0.0"], # TODO: move to extras_require in v3
extras_require={"optional": ["aiodns>1.0"]},
setup_requires=pytest_runner,
test_suite="tests",
Expand Down

0 comments on commit 1a7115f

Please sign in to comment.