Skip to content

Commit 2def112

Browse files
authored
fix(dmg-builder): Support python 3 since python 2 was removed from MacOS 12.3 (#6617)
* Adding python 3 support to dmg-builder in order to support mac os 12.3+ which has entirely removed python2 (fixes: #6606)
1 parent b01d522 commit 2def112

File tree

4 files changed

+23
-7
lines changed

4 files changed

+23
-7
lines changed

.changeset/thick-bikes-sleep.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"dmg-builder": patch
3+
---
4+
5+
fix(dmg-builder): Adding python 3 support to dmg-builder in order to support mac os 12 which has entirely removed python2. Fixes: #6606

packages/dmg-builder/src/dmg.ts

+11-5
Original file line numberDiff line numberDiff line change
@@ -297,11 +297,17 @@ async function customizeDmg(volumePath: string, specification: DmgOptions, packa
297297
const asyncTaskManager = new AsyncTaskManager(packager.info.cancellationToken)
298298
env.iconLocations = await computeDmgEntries(specification, volumePath, packager, asyncTaskManager)
299299
await asyncTaskManager.awaitTasks()
300-
301-
await exec(process.env.PYTHON_PATH || "/usr/bin/python", [path.join(getDmgVendorPath(), "dmgbuild/core.py")], {
302-
cwd: getDmgVendorPath(),
303-
env,
304-
})
300+
const executePython = async (execName: string) => {
301+
await exec(process.env.PYTHON_PATH || `/usr/bin/${execName}`, [path.join(getDmgVendorPath(), "dmgbuild/core.py")], {
302+
cwd: getDmgVendorPath(),
303+
env,
304+
})
305+
}
306+
try {
307+
await executePython("python3")
308+
} catch (error) {
309+
await executePython("python")
310+
}
305311
return packager.packagerOptions.effectiveOptionComputed == null || !(await packager.packagerOptions.effectiveOptionComputed({ volumePath, specification, packager }))
306312
}
307313

packages/dmg-builder/vendor/dmgbuild/core.py

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
import os
55
import re
66
import sys
7+
if sys.version_info.major == 3:
8+
try:
9+
from importlib import reload
10+
except ImportError:
11+
from imp import reload
712
reload(sys) # Reload is a hack
813
sys.setdefaultencoding('UTF8')
914

test/snapshots/BuildTest.js.snap

+2-2
Original file line numberDiff line numberDiff line change
@@ -1505,7 +1505,7 @@ Object {
15051505
"size": 748,
15061506
},
15071507
"index.js": Object {
1508-
"size": 5664,
1508+
"size": 5708,
15091509
},
15101510
"package.json": Object {
15111511
"size": 567,
@@ -1534,7 +1534,7 @@ Object {
15341534
"size": 1081,
15351535
},
15361536
"index.js": Object {
1537-
"size": 3539,
1537+
"size": 3973,
15381538
},
15391539
"package.json": Object {
15401540
"size": 789,

0 commit comments

Comments
 (0)