Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
cpython/Tools/msi/make_zip.py at pythoncapi · pythoncapi/cpython · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
View all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
Uh oh!
There was an error while loading.
Please reload this page
.
pythoncapi
/
cpython
Public
forked from
python/cpython
Notifications
You must be signed in to change notification settings
Fork
0
Star
1
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Files
Expand file tree
pythoncapi
Breadcrumbs
cpython
/
Tools
/
msi
/
make_zip.py
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
250 lines (208 loc) · 7.55 KB
pythoncapi
Breadcrumbs
cpython
/
Tools
/
msi
/
make_zip.py
Copy path
Top
File metadata and controls
Code
Blame
250 lines (208 loc) · 7.55 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
import
argparse
import
py_compile
import
re
import
sys
import
shutil
import
stat
import
os
import
tempfile
from
itertools
import
chain
from
pathlib
import
Path
from
zipfile
import
ZipFile
,
ZIP_DEFLATED
TKTCL_RE
=
re
.
compile
(
r'^(_?tk|tcl).+\.(pyd|dll)'
,
re
.
IGNORECASE
)
DEBUG_RE
=
re
.
compile
(
r'_d\.(pyd|dll|exe|pdb|lib)$'
,
re
.
IGNORECASE
)
PYTHON_DLL_RE
=
re
.
compile
(
r'python\d\d?\.dll$'
,
re
.
IGNORECASE
)
DEBUG_FILES
=
{
'_ctypes_test'
,
'_testbuffer'
,
'_testcapi'
,
'_testconsole'
,
'_testimportmultiple'
,
'_testmultiphase'
,
'xxlimited'
,
'python3_dstub'
,
}
EXCLUDE_FROM_LIBRARY
=
{
'__pycache__'
,
'idlelib'
,
'pydoc_data'
,
'site-packages'
,
'tkinter'
,
'turtledemo'
,
}
EXCLUDE_FROM_EMBEDDABLE_LIBRARY
=
{
'ensurepip'
,
'venv'
,
}
EXCLUDE_FILE_FROM_LIBRARY
=
{
'bdist_wininst.py'
,
}
EXCLUDE_FILE_FROM_LIBS
=
{
'liblzma'
,
'python3stub'
,
}
EXCLUDED_FILES
=
{
'pyshellext'
,
}
def
is_not_debug
(
p
):
if
DEBUG_RE
.
search
(
p
.
name
):
return
False
if
TKTCL_RE
.
search
(
p
.
name
):
return
False
return
p
.
stem
.
lower
()
not
in
DEBUG_FILES
and
p
.
stem
.
lower
()
not
in
EXCLUDED_FILES
def
is_not_debug_or_python
(
p
):
return
is_not_debug
(
p
)
and
not
PYTHON_DLL_RE
.
search
(
p
.
name
)
def
include_in_lib
(
p
):
name
=
p
.
name
.
lower
()
if
p
.
is_dir
():
if
name
in
EXCLUDE_FROM_LIBRARY
:
return
False
if
name
==
'test'
and
p
.
parts
[
-
2
].
lower
()
==
'lib'
:
return
False
if
name
in
{
'test'
,
'tests'
}
and
p
.
parts
[
-
3
].
lower
()
==
'lib'
:
return
False
return
True
if
name
in
EXCLUDE_FILE_FROM_LIBRARY
:
return
False
suffix
=
p
.
suffix
.
lower
()
return
suffix
not
in
{
'.pyc'
,
'.pyo'
,
'.exe'
}
def
include_in_embeddable_lib
(
p
):
if
p
.
is_dir
()
and
p
.
name
.
lower
()
in
EXCLUDE_FROM_EMBEDDABLE_LIBRARY
:
return
False
return
include_in_lib
(
p
)
def
include_in_libs
(
p
):
if
not
is_not_debug
(
p
):
return
False
return
p
.
stem
.
lower
()
not
in
EXCLUDE_FILE_FROM_LIBS
def
include_in_tools
(
p
):
if
p
.
is_dir
()
and
p
.
name
.
lower
()
in
{
'scripts'
,
'i18n'
,
'pynche'
,
'demo'
,
'parser'
}:
return
True
return
p
.
suffix
.
lower
()
in
{
'.py'
,
'.pyw'
,
'.txt'
}
BASE_NAME
=
'python{0.major}{0.minor}'
.
format
(
sys
.
version_info
)
FULL_LAYOUT
=
[
(
'/'
,
'$build'
,
'python.exe'
,
is_not_debug
),
(
'/'
,
'$build'
,
'pythonw.exe'
,
is_not_debug
),
(
'/'
,
'$build'
,
'python{}.dll'
.
format
(
sys
.
version_info
.
major
),
is_not_debug
),
(
'/'
,
'$build'
,
'{}.dll'
.
format
(
BASE_NAME
),
is_not_debug
),
(
'DLLs/'
,
'$build'
,
'*.pyd'
,
is_not_debug
),
(
'DLLs/'
,
'$build'
,
'*.dll'
,
is_not_debug_or_python
),
(
'include/'
,
'include'
,
'*.h'
,
None
),
(
'include/'
,
'PC'
,
'pyconfig.h'
,
None
),
(
'Lib/'
,
'Lib'
,
'**/*'
,
include_in_lib
),
(
'libs/'
,
'$build'
,
'*.lib'
,
include_in_libs
),
(
'Tools/'
,
'Tools'
,
'**/*'
,
include_in_tools
),
]
EMBED_LAYOUT
=
[
(
'/'
,
'$build'
,
'python*.exe'
,
is_not_debug
),
(
'/'
,
'$build'
,
'*.pyd'
,
is_not_debug
),
(
'/'
,
'$build'
,
'*.dll'
,
is_not_debug
),
(
'{}.zip'
.
format
(
BASE_NAME
),
'Lib'
,
'**/*'
,
include_in_embeddable_lib
),
]
if
os
.
getenv
(
'DOC_FILENAME'
):
FULL_LAYOUT
.
append
((
'Doc/'
,
'Doc/build/htmlhelp'
,
os
.
getenv
(
'DOC_FILENAME'
),
None
))
if
os
.
getenv
(
'VCREDIST_PATH'
):
FULL_LAYOUT
.
append
((
'/'
,
os
.
getenv
(
'VCREDIST_PATH'
),
'vcruntime*.dll'
,
None
))
EMBED_LAYOUT
.
append
((
'/'
,
os
.
getenv
(
'VCREDIST_PATH'
),
'vcruntime*.dll'
,
None
))
def
copy_to_layout
(
target
,
rel_sources
):
count
=
0
if
target
.
suffix
.
lower
()
==
'.zip'
:
if
target
.
exists
():
target
.
unlink
()
with
ZipFile
(
str
(
target
),
'w'
,
ZIP_DEFLATED
)
as
f
:
with
tempfile
.
TemporaryDirectory
()
as
tmpdir
:
for
s
,
rel
in
rel_sources
:
if
rel
.
suffix
.
lower
()
==
'.py'
:
pyc
=
Path
(
tmpdir
)
/
rel
.
with_suffix
(
'.pyc'
).
name
try
:
py_compile
.
compile
(
str
(
s
),
str
(
pyc
),
str
(
rel
),
doraise
=
True
,
optimize
=
2
)
except
py_compile
.
PyCompileError
:
f
.
write
(
str
(
s
),
str
(
rel
))
else
:
f
.
write
(
str
(
pyc
),
str
(
rel
.
with_suffix
(
'.pyc'
)))
else
:
f
.
write
(
str
(
s
),
str
(
rel
))
count
+=
1
else
:
for
s
,
rel
in
rel_sources
:
dest
=
target
/
rel
try
:
dest
.
parent
.
mkdir
(
parents
=
True
)
except
FileExistsError
:
pass
if
dest
.
is_file
():
dest
.
chmod
(
stat
.
S_IWRITE
)
shutil
.
copy
(
str
(
s
),
str
(
dest
))
if
dest
.
is_file
():
dest
.
chmod
(
stat
.
S_IWRITE
)
count
+=
1
return
count
def
rglob
(
root
,
pattern
,
condition
):
dirs
=
[
root
]
recurse
=
pattern
[:
3
]
in
{
'**/'
,
'**
\\
'
}
while
dirs
:
d
=
dirs
.
pop
(
0
)
for
f
in
d
.
glob
(
pattern
[
3
:]
if
recurse
else
pattern
):
if
recurse
and
f
.
is_dir
()
and
(
not
condition
or
condition
(
f
)):
dirs
.
append
(
f
)
elif
f
.
is_file
()
and
(
not
condition
or
condition
(
f
)):
yield
f
,
f
.
relative_to
(
root
)
def
main
():
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
'-s'
,
'--source'
,
metavar
=
'dir'
,
help
=
'The directory containing the repository root'
,
type
=
Path
)
parser
.
add_argument
(
'-o'
,
'--out'
,
metavar
=
'file'
,
help
=
'The name of the output archive'
,
type
=
Path
,
default
=
None
)
parser
.
add_argument
(
'-t'
,
'--temp'
,
metavar
=
'dir'
,
help
=
'A directory to temporarily extract files into'
,
type
=
Path
,
default
=
None
)
parser
.
add_argument
(
'-e'
,
'--embed'
,
help
=
'Create an embedding layout'
,
action
=
'store_true'
,
default
=
False
)
parser
.
add_argument
(
'-b'
,
'--build'
,
help
=
'Specify the build directory'
,
type
=
Path
,
default
=
None
)
ns
=
parser
.
parse_args
()
source
=
ns
.
source
or
(
Path
(
__file__
).
resolve
().
parent
.
parent
.
parent
)
out
=
ns
.
out
build
=
ns
.
build
or
Path
(
sys
.
exec_prefix
)
assert
isinstance
(
source
,
Path
)
assert
not
out
or
isinstance
(
out
,
Path
)
assert
isinstance
(
build
,
Path
)
if
ns
.
temp
:
temp
=
ns
.
temp
delete_temp
=
False
else
:
temp
=
Path
(
tempfile
.
mkdtemp
())
delete_temp
=
True
if
out
:
try
:
out
.
parent
.
mkdir
(
parents
=
True
)
except
FileExistsError
:
pass
try
:
temp
.
mkdir
(
parents
=
True
)
except
FileExistsError
:
pass
layout
=
EMBED_LAYOUT
if
ns
.
embed
else
FULL_LAYOUT
try
:
for
t
,
s
,
p
,
c
in
layout
:
if
s
==
'$build'
:
fs
=
build
else
:
fs
=
source
/
s
files
=
rglob
(
fs
,
p
,
c
)
extra_files
=
[]
if
s
==
'Lib'
and
p
==
'**/*'
:
extra_files
.
append
((
source
/
'tools'
/
'msi'
/
'distutils.command.bdist_wininst.py'
,
Path
(
'distutils'
)
/
'command'
/
'bdist_wininst.py'
))
copied
=
copy_to_layout
(
temp
/
t
.
rstrip
(
'/'
),
chain
(
files
,
extra_files
))
print
(
'Copied {} files'
.
format
(
copied
))
if
ns
.
embed
:
with
open
(
str
(
temp
/
(
BASE_NAME
+
'._pth'
)),
'w'
)
as
f
:
print
(
BASE_NAME
+
'.zip'
,
file
=
f
)
print
(
'.'
,
file
=
f
)
print
(
''
,
file
=
f
)
print
(
'# Uncomment to run site.main() automatically'
,
file
=
f
)
print
(
'#import site'
,
file
=
f
)
if
out
:
total
=
copy_to_layout
(
out
,
rglob
(
temp
,
'**/*'
,
None
))
print
(
'Wrote {} files to {}'
.
format
(
total
,
out
))
finally
:
if
delete_temp
:
shutil
.
rmtree
(
temp
,
True
)
if
__name__
==
"__main__"
:
sys
.
exit
(
int
(
main
()
or
0
))
You can’t perform that action at this time.