-
Notifications
You must be signed in to change notification settings - Fork 1k
/
setup.py
209 lines (182 loc) · 8.05 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import os
import re
import sys
import subprocess
from setuptools import setup, Command, find_packages
from setuptools.command.test import test as TestCommand
__version__ = ''
with open('linebot/__about__.py', 'r') as fd:
reg = re.compile(r'__version__ = [\'"]([^\'"]*)[\'"]')
for line in fd:
m = reg.match(line)
if m:
__version__ = m.group(1)
break
def _requirements():
with open('requirements.txt', 'r') as fd:
return [name.strip() for name in fd.readlines()]
def _requirements_test():
with open('requirements-test.txt', 'r') as fd:
return [name.strip() for name in fd.readlines()]
class PyTest(TestCommand):
def finalize_options(self):
TestCommand.finalize_options(self)
self.test_args = []
self.test_suite = True
def run_tests(self):
# import here, cause outside the eggs aren't loaded
import pytest
errno = pytest.main(self.test_args)
sys.exit(errno)
class CodegenCommand(Command):
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
basedir = os.path.abspath(os.path.dirname(__file__))
header = (
"# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"
"#\n"
"# *** DO NOT EDIT THIS FILE ***\n"
"#\n"
"# 1) Modify linebot/api.py\n"
"# 2) Run `python setup.py codegen`\n"
"#\n"
"# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"
"\n"
)
with open(f"{basedir}/linebot/api.py", "r") as original:
source = original.read()
import re
async_source = header + source
async_source = re.sub(" def (?!__init__)", " async def ",
async_source)
async_source = re.sub("from .http_client import HttpClient, RequestsHttpClient", "",
async_source)
# Change the signature of the __init__.
# self, channel_access_token
async_source = re.sub(r"def __init__\(self, channel_access_token,",
"def __init__(self, channel_access_token, async_http_client,",
async_source)
async_source = re.sub(
r",\s*timeout=HttpClient.DEFAULT_TIMEOUT, http_client=RequestsHttpClient",
"", async_source)
async_source = re.sub(
r"if http_client:\n"
+ r"\s*self.http_client = http_client\(timeout=timeout\)\n"
+ r"\s*else:\n"
+ r"\s*self.http_client = RequestsHttpClient\(timeout=timeout\)",
"self.async_http_client = async_http_client", async_source)
async_source = re.sub(
r"\"\"\"__init__ method.*?\"\"\"\n",
'"""__init__ method.' + "\n\n"
+ " :param str channel_access_token: Your channel access token\n"
+ " :param str endpoint: (optional) Default is https://api.line.me\n"
+ " :param str data_endpoint: (optional) Default is https://api-data.line.me\n"
+ "\n\"\"\"\n"
, async_source, flags=re.DOTALL)
async_source = re.sub("'line-bot-sdk-python/'", '"line-bot-sdk-python-async/"',
async_source)
async_source = re.sub('"""linebot.api module."""', '"""linebot.async_api module."""',
async_source)
async_source = re.sub(
"self.(_get|_post|_delete|_put)", "await self.\\1", async_source
)
async_source = re.sub(
"self.http_client.(get|post|delete|put)", "await self.async_http_client.\\1",
async_source
)
async_source = re.sub(
"response.json", "(await response.json)", async_source
)
async_source = re.sub(
"from .http_client import HttpClient, RequestsHttpClient",
"from .async_http_client import AsyncHttpClient, AiohttpAsyncHttpClient",
async_source
)
async_source = re.sub(
"linebot.http_client.RequestsHttpClient",
"linebot.async_http_client.AiohttpAsyncHttpClient",
async_source
)
async_source = re.sub(
"HttpClient.DEFAULT_TIMEOUT", "AsyncHttpClient.DEFAULT_TIMEOUT", async_source
)
async_source = re.sub(
"RequestsHttpClient", "AiohttpAsyncHttpClient", async_source
)
async_source = re.sub(
"Default is self.http_client.timeout", "Default is self.async_http_client.timeout",
async_source
)
async_source = re.sub(
"self.__check_error", "await self.__check_error", async_source
)
async_source = re.sub(
"class LineBotApi",
"class AsyncLineBotApi", async_source
)
async_source = re.sub("stream=(stream|False|True), ", "", async_source)
async_source = re.sub("MessagingApiBlob'", "AsyncMessagingApiBlob'", async_source)
async_source = re.sub("MessagingApiBlob\\(", "AsyncMessagingApiBlob(", async_source)
async_source = re.sub("MessagingApi'", "AsyncMessagingApi'", async_source)
async_source = re.sub("MessagingApi\\(", "AsyncMessagingApi(", async_source)
async_source = re.sub("ManageAudience'", "AsyncManageAudience'", async_source)
async_source = re.sub("ManageAudience\\(", "AsyncManageAudience(", async_source)
async_source = re.sub("Insight'", "AsyncInsight'", async_source)
async_source = re.sub("Insight\\(", "AsyncInsight(", async_source)
async_source = re.sub("ChannelAccessToken'", "AsyncChannelAccessToken'", async_source)
async_source = re.sub("ChannelAccessToken\\(", "AsyncChannelAccessToken(", async_source)
with open(f"{basedir}/linebot/async_api.py", "w") as output:
output.write(async_source)
subprocess.check_call(
[sys.executable, "-m", "black", f"{basedir}/linebot/async_api.py"],
)
with open('README.rst', 'r') as fd:
long_description = fd.read()
setup(
name="line-bot-sdk",
version=__version__,
author="RyosukeHasebe",
author_email="[email protected]",
maintainer="RyosukeHasebe",
maintainer_email="[email protected]",
url="https://github.com/line/line-bot-sdk-python",
description="LINE Messaging API SDK for Python",
long_description=long_description,
license='Apache License 2.0',
packages=find_packages(include=["linebot*"]),
python_requires=">=3.9.0",
install_requires=_requirements(),
tests_require=_requirements_test(),
cmdclass={
'test': PyTest,
'codegen': CodegenCommand
},
classifiers=[
"Development Status :: 5 - Production/Stable",
"License :: OSI Approved :: Apache Software License",
"Intended Audience :: Developers",
"Programming Language :: Python",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Topic :: Software Development"
]
)