This repository has been archived by the owner on Oct 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup.py
183 lines (139 loc) · 4.6 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
from setuptools import find_packages, setup, Command, errors
from shutil import rmtree
import os
import sys
# Package meta-data.
NAME = "http-types"
DESCRIPTION = "Types for HTTP requests and responses"
URL = "http://github.com/Meeshkan/py-http-types"
EMAIL = "dev@meeshkan.com"
AUTHOR = "Meeshkan Dev Team"
REQUIRES_PYTHON = ">=3.6.0"
here = os.path.abspath(os.path.dirname(__file__))
with open(os.path.join(here, "README.md"), encoding="utf-8") as f:
long_description = "\n" + f.read()
REQUIRED = ["python-dateutil>=2.8.1", "dataclasses", "typeguard>=2.7.0"]
DEV = [
"autopep8",
"black",
"flake8",
"jsonschema",
"pyhamcrest",
"pylint",
"pytest",
"pytest-testmon",
"pytest-watch",
"httpretty",
"setuptools",
"twine",
"wheel",
]
VERSION = "0.0.14"
# Optional packages
EXTRAS = {"dev": DEV}
class SetupCommand(Command):
"""Base class for setup.py commands with no arguments"""
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
@staticmethod
def status(s):
"""Prints things in bold."""
print("\033[1m{0}\033[0m".format(s))
def rmdir_if_exists(self, directory):
self.status("Deleting {}".format(directory))
rmtree(directory, ignore_errors=True)
def build():
return os.system(
"{executable} setup.py sdist bdist_wheel --universal".format(
executable=sys.executable
)
)
def type_check():
return os.system("pyright --lib -p pyrightconfig.json")
class BuildDistCommand(SetupCommand):
"""Support setup.py upload."""
description = "Build the package."
def run(self):
self.status("Removing previous builds...")
self.rmdir_if_exists(os.path.join(here, "dist"))
self.status("Building Source and Wheel (universal) distribution...")
exit_code = build()
if exit_code != 0:
raise errors.DistutilsError("Build failed.")
sys.exit()
class TypeCheckCommand(SetupCommand):
"""Run type-checking."""
description = "Run type-checking."
def run(self):
exit_code = type_check()
self.status("Typecheck exited with code: {code}".format(code=exit_code))
if exit_code != 0:
raise errors.DistutilsError("Type-checking failed.")
class TestCommand(SetupCommand):
"""Support setup.py test."""
description = "Run local test if they exist"
def run(self):
self.status("Formatting code with black...")
exit_code = os.system("black .")
if exit_code != 0:
raise errors.DistutilsError("Formatting with black failed.")
self.status("Running pytest...")
exit_code = os.system("pytest")
if exit_code != 0:
raise errors.DistutilsError("Tests failed.")
self.status("Running type-checking...")
exit_code = type_check()
if exit_code != 0:
raise errors.DistutilsError("Type-checking failed.")
self.status("Running flake8...")
exit_code = os.system(
"flake8 --exclude .git,.venv,__pycache__,build,dist")
if exit_code != 0:
raise errors.DistutilsError(" failed.")
class UploadCommand(SetupCommand):
"""Support setup.py upload."""
description = "Build and publish the package."
def run(self):
self.status("Removing previous builds...")
self.rmdir_if_exists(os.path.join(here, "dist"))
self.status("Building Source and Wheel (universal) distribution...")
exit_code = build()
if exit_code != 0:
raise errors.DistutilsError("Build failed.")
self.status("Uploading the package to PyPI via Twine...")
os.system("twine upload dist/*")
self.status("Pushing git tags...")
os.system("git tag v{about}".format(about=VERSION))
os.system("git push --tags")
sys.exit()
setup(
name=NAME,
version=VERSION,
description=DESCRIPTION,
long_description=long_description,
long_description_content_type="text/markdown",
url=URL,
author=AUTHOR,
author_email=EMAIL,
python_requires=REQUIRES_PYTHON,
license="MIT",
packages=find_packages(exclude=["tests"]),
include_package_data=True,
install_requires=REQUIRED,
extras_require=EXTRAS,
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
],
zip_safe=False,
cmdclass={
"dist": BuildDistCommand,
"test": TestCommand,
"typecheck": TypeCheckCommand,
"upload": UploadCommand,
},
)