-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
201 lines (144 loc) · 4.93 KB
/
setup.py
File metadata and controls
201 lines (144 loc) · 4.93 KB
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
from __future__ import annotations
import os
from subprocess import run
from typing import List, NamedTuple, Optional, Union
from distutils.errors import DistutilsError
from distutils import log
from setuptools import Command, setup, find_packages
#
# The `check` subcommand
#
class Check(NamedTuple):
cmd: Union[str, List[str]]
shell: bool = False
def display_cmd(self) -> str:
return self.cmd if isinstance(self.cmd, str) else ' '.join(self.cmd)
class CheckCommand(Command): # type: ignore
user_options: List[str] = []
def initialize_options(self) -> None:
pass
def finalize_options(self) -> None:
pass
def run(self) -> None:
here = os.path.dirname(os.path.abspath(__file__))
checks: List[Union[Check, str]] = [
# fmt: off
'coverage',
# Specify files and directories directly because black's file ignoring
# will look at the absolute path:
# https://github.com/python/black/issues/712
Check('black --check --diff *.py git_fold', shell=True),
Check(['mypy', '--strict', '--ignore-missing-imports', '.']),
Check('pylint *.py git_fold', shell=True),
]
return_codes: List[Union[bool, int]] = []
for check_count, check in enumerate(checks, start=1):
self.announce(
f'\nCheck {check_count}: {display_check(check)}', level=log.INFO
)
if isinstance(check, str):
success = True
try:
self.run_command(check)
except DistutilsError:
success = False
return_codes.append(success)
else:
res = run(check.cmd, shell=check.shell, cwd=here)
self.announce(f'Return code: {res.returncode}', level=log.DEBUG)
return_codes.append(res.returncode)
self.announce('\nResults:', level=log.INFO)
for check_count, (check, retcode) in enumerate(
zip(checks, return_codes), start=1
):
res_out = (
' ' if isinstance(retcode, bool) or retcode == 0 else f'({retcode})'
)
self.announce(
f'{get_mark(retcode)} {res_out: <4}{check_count}: {display_check(check)}',
level=log.INFO,
)
if not all(retcode_success(retcode) for retcode in return_codes):
raise DistutilsError('Some checks unsuccessful')
def display_check(check: Union[Check, str]) -> str:
if isinstance(check, str):
return f'setup.py {check}'
return check.display_cmd()
def retcode_success(retcode: Union[bool, int]) -> bool:
if isinstance(retcode, bool):
return retcode
return retcode == 0
def get_mark(retcode: Union[bool, int]) -> str:
return '✨' if retcode_success(retcode) else '❌'
#
# The `coverage` subcommand
#
class CoverageCommand(Command): # type: ignore
user_options: List[str] = []
def initialize_options(self) -> None:
pass
def finalize_options(self) -> None:
pass
def run(self) -> None:
from coverage import Coverage
cov = Coverage()
failed_message: Optional[str] = None
cov.start()
try:
self.run_command('test')
except DistutilsError as exc:
failed_message = str(exc)
finally:
cov.save()
cov.report()
cov.html_report()
if failed_message:
raise DistutilsError(f'tests failed: {failed_message}')
#
# Package declaration
#
with open('README.md') as f:
LONG_DESCRIPTION = f.read()
setup(
# fmt: off
name='git_fold',
version='0.0.1',
description='A git extention for flexible, convenient change backporting',
long_description=LONG_DESCRIPTION,
url='https://github.com/wabain/git-fold.git',
author='William Bain',
author_email='[email protected]',
license='MIT',
# See https://pypi.python.org/pypi?%3Aaction=list_classifiers
classifiers=[
'Development Status :: 3 - Alpha',
'Intended Audience :: Developers',
'Topic :: Software Development :: Version Control :: Git',
'License :: OSI Approved :: MIT License',
'Programming Language :: Python :: 3 :: Only',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
],
keywords='git rebase git-rebase vcs version-control',
packages=find_packages(exclude=['tests*']),
install_requires=[],
extras_require={
'dev': [
'black>=19.2<20',
'mypy==0.711',
'pylint>=2.3,<3',
],
'test': [
'coverage>=4.5,<5',
],
},
entry_points={
'console_scripts': [
'git-fold = git_fold.__main__:main',
],
},
cmdclass={
'check': CheckCommand,
'coverage': CoverageCommand,
}
)