-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathupload.py
38 lines (29 loc) · 927 Bytes
/
upload.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
import urllib.request
from run_tests import do_call
from conf import PACKAGE_NAME, VERSION
def upload():
print('Uploading package...')
do_call(['python', 'setup.py', 'sdist'])
do_call(['python', 'setup.py', 'bdist_wheel'])
do_call(['twine', 'upload', 'dist/*'])
def version_exists():
url = ("https://pypi.python.org/pypi"
"?:action=display&name={package_name}&version={version}".format(
package_name=PACKAGE_NAME,
version=VERSION))
try:
req = urllib.request.Request(url, method="HEAD")
urllib.request.urlopen(req)
except urllib.error.HTTPError as e:
if e.code == 404:
return False
raise e
return True
def main():
if version_exists():
print('Please bump your version. Version {} already exists'.format(
VERSION))
else:
upload()
if __name__ == '__main__':
main()