pyloid 0.20.1.dev1__py3-none-any.whl → 0.20.2__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,247 @@
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
- )
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
247
  """