Skip to content

Commit

Permalink
macOS: Reduce .dmg size from 237 MB -> 50.7 MB
Browse files Browse the repository at this point in the history
References #124
  • Loading branch information
davidfstr committed Sep 5, 2023
2 parents fb3e21d + 9141946 commit 89e1265
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 9 deletions.
21 changes: 19 additions & 2 deletions setup/make-mac.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,26 @@
VERSION=`python -c 'import sys; sys.path.append("../src"); import crystal; print(crystal.__version__)'`

rm -rf build dist dist-mac
poetry run python setup.py py2app

# Build .app
if [ "$1" != "--app-only" ]; then
GRAPH_OPT=""
else
# --graph: Generates a GraphViz .dot file in the build directory that shows
# the calculated module dependency graph
GRAPH_OPT="--graph"
fi
poetry run python setup.py py2app $GRAPH_OPT

# Slim .app
zip "dist/Crystal Web Archiver.app/Contents/Resources/lib/python39.zip" \
-d "wx/locale/*"

# Build .dmg
mkdir dist-mac
if [ "$1" != "--app-only" ]; then
echo 'Building disk image... (skip with --app-only option)'
hdiutil create -srcfolder dist -volname "Crystal Web Archiver" -format UDZO dist-mac/crystal-mac-$VERSION.dmg
# -format UDBZ: Use bzip2 compression, which produces smaller images
# than zlib compression (UDZO), even with zlib-level=9
hdiutil create -srcfolder dist -volname "Crystal Web Archiver" -format UDBZ dist-mac/crystal-mac-$VERSION.dmg
fi
5 changes: 5 additions & 0 deletions setup/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@
'argv_emulation': False,
'iconfile': 'media/AppIconMac.icns',
'plist': PLIST,
'excludes': [
'numpy',
'test', # CPython test data
'PIL',
]
}},
)
elif sys.platform == 'win32':
Expand Down
18 changes: 11 additions & 7 deletions src/crystal/tests/util/screenshots.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from contextlib import contextmanager
import os
import pyscreeze
import sys
from typing import Iterator

Expand All @@ -13,11 +12,16 @@ def screenshot_if_raises() -> Iterator[None]:
# Take screenshot if screenshots directory path defined
screenshots_dirpath = os.environ.get('CRYSTAL_SCREENSHOTS_DIRPATH')
if screenshots_dirpath is not None:
os.makedirs(screenshots_dirpath, exist_ok=True)

screenshot_filename = os.environ.get('CRYSTAL_SCREENSHOT_ID', 'screenshot') + '.png'
screenshot_filepath = os.path.join(screenshots_dirpath, screenshot_filename)
print('*** Saving screenshot to: ' + os.path.abspath(screenshot_filepath), file=sys.stderr)
pyscreeze.screenshot(screenshot_filepath)
try:
import pyscreeze
except ImportError: # probably PIL missing
print('*** Unable to save screenshot because pyscreeze not available. Probably PIL is missing.', file=sys.stderr)
else:
os.makedirs(screenshots_dirpath, exist_ok=True)

screenshot_filename = os.environ.get('CRYSTAL_SCREENSHOT_ID', 'screenshot') + '.png'
screenshot_filepath = os.path.join(screenshots_dirpath, screenshot_filename)
print('*** Saving screenshot to: ' + os.path.abspath(screenshot_filepath), file=sys.stderr)
pyscreeze.screenshot(screenshot_filepath)

raise

0 comments on commit 89e1265

Please sign in to comment.