-
Notifications
You must be signed in to change notification settings - Fork 4
/
create_wheel.py
141 lines (120 loc) · 4.77 KB
/
create_wheel.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
import os
from wheel.util import urlsafe_b64encode, native, open_for_csv
from wheel.archive import archive_wheelfile
import hashlib
import csv
from email.message import Message
from email.generator import Generator
import shutil
import sys
version = sys.argv[1]
pyversion = sys.argv[2]
os_name = sys.argv[3]
bitness = sys.argv[4]
dir_name = sys.argv[5]
if os_name=="linux":
tag = "cp%s-none-manylinux1_x86_64" % (pyversion)
elif os_name=="osx":
tag = ["cp%s-none-macosx_10_6_intel" % (pyversion),
"cp%s-none-macosx_10_9_intel" % (pyversion),
"cp%s-none-macosx_10_9_x86_64" % (pyversion),
"cp%s-none-macosx_10_10_intel" % (pyversion),
"cp%s-none-macosx_10_10_x86_64" % (pyversion)]
elif os_name=="windows":
if bitness=="64":
tag = "cp%s-none-win_amd64" % pyversion
else:
tag = "cp%s-none-win32" % pyversion
else:
raise Exception()
def write_record(bdist_dir, distinfo_dir):
record_path = os.path.join(distinfo_dir, 'RECORD')
record_relpath = os.path.relpath(record_path, bdist_dir)
def walk():
for dir, dirs, files in os.walk(bdist_dir):
dirs.sort()
for f in sorted(files):
yield os.path.join(dir, f)
def skip(path):
"""Wheel hashes every possible file."""
return (path == record_relpath)
with open_for_csv(record_path, 'w+') as record_file:
writer = csv.writer(record_file)
for path in walk():
relpath = os.path.relpath(path, bdist_dir)
if skip(relpath):
hash = ''
size = ''
else:
with open(path, 'rb') as f:
data = f.read()
digest = hashlib.sha256(data).digest()
hash = 'sha256=' + native(urlsafe_b64encode(digest))
size = len(data)
record_path = os.path.relpath(
path, bdist_dir).replace(os.path.sep, '/')
writer.writerow((record_path, hash, size))
wheel_dist_name = "casadi" + "-" + version
bdist_dir = dir_name
distinfo_dir = os.path.join(bdist_dir,'%s.dist-info' % wheel_dist_name)
if not os.path.exists(distinfo_dir):
os.mkdir(distinfo_dir)
print os.listdir(dir_name)
for d in os.listdir(dir_name):
if not d.startswith("casadi"):
shutil.move(os.path.join(dir_name, d),os.path.join(bdist_dir,"casadi"))
msg = Message()
msg['Wheel-Version'] = '1.0' # of the spec
#msg['Generator'] = generator
msg['Root-Is-Purelib'] = "false"
if isinstance(tag,list):
for t in tag: msg["Tag"] = t
else:
msg["Tag"] = tag
wheelfile_path = os.path.join(distinfo_dir, 'WHEEL')
with open(wheelfile_path, 'w') as f:
Generator(f, maxheaderlen=0).flatten(msg)
metadata_path = os.path.join(distinfo_dir, 'METADATA')
with open(metadata_path, 'w') as f:
f.write("""Metadata-Version: 2.0
Name: casadi
Version: %s
Summary: CasADi -- framework for algorithmic differentiation and numeric optimization
Home-page: http://casadi.org
Author: Joel Andersson, Joris Gillis, Greg Horn
Author-email: [email protected]
License: GNU Lesser General Public License v3 or later (LGPLv3+)
Download-URL: http://casadi.org
Platform: Windows
Platform: Linux
Platform: Mac OS-X
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved
Classifier: Programming Language :: C++
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 2
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.4
Classifier: Programming Language :: Python :: 3.5
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Topic :: Scientific/Engineering
Classifier: Operating System :: Microsoft :: Windows
Classifier: Operating System :: POSIX
Classifier: Operating System :: Unix
Classifier: Operating System :: MacOS
Requires-Dist: numpy
CasADi is a symbolic framework for numeric optimization implementing automatic differentiation in forward and reverse modes on sparse matrix-valued computational graphs. It supports self-contained C-code generation and interfaces state-of-the-art codes such as SUNDIALS, IPOPT etc. It can be used from C++, Python or Matlab/Octave.""" % (version))
#wheel_dist_name = wheel_dist_name+".post1"
if isinstance(tag,list):
fullname = wheel_dist_name+"-"+tag[0]
for t in tag[1:]:
fullname+="."+t.split("-")[-1]
else:
fullname = wheel_dist_name+"-"+tag
write_record(bdist_dir, distinfo_dir)
archive_wheelfile(fullname,dir_name)
#twine upload casadi-3.1.0-cp27-cp27m-manylinux1_x86_64.whl