Skip to content

Commit 6d71cec

Browse files
author
Christopher Doris
committed
install dmg
1 parent 5f2bac5 commit 6d71cec

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

juliacall/install.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import os
66
import platform
77
import shutil
8+
import subprocess
89
import tarfile
910
import time
1011
import urllib.request
@@ -176,4 +177,22 @@ def install_julia_tar_gz(f, buf, prefix):
176177
os.rmdir(os.path.join(prefix, top))
177178

178179
def install_julia_dmg(f, buf, prefix):
179-
raise NotImplementedError('cannot yet install Julia from DMG')
180+
tmpdir = prefix + '.tmp'
181+
os.makedirs(tmpdir)
182+
# write the dmg file out
183+
dmg = os.path.join(tmpdir, 'dmg')
184+
with open(dmg, 'wb') as f:
185+
f.write(buf.read())
186+
# mount it
187+
mount = os.path.join(tmpdir, 'mount')
188+
subprocess.run(['hdiutil', 'mount', '-mount', 'required', '-mountpoint', mount, dmg], check=True, capture_output=True)
189+
# copy stuff out
190+
appdirs = [d for d in os.listdir(mount) if d.startswith('Julia') and d.endswith('.app')]
191+
if len(appdirs) != 1:
192+
raise Exception('expecting one Julia*.app directory')
193+
srcdir = os.path.join(mount, appdirs[0], 'Contents', 'Resources', 'julia')
194+
shutil.copytree(srcdir, prefix, symlinks=True)
195+
# unmount
196+
subprocess.run(['umount', mount], check=True, capture_output=True)
197+
# delete tmpdir
198+
shutil.rmtree(tmpdir)

0 commit comments

Comments
 (0)