Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrading to Python 3.12 and building a universal app (Intel + Apple Silicon) #560

Merged
merged 27 commits into from
Feb 14, 2024

Conversation

justvanrossum
Copy link
Collaborator

No description provided.

@justvanrossum
Copy link
Collaborator Author

The build works on both Intel and Apple Silicon: https://github.com/typemytype/drawbot/actions/runs/7681596610

import sys, platform
print(sys.version)
print(platform.platform())

Intel:

3.12.1 (v3.12.1:2305ca5144, Dec  7 2023, 17:23:39) [Clang 13.0.0 (clang-1300.0.29.30)]
macOS-14.2.1-x86_64-i386-64bit

Apple Silicon:

3.12.1 (v3.12.1:2305ca5144, Dec  7 2023, 17:23:38) [Clang 13.0.0 (clang-1300.0.29.30)]
macOS-14.2.1-arm64-arm-64bit

@justvanrossum
Copy link
Collaborator Author

gif and mp4 export work, but the embedded tools are still Intel. We should track down Universal builds for ffmpeg, gifsicle, potrace, etc.

@justvanrossum
Copy link
Collaborator Author

If it wasn't for PIL, DrawBot would still run on macOS 10.10...

3.12.1 (v3.12.1:2305ca5144, Dec  7 2023, 17:23:39) [Clang 13.0.0 (clang-1300.0.29.30)]
macOS-10.10.5-x86_64-i386-64bit

I'm trying to find out what it is lowest macOS that current PIL/Pillow is expected to run on: python-pillow/Pillow#6862 (comment)

@justvanrossum justvanrossum changed the title First attempt at upgrading to Python 3.12 and building a universal app (Intel + Apple Silicon) Upgrading to Python 3.12 and building a universal app (Intel + Apple Silicon) Jan 28, 2024
@justvanrossum
Copy link
Collaborator Author

justvanrossum commented Jan 28, 2024

With Pillow 10.1.0, DrawBot actually works on macOS 10.10:
image

@justvanrossum
Copy link
Collaborator Author

Hm, this seems an official source for ffmpeg, and they don't seem to intend to provide Apple Silicon binaries: https://evermeet.cx/ffmpeg/apple-silicon-arm

Tangentially, I found this blog post that shows how to speed up h264 encoding on Apple Silicon: https://www.learnwithjason.dev/blog/hardware-acceleration-ffmpeg-apple-silicon/

@typemytype
Copy link
Owner

super mega cool!!

that statement related to ffmpeg seems not sustainable in the long run... there will be no intel mac in a few years...

a quick test leads to this error, it will not be the only one I guess:

from fontTools import bezierTools
Traceback (most recent call last):
  File "<untitled>", line 1, in <module>
ImportError: cannot import name 'bezierTools' from 'fontTools' (/private/var/folders/qy/sv345q756dg_jsx6jg2tf6240000gn/T/AppTranslocation/874D5ABD-17F6-463E-9CCB-6A63FAA449DB/d/DrawBot.app/Contents/Resources/lib/python3.12/fontTools/__init__.py)

this happens cause pip checks the arch, you force the arch somewhere, if I remember it correctly

@justvanrossum
Copy link
Collaborator Author

justvanrossum commented Jan 29, 2024

a quick test leads to this error

Argh yes, it is because if x84 and universal2 wheels are available, it picks x84 :(

We may have to work around it with a script downloading wheels from pypi directly.

@justvanrossum
Copy link
Collaborator Author

that statement related to ffmpeg seems not sustainable in the long run

Interesting (and sad) to see that providing binaries for this hugely successful tool seems to depend on one guy...

@justvanrossum
Copy link
Collaborator Author

justvanrossum commented Jan 29, 2024

I think this may be a possible approach:

  • run pip install -r requirements.txt and capture the output
  • find and parse all wheel filenames ([^\s]+.whl.metadata + packaging.utils.parse_wheel_filename())
  • any wheel that is x86 or arm64 needs attention (we ignore "any" and "universal2"):
    • check the pypi json for the package + version
    • if there is a universal2 wheel, download it, write to location_for_special_universal_wheels/*.whl
    • else if there are x86 and arm64 wheels, download both and merge (delocate.fuse.fuse_wheels()), write to location_for_special_universal_wheels/*.whl
    • else: error
  • pip install --force location_for_special_universal_wheels/*.whl

@justvanrossum
Copy link
Collaborator Author

I think this may be a possible approach

I did that and it seems to work correctly on M123 and Intel, down to macOS 10.10:

@justvanrossum
Copy link
Collaborator Author

@typemytype, this is ready for review/merge.

@justvanrossum justvanrossum merged commit bf2f0f5 into master Feb 14, 2024
1 check passed
@justvanrossum justvanrossum deleted the py312-universal branch February 14, 2024 13:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants