-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmkdist.py
168 lines (144 loc) · 4.88 KB
/
mkdist.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Created on 2019年9月9日
@author: Irony
@site: https://pyqt5.com https://github.com/892768447
@email: 892768447@qq.com
@file: mkdist
@description:
"""
import argparse
import base64
import hashlib
import os
import shutil
from pathlib import Path
from zipfile import ZIP_DEFLATED, ZipFile
__Author__ = 'Irony'
__Copyright__ = 'Copyright (c) 2019'
parser = argparse.ArgumentParser()
parser.add_argument('-p', '--platform', default=None,
metavar='[Windows or Linux]',
choices=['Windows', 'Linux'],
required=True, help='System platform')
parser.add_argument('-a', '--arch', default=None, type=str.lower,
metavar='[x86 or x64]',
choices=['x86', 'x64'],
required=True, help='System Arch')
parser.add_argument('-v', '--version', default=None, type=str.lower,
required=True, help='PyQt5 Version')
parser.add_argument('-t', '--tags', default=['cp35', 'cp36', 'cp37', 'cp38'], nargs='+',
metavar='cp35 cp36 cp37 cp38', help='Python version')
args = parser.parse_args()
assert args.version != None
print('Platform:', args.platform)
print('Arch:', args.arch)
print('Version:', args.version)
Name = 'PyQtScript'
print('Name:', Name)
print(args.tags)
Tags = '.'.join(args.tags)
print('Tags:', Tags)
build_version = os.environ.get('APPVEYOR_BUILD_VERSION', '')
print('build_version :', build_version)
# 创建描述信息目录
dist_info_dir = '{0}-{1}.dist-info'.format(Name, build_version if build_version else args.version)
os.makedirs(dist_info_dir, exist_ok=True)
info_files = []
# 遍历需要安装的文件
pyqt_dir_path = '{0}/{1}/'.format(args.platform, args.arch)
for path in Path(os.path.join(pyqt_dir_path, 'PyQt5')).rglob('*'):
if path.is_file():
if '__pycache__' in str(path):
continue
info_files.append(path)
# 写入INSTALLER文件
path = os.path.join(dist_info_dir, 'INSTALLER')
info_files.append(Path(path))
with open(path, 'w') as fp:
fp.write('pip\n')
# 写入METADATA文件
METADATA = """Metadata-Version: 1.0
Name: {Name}
Version: {VersionMe}
Summary: Python bindings for the Qt WebKit library
Home-page: https://pyqt5.com
Author: Irony
Author-email: 892768447@qq.com
License: GPL v3
Platform: UNIX
Platform: Windows
Classifier: Programming Language :: Python :: 3.5
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Requires-Dist: PyQt5 (>={Version})
Installation
------------
Wheels for the GPL version for 32 Windows can be installed from PyPI::
pip install {Name}
The wheels include a copy of the required parts of the LGPL version of Qt.
""".format(Name=Name, VersionMe=build_version if build_version else args.version,
Version=args.version, Platform=args.platform)
path = os.path.join(dist_info_dir, 'METADATA')
info_files.append(Path(path))
with open(path, 'w') as fp:
fp.write(METADATA)
# 写入RECORD文件
record_path = os.path.join(dist_info_dir, 'RECORD')
with open(record_path, 'w') as fp:
for path in info_files:
if str(path).startswith(args.platform):
cpath = path.relative_to(pyqt_dir_path)
else:
cpath = path
path = str(path)
cpath = str(cpath).replace('\\', '/')
# 计算文件的sha256
data = open(path, 'rb').read()
digest = base64.urlsafe_b64encode(
hashlib.sha256(data).digest()).rstrip(b'=').decode('ascii')
fp.write(
'{0},sha256={1},{2}\n'.format(cpath, digest, len(data)))
fp.write('{0}/RECORD,,\n'.format(dist_info_dir))
info_files.append(Path(record_path))
# 写入WHEEL文件
if args.platform == 'Windows':
Tag = '{0}-none{1}'.format(Tags,
'-win32' if args.arch == 'x86' else '-win_amd64' if args.arch == 'x64' else '')
elif args.platform == 'Linux':
Tag = '{0}-abi3-manylinux1_x86_64'.format(Tags)
else:
Tag = '{0}-none'.format(Tags)
WHEEL = """Wheel-Version: 1.0
Generator: Irony
Root-Is-Purelib: false
Tag: {0}
""".format(Tag)
path = os.path.join(dist_info_dir, 'WHEEL')
info_files.append(Path(path))
with open(path, 'w') as fp:
fp.write(WHEEL)
print('wirte dist info ok')
# 生成whl文件
os.makedirs('dist', exist_ok=True)
dist_file = os.path.join(
'dist',
'{0}-{1}-{2}.whl'.format(Name, build_version if build_version else args.version, Tag))
print('make {0}'.format(dist_file))
zipfp = ZipFile(dist_file, 'w', ZIP_DEFLATED)
for path in info_files:
if str(path).startswith(args.platform):
cpath = path.relative_to(pyqt_dir_path)
else:
cpath = path
path = str(path)
cpath = str(cpath).replace('\\', '/')
zipfp.write(str(path), str(cpath))
zipfp.close()
try:
shutil.rmtree(dist_info_dir)
except Exception as e:
print(e)
print('make dist file ok')