Skip to content

Commit 89e1265

Browse files
committed
macOS: Reduce .dmg size from 237 MB -> 50.7 MB
References #124
2 parents fb3e21d + 9141946 commit 89e1265

File tree

3 files changed

+35
-9
lines changed

3 files changed

+35
-9
lines changed

setup/make-mac.sh

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,26 @@
33
VERSION=`python -c 'import sys; sys.path.append("../src"); import crystal; print(crystal.__version__)'`
44

55
rm -rf build dist dist-mac
6-
poetry run python setup.py py2app
6+
7+
# Build .app
8+
if [ "$1" != "--app-only" ]; then
9+
GRAPH_OPT=""
10+
else
11+
# --graph: Generates a GraphViz .dot file in the build directory that shows
12+
# the calculated module dependency graph
13+
GRAPH_OPT="--graph"
14+
fi
15+
poetry run python setup.py py2app $GRAPH_OPT
16+
17+
# Slim .app
18+
zip "dist/Crystal Web Archiver.app/Contents/Resources/lib/python39.zip" \
19+
-d "wx/locale/*"
20+
21+
# Build .dmg
722
mkdir dist-mac
823
if [ "$1" != "--app-only" ]; then
924
echo 'Building disk image... (skip with --app-only option)'
10-
hdiutil create -srcfolder dist -volname "Crystal Web Archiver" -format UDZO dist-mac/crystal-mac-$VERSION.dmg
25+
# -format UDBZ: Use bzip2 compression, which produces smaller images
26+
# than zlib compression (UDZO), even with zlib-level=9
27+
hdiutil create -srcfolder dist -volname "Crystal Web Archiver" -format UDBZ dist-mac/crystal-mac-$VERSION.dmg
1128
fi

setup/setup.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@
6464
'argv_emulation': False,
6565
'iconfile': 'media/AppIconMac.icns',
6666
'plist': PLIST,
67+
'excludes': [
68+
'numpy',
69+
'test', # CPython test data
70+
'PIL',
71+
]
6772
}},
6873
)
6974
elif sys.platform == 'win32':
Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from contextlib import contextmanager
22
import os
3-
import pyscreeze
43
import sys
54
from typing import Iterator
65

@@ -13,11 +12,16 @@ def screenshot_if_raises() -> Iterator[None]:
1312
# Take screenshot if screenshots directory path defined
1413
screenshots_dirpath = os.environ.get('CRYSTAL_SCREENSHOTS_DIRPATH')
1514
if screenshots_dirpath is not None:
16-
os.makedirs(screenshots_dirpath, exist_ok=True)
17-
18-
screenshot_filename = os.environ.get('CRYSTAL_SCREENSHOT_ID', 'screenshot') + '.png'
19-
screenshot_filepath = os.path.join(screenshots_dirpath, screenshot_filename)
20-
print('*** Saving screenshot to: ' + os.path.abspath(screenshot_filepath), file=sys.stderr)
21-
pyscreeze.screenshot(screenshot_filepath)
15+
try:
16+
import pyscreeze
17+
except ImportError: # probably PIL missing
18+
print('*** Unable to save screenshot because pyscreeze not available. Probably PIL is missing.', file=sys.stderr)
19+
else:
20+
os.makedirs(screenshots_dirpath, exist_ok=True)
21+
22+
screenshot_filename = os.environ.get('CRYSTAL_SCREENSHOT_ID', 'screenshot') + '.png'
23+
screenshot_filepath = os.path.join(screenshots_dirpath, screenshot_filename)
24+
print('*** Saving screenshot to: ' + os.path.abspath(screenshot_filepath), file=sys.stderr)
25+
pyscreeze.screenshot(screenshot_filepath)
2226

2327
raise

0 commit comments

Comments
 (0)