pyloid 0.20.2__py3-none-any.whl → 0.20.2.dev2__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
pyloid/builder/spec.py CHANGED
@@ -1,247 +1,266 @@
1
- from pyloid.utils import get_platform
2
- import json
3
- from pathlib import Path
4
-
5
- def create_spec_from_json(json_path):
6
- with open(json_path, 'r', encoding='utf-8') as f:
7
- config = json.load(f)
8
-
9
- os_type = get_platform()
10
-
11
- if os_type == 'macos':
12
- spec_content = _create_macos_spec(config)
13
- elif os_type == 'linux':
14
- spec_content = _create_linux_spec(config)
15
- else: # windows
16
- spec_content = _create_windows_spec(config)
17
-
18
- spec_path = Path(f"build-{os_type}.spec")
19
- spec_path.write_text(spec_content, encoding='utf-8')
20
-
21
- return str(spec_path)
22
-
23
- def _create_windows_spec(config):
24
- bundle_type = config.get('bundle', {}).get('windows', 'directory')
25
-
26
- base_spec = f"""# -*- mode: python ; coding: utf-8 -*-
27
-
28
- block_cipher = None
29
-
30
- a = Analysis(
31
- ['{config['main_script']}'],
32
- pathex={config.get('pathex', [])},
33
- binaries={config.get('binaries', [])},
34
- datas={config.get('datas', [])},
35
- hiddenimports={config.get('hiddenimports', [])},
36
- hookspath={config.get('hookspath', [])},
37
- hooksconfig={config.get('hooksconfig', {})},
38
- runtime_hooks={config.get('runtime_hooks', [])},
39
- excludes={config.get('excludes', [])},
40
- win_no_prefer_redirects=False,
41
- win_private_assemblies=False,
42
- cipher=block_cipher,
43
- noarchive=False
44
- )
45
-
46
- pyz = PYZ(a.pure, a.zipped_data,
47
- cipher=block_cipher)
48
- """
49
-
50
- if bundle_type == 'onefile':
51
- return base_spec + f"""
52
- exe = EXE(
53
- pyz,
54
- a.scripts,
55
- a.binaries,
56
- a.zipfiles,
57
- a.datas,
58
- [],
59
- name='{config.get("name", "pyloid-app")}',
60
- debug=False,
61
- bootloader_ignore_signals=False,
62
- strip=False,
63
- upx=True,
64
- upx_exclude=[],
65
- runtime_tmpdir=None,
66
- console=False,
67
- disable_windowed_traceback=False,
68
- argv_emulation=False,
69
- target_arch=None,
70
- codesign_identity=None,
71
- entitlements_file=None,
72
- icon='{config.get('icon', 'src-pyloid/icons/icon.ico')}'
73
- )
74
- """
75
- else:
76
- return base_spec + f"""
77
- exe = EXE(
78
- pyz,
79
- a.scripts,
80
- [],
81
- exclude_binaries=True,
82
- name='{config.get("name", "pyloid-app")}',
83
- debug=False,
84
- bootloader_ignore_signals=False,
85
- strip=False,
86
- upx=True,
87
- console=False,
88
- disable_windowed_traceback=False,
89
- argv_emulation=False,
90
- target_arch=None,
91
- codesign_identity=None,
92
- entitlements_file=None,
93
- icon='{config.get('icon', 'src-pyloid/icons/icon.ico')}'
94
- )
95
-
96
- coll = COLLECT(
97
- exe,
98
- a.binaries,
99
- a.zipfiles,
100
- a.datas,
101
- strip=False,
102
- upx=True,
103
- upx_exclude=[],
104
- name='{config.get("name", "pyloid-app")}'
105
- )
106
- """
107
-
108
- def _create_macos_spec(config):
109
- return f"""# -*- mode: python ; coding: utf-8 -*-
110
-
111
- a = Analysis(
112
- ['{config['main_script']}'],
113
- pathex={config.get('pathex', [])},
114
- binaries={config.get('binaries', [])},
115
- datas={config.get('datas', [])},
116
- hiddenimports={config.get('hiddenimports', [])},
117
- hookspath={config.get('hookspath', [])},
118
- hooksconfig={config.get('hooksconfig', {})},
119
- runtime_hooks={config.get('runtime_hooks', [])},
120
- excludes={config.get('excludes', [])},
121
- noarchive=False,
122
- optimize=0
123
- )
124
-
125
- pyz = PYZ(a.pure)
126
-
127
- exe = EXE(
128
- pyz,
129
- a.scripts,
130
- [],
131
- exclude_binaries=True,
132
- name='{config.get("name", "pyloid-app")}',
133
- debug=False,
134
- bootloader_ignore_signals=False,
135
- strip=False,
136
- upx=True,
137
- console=False,
138
- disable_windowed_traceback=False,
139
- argv_emulation=False,
140
- target_arch=None,
141
- codesign_identity=None,
142
- entitlements_file=None,
143
- icon='{config.get('icon', 'src-pyloid/icons/icon.ico')}'
144
- )
145
-
146
- coll = COLLECT(
147
- exe,
148
- a.binaries,
149
- a.datas,
150
- strip=False,
151
- upx=True,
152
- upx_exclude=[],
153
- name='{config.get("name", "pyloid-app")}'
154
- )
155
-
156
- app = BUNDLE(
157
- coll,
158
- name='{config.get("name", "pyloid-app")}.app',
159
- icon='{config.get('icon', 'src-pyloid/icons/icon.icns')}',
160
- bundle_identifier=None
161
- )
162
- """
163
-
164
- def _create_linux_spec(config):
165
- bundle_type = config.get('bundle', {}).get('linux', 'directory')
166
-
167
- base_spec = f"""# -*- mode: python ; coding: utf-8 -*-
168
-
169
- block_cipher = None
170
-
171
- a = Analysis(
172
- ['{config['main_script']}'],
173
- pathex={config.get('pathex', [])},
174
- binaries={config.get('binaries', [])},
175
- datas={config.get('datas', [])},
176
- hiddenimports={config.get('hiddenimports', [])},
177
- hookspath={config.get('hookspath', [])},
178
- hooksconfig={config.get('hooksconfig', {})},
179
- runtime_hooks={config.get('runtime_hooks', [])},
180
- excludes={config.get('excludes', [])},
181
- win_no_prefer_redirects=False,
182
- win_private_assemblies=False,
183
- cipher=block_cipher,
184
- noarchive=False
185
- )
186
-
187
- pyz = PYZ(a.pure, a.zipped_data,
188
- cipher=block_cipher)
189
- """
190
-
191
- if bundle_type == 'onefile':
192
- return base_spec + f"""
193
- exe = EXE(
194
- pyz,
195
- a.scripts,
196
- a.binaries,
197
- a.zipfiles,
198
- a.datas,
199
- [],
200
- name='{config.get("name", "pyloid-app")}',
201
- debug=False,
202
- bootloader_ignore_signals=False,
203
- strip=False,
204
- upx=True,
205
- upx_exclude=[],
206
- runtime_tmpdir=None,
207
- console=False,
208
- disable_windowed_traceback=False,
209
- argv_emulation=False,
210
- target_arch=None,
211
- codesign_identity=None,
212
- entitlements_file=None,
213
- icon='{config.get('icon', 'src-pyloid/icons/icon.png')}'
214
- )
215
- """
216
- else:
217
- return base_spec + f"""
218
- exe = EXE(
219
- pyz,
220
- a.scripts,
221
- [],
222
- exclude_binaries=True,
223
- name='{config.get("name", "pyloid-app")}',
224
- debug=False,
225
- bootloader_ignore_signals=False,
226
- strip=False,
227
- upx=True,
228
- console=False,
229
- disable_windowed_traceback=False,
230
- argv_emulation=False,
231
- target_arch=None,
232
- codesign_identity=None,
233
- entitlements_file=None,
234
- icon='{config.get('icon', 'src-pyloid/icons/icon.png')}'
235
- )
236
-
237
- coll = COLLECT(
238
- exe,
239
- a.binaries,
240
- a.zipfiles,
241
- a.datas,
242
- strip=False,
243
- upx=True,
244
- upx_exclude=[],
245
- name='{config.get("name", "pyloid-app")}'
246
- )
247
- """
1
+ from pyloid.utils import get_platform
2
+ import json
3
+ from pathlib import Path
4
+
5
+
6
+ def create_spec_from_json(json_path):
7
+ with open(json_path, "r", encoding="utf-8") as f:
8
+ config = json.load(f)
9
+
10
+ os_type = get_platform()
11
+
12
+ if os_type == "macos":
13
+ spec_content = _create_macos_spec(config)
14
+ elif os_type == "linux":
15
+ spec_content = _create_linux_spec(config)
16
+ else: # windows
17
+ spec_content = _create_windows_spec(config)
18
+
19
+ spec_path = Path(f"build-{os_type}.spec")
20
+ spec_path.write_text(spec_content, encoding="utf-8")
21
+
22
+ return str(spec_path)
23
+
24
+
25
+ def _create_windows_spec(config):
26
+ bundle_type = config.get("bundle", {}).get("windows", "directory")
27
+ console = config.get("console", False)
28
+
29
+ base_spec = f"""# -*- mode: python ; coding: utf-8 -*-
30
+
31
+ block_cipher = None
32
+
33
+ a = Analysis(
34
+ ['{config['main_script']}'],
35
+ pathex={config.get('pathex', [])},
36
+ binaries={config.get('binaries', [])},
37
+ datas={config.get('datas', [])},
38
+ hiddenimports={config.get('hiddenimports', [])},
39
+ hookspath={config.get('hookspath', [])},
40
+ hooksconfig={config.get('hooksconfig', {})},
41
+ runtime_hooks={config.get('runtime_hooks', [])},
42
+ excludes={config.get('excludes', [])},
43
+ win_no_prefer_redirects=False,
44
+ win_private_assemblies=False,
45
+ cipher=block_cipher,
46
+ noarchive=False
47
+ )
48
+
49
+ pyz = PYZ(a.pure, a.zipped_data,
50
+ cipher=block_cipher)
51
+ """
52
+
53
+ if bundle_type == "onefile":
54
+ return (
55
+ base_spec
56
+ + f"""
57
+ exe = EXE(
58
+ pyz,
59
+ a.scripts,
60
+ a.binaries,
61
+ a.zipfiles,
62
+ a.datas,
63
+ [],
64
+ name='{config.get("name", "pyloid-app")}',
65
+ debug=False,
66
+ bootloader_ignore_signals=False,
67
+ strip=False,
68
+ upx=True,
69
+ upx_exclude=[],
70
+ runtime_tmpdir=None,
71
+ console={console},
72
+ disable_windowed_traceback=False,
73
+ argv_emulation=False,
74
+ target_arch=None,
75
+ codesign_identity=None,
76
+ entitlements_file=None,
77
+ icon='{config.get('icon', 'src-pyloid/icons/icon.ico')}'
78
+ )
79
+ """
80
+ )
81
+ else:
82
+ return (
83
+ base_spec
84
+ + f"""
85
+ exe = EXE(
86
+ pyz,
87
+ a.scripts,
88
+ [],
89
+ exclude_binaries=True,
90
+ name='{config.get("name", "pyloid-app")}',
91
+ debug=False,
92
+ bootloader_ignore_signals=False,
93
+ strip=False,
94
+ upx=True,
95
+ console={console},
96
+ disable_windowed_traceback=False,
97
+ argv_emulation=False,
98
+ target_arch=None,
99
+ codesign_identity=None,
100
+ entitlements_file=None,
101
+ icon='{config.get('icon', 'src-pyloid/icons/icon.ico')}'
102
+ )
103
+
104
+ coll = COLLECT(
105
+ exe,
106
+ a.binaries,
107
+ a.zipfiles,
108
+ a.datas,
109
+ strip=False,
110
+ upx=True,
111
+ upx_exclude=[],
112
+ name='{config.get("name", "pyloid-app")}'
113
+ )
114
+ """
115
+ )
116
+
117
+
118
+ def _create_macos_spec(config):
119
+ console = config.get("console", False)
120
+ return f"""# -*- mode: python ; coding: utf-8 -*-
121
+
122
+ a = Analysis(
123
+ ['{config['main_script']}'],
124
+ pathex={config.get('pathex', [])},
125
+ binaries={config.get('binaries', [])},
126
+ datas={config.get('datas', [])},
127
+ hiddenimports={config.get('hiddenimports', [])},
128
+ hookspath={config.get('hookspath', [])},
129
+ hooksconfig={config.get('hooksconfig', {})},
130
+ runtime_hooks={config.get('runtime_hooks', [])},
131
+ excludes={config.get('excludes', [])},
132
+ noarchive=False,
133
+ optimize=0
134
+ )
135
+
136
+ pyz = PYZ(a.pure)
137
+
138
+ exe = EXE(
139
+ pyz,
140
+ a.scripts,
141
+ [],
142
+ exclude_binaries=True,
143
+ name='{config.get("name", "pyloid-app")}',
144
+ debug=False,
145
+ bootloader_ignore_signals=False,
146
+ strip=False,
147
+ upx=True,
148
+ console={console},
149
+ disable_windowed_traceback=False,
150
+ argv_emulation=False,
151
+ target_arch=None,
152
+ codesign_identity=None,
153
+ entitlements_file=None,
154
+ icon='{config.get('icon', 'src-pyloid/icons/icon.ico')}'
155
+ )
156
+
157
+ coll = COLLECT(
158
+ exe,
159
+ a.binaries,
160
+ a.datas,
161
+ strip=False,
162
+ upx=True,
163
+ upx_exclude=[],
164
+ name='{config.get("name", "pyloid-app")}'
165
+ )
166
+
167
+ app = BUNDLE(
168
+ coll,
169
+ name='{config.get("name", "pyloid-app")}.app',
170
+ icon='{config.get('icon', 'src-pyloid/icons/icon.icns')}',
171
+ bundle_identifier=None
172
+ )
173
+ """
174
+
175
+
176
+ def _create_linux_spec(config):
177
+ bundle_type = config.get("bundle", {}).get("linux", "directory")
178
+ console = config.get("console", False)
179
+
180
+ base_spec = f"""# -*- mode: python ; coding: utf-8 -*-
181
+
182
+ block_cipher = None
183
+
184
+ a = Analysis(
185
+ ['{config['main_script']}'],
186
+ pathex={config.get('pathex', [])},
187
+ binaries={config.get('binaries', [])},
188
+ datas={config.get('datas', [])},
189
+ hiddenimports={config.get('hiddenimports', [])},
190
+ hookspath={config.get('hookspath', [])},
191
+ hooksconfig={config.get('hooksconfig', {})},
192
+ runtime_hooks={config.get('runtime_hooks', [])},
193
+ excludes={config.get('excludes', [])},
194
+ win_no_prefer_redirects=False,
195
+ win_private_assemblies=False,
196
+ cipher=block_cipher,
197
+ noarchive=False
198
+ )
199
+
200
+ pyz = PYZ(a.pure, a.zipped_data,
201
+ cipher=block_cipher)
202
+ """
203
+
204
+ if bundle_type == "onefile":
205
+ return (
206
+ base_spec
207
+ + f"""
208
+ exe = EXE(
209
+ pyz,
210
+ a.scripts,
211
+ a.binaries,
212
+ a.zipfiles,
213
+ a.datas,
214
+ [],
215
+ name='{config.get("name", "pyloid-app")}',
216
+ debug=False,
217
+ bootloader_ignore_signals=False,
218
+ strip=False,
219
+ upx=True,
220
+ upx_exclude=[],
221
+ runtime_tmpdir=None,
222
+ console={console},
223
+ disable_windowed_traceback=False,
224
+ argv_emulation=False,
225
+ target_arch=None,
226
+ codesign_identity=None,
227
+ entitlements_file=None,
228
+ icon='{config.get('icon', 'src-pyloid/icons/icon.png')}'
229
+ )
230
+ """
231
+ )
232
+ else:
233
+ return (
234
+ base_spec
235
+ + f"""
236
+ exe = EXE(
237
+ pyz,
238
+ a.scripts,
239
+ [],
240
+ exclude_binaries=True,
241
+ name='{config.get("name", "pyloid-app")}',
242
+ debug=False,
243
+ bootloader_ignore_signals=False,
244
+ strip=False,
245
+ upx=True,
246
+ console={console},
247
+ disable_windowed_traceback=False,
248
+ argv_emulation=False,
249
+ target_arch=None,
250
+ codesign_identity=None,
251
+ entitlements_file=None,
252
+ icon='{config.get('icon', 'src-pyloid/icons/icon.png')}'
253
+ )
254
+
255
+ coll = COLLECT(
256
+ exe,
257
+ a.binaries,
258
+ a.zipfiles,
259
+ a.datas,
260
+ strip=False,
261
+ upx=True,
262
+ upx_exclude=[],
263
+ name='{config.get("name", "pyloid-app")}'
264
+ )
265
+ """
266
+ )