From a59cdcf29a404b22ee08a611bb0599db3d589957 Mon Sep 17 00:00:00 2001 From: David Foster Date: Mon, 4 Sep 2023 22:00:43 -0400 Subject: [PATCH 1/8] make-mac: Output the module dependency graph during the build process --- setup/make-mac.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/setup/make-mac.sh b/setup/make-mac.sh index 63d1ca35..7f945ffe 100755 --- a/setup/make-mac.sh +++ b/setup/make-mac.sh @@ -3,7 +3,9 @@ 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 +# --graph: Generates a GraphViz .dot file in the build directory that shows +# the calculated module dependency graph +poetry run python setup.py py2app --graph mkdir dist-mac if [ "$1" != "--app-only" ]; then echo 'Building disk image... (skip with --app-only option)' From f1b4b911394ddc37bf7d98ef8dc7613f76b053a4 Mon Sep 17 00:00:00 2001 From: David Foster Date: Mon, 4 Sep 2023 22:20:14 -0400 Subject: [PATCH 2/8] macOS: Reduce .app size by removing numpy from output Reduces .app size from 237 MB -> 136 MB! --- setup/setup.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/setup/setup.py b/setup/setup.py index b8efae32..d0875823 100644 --- a/setup/setup.py +++ b/setup/setup.py @@ -64,6 +64,9 @@ 'argv_emulation': False, 'iconfile': 'media/AppIconMac.icns', 'plist': PLIST, + 'excludes': [ + 'numpy', + ] }}, ) elif sys.platform == 'win32': From 937dbeee1d21b7cf636d03c55db50040c1ab83bb Mon Sep 17 00:00:00 2001 From: David Foster Date: Tue, 5 Sep 2023 07:53:59 -0400 Subject: [PATCH 3/8] macOS: Reduce .dmg size by increasing zlip compression level from 1 to 6 70 MB -> 65.8 MB --- setup/make-mac.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/setup/make-mac.sh b/setup/make-mac.sh index 7f945ffe..2236cfe2 100755 --- a/setup/make-mac.sh +++ b/setup/make-mac.sh @@ -9,5 +9,6 @@ poetry run python setup.py py2app --graph 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 + # zlib-level=6: Increase compression level from default (1) + hdiutil create -srcfolder dist -volname "Crystal Web Archiver" -format UDZO -imagekey zlib-level=6 dist-mac/crystal-mac-$VERSION.dmg fi From 27200134ac2b3e2f0e04ee0937965a6108ffc8da Mon Sep 17 00:00:00 2001 From: David Foster Date: Tue, 5 Sep 2023 07:59:33 -0400 Subject: [PATCH 4/8] macOS: Reduce .dmg size by changing compression from zlib to bzip2 65.8 MB -> 63.6 MB --- setup/make-mac.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/setup/make-mac.sh b/setup/make-mac.sh index 2236cfe2..472de877 100755 --- a/setup/make-mac.sh +++ b/setup/make-mac.sh @@ -9,6 +9,7 @@ poetry run python setup.py py2app --graph mkdir dist-mac if [ "$1" != "--app-only" ]; then echo 'Building disk image... (skip with --app-only option)' - # zlib-level=6: Increase compression level from default (1) - hdiutil create -srcfolder dist -volname "Crystal Web Archiver" -format UDZO -imagekey zlib-level=6 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 From 1640b4df0e9be17f64b85c1b07f6a3c37d3c7a13 Mon Sep 17 00:00:00 2001 From: David Foster Date: Tue, 5 Sep 2023 08:05:56 -0400 Subject: [PATCH 5/8] macOS: Reduce .dmg size by excluding "test" module from CPython 63.6 MB -> 61.1 MB --- setup/setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup/setup.py b/setup/setup.py index d0875823..71c27e89 100644 --- a/setup/setup.py +++ b/setup/setup.py @@ -66,6 +66,7 @@ 'plist': PLIST, 'excludes': [ 'numpy', + 'test', # CPython test data ] }}, ) From 6667bb0bf4d0f90ae9c906040620d27b146a759d Mon Sep 17 00:00:00 2001 From: David Foster Date: Tue, 5 Sep 2023 08:23:34 -0400 Subject: [PATCH 6/8] macOS: Reduce .dmg size by excluding "locale" data from wxPython 61.1 MB -> 59.1 MB --- setup/make-mac.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/setup/make-mac.sh b/setup/make-mac.sh index 472de877..3db21fc3 100755 --- a/setup/make-mac.sh +++ b/setup/make-mac.sh @@ -3,9 +3,17 @@ VERSION=`python -c 'import sys; sys.path.append("../src"); import crystal; print(crystal.__version__)'` rm -rf build dist dist-mac + +# Build .app # --graph: Generates a GraphViz .dot file in the build directory that shows # the calculated module dependency graph poetry run python setup.py py2app --graph + +# 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)' From 0dc72392f4fdba16b02b5a88ece7e057143ae6cd Mon Sep 17 00:00:00 2001 From: David Foster Date: Tue, 5 Sep 2023 08:28:30 -0400 Subject: [PATCH 7/8] macOS: Reduce .dmg size by excluding "PIL" 59.1 MB -> 50.7 MB --- setup/setup.py | 1 + src/crystal/tests/util/screenshots.py | 18 +++++++++++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/setup/setup.py b/setup/setup.py index 71c27e89..47a59dd8 100644 --- a/setup/setup.py +++ b/setup/setup.py @@ -67,6 +67,7 @@ 'excludes': [ 'numpy', 'test', # CPython test data + 'PIL', ] }}, ) diff --git a/src/crystal/tests/util/screenshots.py b/src/crystal/tests/util/screenshots.py index 377d64dc..3306aa27 100644 --- a/src/crystal/tests/util/screenshots.py +++ b/src/crystal/tests/util/screenshots.py @@ -1,6 +1,5 @@ from contextlib import contextmanager import os -import pyscreeze import sys from typing import Iterator @@ -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 \ No newline at end of file From 9141946bca1ad6972dac012ea3e53e766e32ba71 Mon Sep 17 00:00:00 2001 From: David Foster Date: Tue, 5 Sep 2023 08:49:34 -0400 Subject: [PATCH 8/8] make-mac: Don't output module dependency graph if building .dmg --- setup/make-mac.sh | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/setup/make-mac.sh b/setup/make-mac.sh index 3db21fc3..44dbe7f6 100755 --- a/setup/make-mac.sh +++ b/setup/make-mac.sh @@ -5,9 +5,14 @@ VERSION=`python -c 'import sys; sys.path.append("../src"); import crystal; print rm -rf build dist dist-mac # Build .app -# --graph: Generates a GraphViz .dot file in the build directory that shows -# the calculated module dependency graph -poetry run python setup.py py2app --graph +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" \