-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsetup.py
158 lines (129 loc) · 4.48 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
import setuptools
import sys
import os
import io
import re
###############################################################################
name = 'veracode-python'
description = 'Python wrapper for the Veracode XML APIs'
install_requires = [
'lxml>=4.4.1',
'python-dateutil>=2.8.1',
'requests>=2.22.0',
'strconv>=0.4.2',
'xmltodict>=0.12.0',
'Click>=7.0',
'tabulate>=0.8.6',
'veracode-api-signing>=19.9.0'
]
keywords = []
entry_points = {'console_scripts': [
'veracode=veracode.utils.cli:main'
]}
python_requires='>= 3.5'
author = 'Chuck Orde'
author_email = 'chuckorde@gmail.com'
repo_user = 'chuckorde'
license = 'BSD-3-Clause'
classifiers=[
'Development Status :: 3 - Alpha',
'Intended Audience :: Developers',
'License :: OSI Approved :: BSD License',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
]
repo_name = name
repo_url = 'https://github.com/{}'
download_url = '{}/archive/v{}/.tar.gz'
release_api_url = 'https://api.github.com/repos/{}/{}/releases?access_token={}'
###############################################################################
# >>> python setup.py -q version
# 0.1.0
# >>> python setup.py -q version -i patch
# 0.1.1
# >>> python setup.py -q version -i minor
# 0.2.0
# -q turns off 'running version' output
class Version(setuptools.Command):
version_re = r"__version__ = '(.*?)'"
user_options = [ ('increment=', 'i', None), ]
def initialize_options(self):
self.increment = None
def finalize_options(self):
pass
def run(self):
if self.increment:
self._increment_semantic_version()
print(self.get())
def _increment_semantic_version(self):
current_version = self.get()
(major, minor, patch) = [int(n) for n in current_version.split('.')]
release = self.increment.upper()
assert(release in ['MAJOR', 'MINOR', 'PATCH'])
if release == 'PATCH': patch = patch + 1
if release == 'MINOR': minor = minor + 1; patch = 0
if release == 'MAJOR': major = major + 1; minor = 0; patch = 0
new_version = '{}.{}.{}'.format( major, minor, patch)
with io.open(self._find_init_file(), 'r', encoding='utf8') as f:
init_file = f.read()
with io.open(self._find_init_file(), 'w', encoding='utf8') as f:
f.write(init_file.replace(current_version, new_version))
def _find_init_file(self):
for walk in os.walk('.'):
(path, directory, module) = walk
if '__init__.py' in module:
return os.path.join(path, '__init__.py')
@classmethod
def get(self):
with io.open(self._find_init_file(self), 'r', encoding='utf8') as f:
version = re.search(self.version_re, f.read()).group(1)
return version
class Github(setuptools.Command):
user_options = [ ('create-release=', 'r', None), ]
def initialize_options(self):
self.create_release = None
def finalize_options(self):
pass
def run(self):
if not self.create_release:
raise Exception('You must specifiy --release=<API TOKEN>')
import requests
version = Version.get()
json = {
"tag_name": "v{}".format(version),
"target_commitish": "master",
"name": "v{}".format(version),
"body": "Release v{}".format(version),
"draft": False,
"prerelease": False
}
api_url = release_api_url.format(
repo_user, repo_name, self.create_release)
res = requests.post(api_url, json=json)
print (res.status_code, res.json())
version = Version.get()
url = '{}/{}'.format(repo_url.format(repo_user), repo_name)
download_url = download_url.format(url, version)
with io.open('README.md', 'r') as f:
long_description = f.read()
setuptools.setup(
name = name,
packages = setuptools.find_packages(),
version = version,
license = license,
description = description,
long_description = long_description,
long_description_content_type = 'text/markdown',
author = author,
author_email = author_email,
url = url,
download_url = download_url,
keywords = keywords,
install_requires = install_requires,
classifiers = classifiers,
python_requires = python_requires,
cmdclass = { 'version': Version, 'github': Github },
entry_points = entry_points,
)