-
Notifications
You must be signed in to change notification settings - Fork 16
/
setup.py
executable file
·161 lines (130 loc) · 4.36 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
#!/usr/bin/env python3
import functools
import pathlib
import re
import sys
from glob import glob
from setuptools import Command, find_packages, setup
from setuptools.command.test import test as TestCommand
try:
from pip.req import parse_requirements
except ImportError: # pip >= 10.0.0
from pip._internal.req import parse_requirements
WORK_DIR = pathlib.Path(__file__).parent
# Check python version
MINIMAL_PY_VERSION = (3, 7)
if sys.version_info < MINIMAL_PY_VERSION:
raise RuntimeError('aiograph works only with Python {}+'.format('.'.join(map(str, MINIMAL_PY_VERSION))))
@functools.lru_cache()
def get_version():
"""
Read version
:return: str
"""
txt = (WORK_DIR / 'aiograph' / '__init__.py').read_text('utf-8')
try:
return re.findall(r"^__version__ = '([^']+)'\r?$", txt, re.M)[0]
except IndexError:
raise RuntimeError('Unable to determine version.')
def get_description():
"""
Read full description from 'README.rst'
:return: description
:rtype: str
"""
with open('README.rst', 'r', encoding='utf-8') as f:
return f.read()
@functools.lru_cache()
def get_requirements(filename=None):
"""
Read requirements from 'requirements txt'
:return: requirements
:rtype: list
"""
if filename is None:
filename = 'requirements.txt'
file = WORK_DIR / filename
install_reqs = parse_requirements(str(file), session='hack')
try:
requirements = [str(ir.req) for ir in install_reqs]
except:
requirements = [str(ir.requirement) for ir in install_reqs]
return requirements
class PyTest(TestCommand):
user_options = []
def run(self):
import subprocess
errno = subprocess.call([sys.executable, '-m', 'pytest', '--cov=aiograph', 'tests'])
raise SystemExit(errno)
class UploadCommand(Command):
command_name = 'upload'
description = 'upload the distribution with the Python package index'
user_options = [
('set-tag', 't', 'set Git tag')
]
def initialize_options(self):
self.path = WORK_DIR / 'dist'
self.lib_version = get_version()
self.set_tag = False
def finalize_options(self):
opts = self.distribution.get_option_dict(self.get_command_name())
self.set_tag = 'set_tag' in opts
def find_target(self):
if not self.path.is_dir():
return
targets = []
for file in glob(str(self.path / f"aiograph-{self.lib_version}[-.]*")):
targets.append(str((self.path / file).absolute()))
return targets
def upload(self, targets):
import subprocess
errno = subprocess.call(['twine', 'upload'] + targets)
return errno
def create_tag(self):
import subprocess
errno = subprocess.call(['git', 'tag', f"v{self.lib_version}"])
return errno
def run(self):
targets = self.find_target()
if targets:
errno = self.upload(targets)
if not errno and self.set_tag:
errno = self.create_tag()
raise SystemExit(errno)
else:
raise FileNotFoundError('No files to be uploaded!')
setup(
name='aiograph',
version=get_version(),
packages=find_packages(exclude=('tests', 'tests.*', 'examples.*', 'docs',)),
url='https://github.com/aiogram/aiograph',
license='MIT',
requires_python='>=3.7',
author='Alex Root Junior',
author_email='[email protected]',
maintainer=', '.join((
'Alex Root Junior <[email protected]>',
)),
maintainer_email='[email protected]',
description='asynchronous Python Telegra.ph API wrapper',
long_description=get_description(),
classifiers=[
'Development Status :: 5 - Production/Stable',
'Environment :: Console',
'Framework :: AsyncIO',
'Intended Audience :: Developers',
'Intended Audience :: System Administrators',
'License :: OSI Approved :: MIT License',
'Programming Language :: Python :: 3.7',
'Topic :: Software Development :: Libraries :: Application Frameworks',
],
install_requires=get_requirements(),
tests_require=get_requirements('dev_requirements.txt'),
extras_require={
'dev': get_requirements('dev_requirements.txt')
},
cmdclass={
'test': PyTest,
UploadCommand.command_name: UploadCommand
}
)