-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.py
42 lines (31 loc) · 1.01 KB
/
build.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
# -*- coding: utf-8 -*-
import os
import sys
import shutil
from subprocess import call
def onerror(func, path, exc_info):
"""
Error handler for ``shutil.rmtree``.
If the error is due to an access error (read only file)
it attempts to add write permission and then retries.
If the error is for another reason it re-raises the error.
Usage : ``shutil.rmtree(path, onerror=onerror)``
"""
import stat
if not os.access(path, os.W_OK):
# Is the error an access error ?
os.chmod(path, stat.S_IWUSR)
func(path)
else:
raise Exception
if __name__ == '__main__':
# remove previous build
if os.path.exists('dist'):
shutil.rmtree('dist', onerror=onerror)
#
ext = 'zip' if sys.platform == 'win32' else 'gztar'
call(['python', 'setup.py', 'sdist', '--formats=' + ext, 'bdist_wheel'])
# remove service directories
for d in ['build', 'alphalogic_api.egg-info']:
if os.path.exists(d):
shutil.rmtree(d, onerror=onerror)