-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpublish.py
More file actions
85 lines (60 loc) · 2.37 KB
/
Copy pathpublish.py
File metadata and controls
85 lines (60 loc) · 2.37 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
import os
import shutil
import sys
import contemply.cli as cli
root = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, (os.path.join(root, 'src')))
import atraxiflow
def clean_dist():
try:
shutil.rmtree(os.path.join(root, 'dist'))
except FileNotFoundError:
pass
def build_package():
print('Building package...')
print('Building for version {0}'.format(atraxiflow.__version__))
# Copy license file to it is included in the package
shutil.copy(os.path.join(root, 'LICENSE'), os.path.join(root, 'src', 'atraxiflow'))
os.system('python3 setup.py sdist bdist_wheel')
print('Checking files...')
for file in [os.path.join(root, 'dist', 'atraxi-flow-{0}.tar.gz').format(atraxiflow.__version__),
os.path.join(root, 'dist', 'atraxi_flow-{0}-py3-none-any.whl').format(atraxiflow.__version__)]:
if os.path.exists(file):
print('{0} okay'.format(os.path.basename(file)))
else:
print('Missing file: {0}'.format(file))
sys.exit(1)
def upload(dest='test'):
if dest == 'test':
# upload to testing environment
ret = os.system('python3 -m twine upload --repository-url https://test.pypi.org/legacy/ dist/*')
if ret != 0:
print('Error while uploading.')
elif dest == 'production':
# upload to production environment
ret = os.system('python3 -m twine upload dist/*')
if ret != 0:
print('Error while uploading.')
else:
print('Unknown destination')
def cleanup():
print('cleaning up...')
shutil.rmtree(os.path.join(root, 'build'))
shutil.rmtree(os.path.join(root, 'src', 'atraxi_flow.egg-info'))
os.unlink(os.path.join(root, 'src', 'atraxiflow', 'LICENSE'))
if __name__ == '__main__':
print('*** Publish to PyPi ***')
if cli.prompt('Do you want to run tests before publishing?'):
export = 'export PYTHONPATH="{0}:$PYTHONPATH"'.format(os.path.join(root, 'src'))
ret = os.system('{0} && pytest test --cov=atraxiflow'.format(export))
if ret != 0:
print('pytest failed.')
sys.exit()
else:
print('Tests okay.')
clean_dist()
build_package()
print('Preparing upload...')
production = cli.prompt('Is this a production release?', 'No')
upload('production' if production else 'test')
cleanup()