This repository has been archived by the owner on Feb 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
add_build_no.py
65 lines (52 loc) · 2.43 KB
/
add_build_no.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
#!/usr/bin/env python
""" Adds a build number to passed wheel filenames
Usage:
python add_build_no.py <build_tag> <whl_fname> [<whl_fname> ...]
E.g.
python add_build_no.py 1 h5py-2.6.0-*whl
This will give you output like so::
Copying h5py-2.6.0-cp27-cp27m-manylinux1_i686.whl to h5py-2.6.0-1-cp27-cp27m-manylinux1_i686.whl
Copying h5py-2.6.0-cp27-cp27m-manylinux1_x86_64.whl to h5py-2.6.0-1-cp27-cp27m-manylinux1_x86_64.whl
Copying h5py-2.6.0-cp27-cp27mu-manylinux1_i686.whl to h5py-2.6.0-1-cp27-cp27mu-manylinux1_i686.whl
Copying h5py-2.6.0-cp27-cp27mu-manylinux1_x86_64.whl to h5py-2.6.0-1-cp27-cp27mu-manylinux1_x86_64.whl
Copying h5py-2.6.0-cp34-cp34m-manylinux1_i686.whl to h5py-2.6.0-1-cp34-cp34m-manylinux1_i686.whl
Copying h5py-2.6.0-cp34-cp34m-manylinux1_x86_64.whl to h5py-2.6.0-1-cp34-cp34m-manylinux1_x86_64.whl
Copying h5py-2.6.0-cp35-cp35m-manylinux1_i686.whl to h5py-2.6.0-1-cp35-cp35m-manylinux1_i686.whl
Copying h5py-2.6.0-cp35-cp35m-manylinux1_x86_64.whl to h5py-2.6.0-1-cp35-cp35m-manylinux1_x86_64.whl
"""
from __future__ import print_function
import os
from os.path import split as psplit, join as pjoin
from shutil import copyfile
import argparse
from wheel.install import WheelFile
def make_parser():
parser = argparse.ArgumentParser()
parser.add_argument('-s', '--build-suffix',
type=str,
default='-',
help='Suffix for build number')
parser.add_argument('-r', '--rename',
action='store_true',
help='If set, remove original wheel')
parser.add_argument('build_tag', help="Build tag")
parser.add_argument('files', nargs="*", help="Input files")
return parser
def main():
args = make_parser().parse_args()
for wheel_fname in args.files:
path, fname = psplit(wheel_fname)
wf = WheelFile(fname)
parsed = wf.parsed_filename.groupdict()
parsed['build'] = args.build_tag
parsed['build_suffix'] = args.build_suffix
out_fname = ('{name}-{ver}{build_suffix}{build}-{pyver}-{abi}-{plat}'
'.whl'.format(**parsed))
out_path = pjoin(path, out_fname)
print('{} {} to {}'.format(
'Renaming' if args.rename else 'Copying', wheel_fname, out_path))
copyfile(wheel_fname, out_path)
if args.rename:
os.unlink(wheel_fname)
if __name__ == '__main__':
main()