@@ -17,6 +17,7 @@ class PlatformConfig:
17
17
ext_suffixes : list [str ]
18
18
so_path : str
19
19
python_lib_dir : str
20
+ python_bin_paths : list [str ]
20
21
python_ext_dir : str
21
22
executable : str
22
23
@@ -42,6 +43,7 @@ def add_platform_config(*args, **kwargs):
42
43
ext_suffixes = ['.so' ],
43
44
so_path = 'lib/libpython3.12.so.1.0' ,
44
45
python_lib_dir = 'lib/python3.12' ,
46
+ python_bin_paths = ['bin' ],
45
47
python_ext_dir = 'lib/python3.12/lib-dynload' ,
46
48
executable = 'bin/python3.12' ,
47
49
)
@@ -55,6 +57,7 @@ def add_platform_config(*args, **kwargs):
55
57
ext_suffixes = ['.dll' , '.pyd' ],
56
58
so_path = 'python312.dll' ,
57
59
python_lib_dir = 'Lib' ,
60
+ python_bin_paths = ['python.exe' , 'pythonw.exe' ],
58
61
python_ext_dir = 'DLLs' ,
59
62
executable = 'python.exe' ,
60
63
)
@@ -68,6 +71,7 @@ def add_platform_config(*args, **kwargs):
68
71
ext_suffixes = ['.so' ],
69
72
so_path = 'lib/libpython3.12.dylib' ,
70
73
python_lib_dir = 'lib/python3.12' ,
74
+ python_bin_paths = ['bin' ],
71
75
python_ext_dir = 'lib/python3.12/lib-dynload' ,
72
76
executable = 'bin/python3.12' ,
73
77
)
@@ -81,6 +85,7 @@ def add_platform_config(*args, **kwargs):
81
85
ext_suffixes = ['.so' ],
82
86
so_path = 'lib/libpython3.12.dylib' ,
83
87
python_lib_dir = 'lib/python3.12' ,
88
+ python_bin_paths = ['bin' ],
84
89
python_ext_dir = 'lib/python3.12/lib-dynload' ,
85
90
executable = 'bin/python3.12' ,
86
91
)
@@ -105,32 +110,49 @@ def prepare_for_platform(platform: str, arch: str,
105
110
106
111
shutil .unpack_archive (src_dir / pathlib .Path (config .source_url ).name , extract_dir = src_dir )
107
112
108
- src = src_dir / 'python'
109
- src_lib_path = src / config .so_path
113
+ src_python = src_dir / 'python'
114
+ src_lib_path = src_python / config .so_path
110
115
lib_filename = pathlib .Path (config .so_path ).name
111
116
112
117
if platform == 'macos' :
113
118
# Rename the library id (which we depend on) to be in @rpath.
114
119
# (it defaults to /install/lib/)
115
- subprocess .run (['install_name_tool' , '-id' , f'@rpath/{ lib_filename } ' , src_lib_path ], check = True )
120
+ subprocess .run (['install_name_tool' , '-id' , f'@rpath/python/lib/{ lib_filename } ' , src_lib_path ], check = True )
121
+
116
122
117
- dest_dir .mkdir (parents = True , exist_ok = True )
118
- shutil .copy2 (src_lib_path , dest_dir )
123
+ dest_dir_python = dest_dir / 'python'
124
+ dest_dir_python_lib = dest_dir_python / 'lib'
125
+ dest_dir_python_lib .mkdir (parents = True , exist_ok = True )
119
126
127
+ shutil .copy2 (src_lib_path , dest_dir_python_lib )
120
128
if platform == 'macos' :
121
- subprocess .run (['strip' , '-x' , dest_dir / lib_filename ], check = True )
129
+ subprocess .run (['strip' , '-x' , dest_dir_python_lib / lib_filename ], check = True )
122
130
else :
123
- subprocess .run (['strip' , '-s' , dest_dir / lib_filename ], check = True )
131
+ subprocess .run (['strip' , '-s' , dest_dir_python_lib / lib_filename ], check = True )
132
+
133
+ for bin_path in config .python_bin_paths :
134
+ src_path : pathlib .Path = src_python / bin_path
135
+
136
+ if src_path .is_file ():
137
+ shutil .copy2 (src_path , dest_dir_python / bin_path )
138
+ elif src_path .is_dir ():
139
+ shutil .copytree (src_path , dest_dir_python / bin_path , dirs_exist_ok = True )
140
+ else :
141
+ raise RuntimeError (f"Cannot find file: { src_path } " )
142
+
143
+ if bin_path == 'bin' :
144
+ # Ignore the bin path in Godot.
145
+ open (dest_dir_python / bin_path / '.gdignore' , 'a' ).close ()
124
146
125
- if (src / config .python_ext_dir ).exists ():
126
- dest_ext_dir = dest_dir / 'python3.12' / 'lib-dynload'
147
+ if (src_python / config .python_ext_dir ).exists ():
148
+ dest_ext_dir = dest_dir_python_lib / 'python3.12' / 'lib-dynload'
127
149
dest_ext_dir .mkdir (parents = True , exist_ok = True )
128
150
129
- for path in (src / config .python_ext_dir ).iterdir ():
151
+ for path in (src_python / config .python_ext_dir ).iterdir ():
130
152
if any (suffix in path .suffixes for suffix in config .ext_suffixes ):
131
153
shutil .copy2 (path , dest_ext_dir )
132
154
133
- shutil .make_archive (dest_dir / 'python312' , 'zip' , root_dir = src / config .python_lib_dir , base_dir = '' )
155
+ shutil .make_archive (dest_dir / 'python312' , 'zip' , root_dir = src_python / config .python_lib_dir , base_dir = '' )
134
156
135
157
136
158
def get_python_for_platform (platform : str , arch : str , src_dir : pathlib .Path ) -> pathlib .Path :
0 commit comments