vigo / textmate2-python-fmt

Python FMT is a python linter/formatter/checker for TextMate.
MIT License
13 stars 5 forks source link

calling out to a compiled version of black fails on ARM #9

Open tungol opened 6 months ago

tungol commented 6 months ago

By default, pip installs a compiled version of black appropriate for the current architecture. On an ARM Macbook, that ends up with an error message like this:

  File "/Users/stephen/Library/Python/3.12/bin//black", line 5, in <module>
    from black import patched_main
ImportError: dlopen(/Users/stephen/Library/Python/3.12/lib/python/site-packages/black/__init__.cpython-312-darwin.so, 0x0002): tried: '/Users/stephen/Library/Python/3.12/lib/python/site-packages/black/__init__.cpython-312-darwin.so' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64')), '/System/Volumes/Preboot/Cryptexes/OS/Users/stephen/Library/Python/3.12/lib/python/site-packages/black/__init__.cpython-312-darwin.so' (no such file), '/Users/stephen/Library/Python/3.12/lib/python/site-packages/black/__init__.cpython-312-darwin.so' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64'))

The main problem being that we're using the ancient ruby18 bundled with Textmate, which is x86 only. If we allow Python FMT to use system ruby instead, this happens:

/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require': dlopen(/Users/stephen/Library/Application Support/TextMate/Managed/Bundles/Bundle Support.tmbundle/Support/shared/lib/osx/plist.bundle, 0x0009): tried: '/Users/stephen/Library/Application Support/TextMate/Managed/Bundles/Bundle Support.tmbundle/Support/shared/lib/osx/plist.bundle' (fat file, but missing compatible architecture (have 'unknown,i386,x86_64', need 'arm64')), '/System/Volumes/Preboot/Cryptexes/OS/Users/stephen/Library/Application Support/TextMate/Managed/Bundles/Bundle Support.tmbundle/Support/shared/lib/osx/plist.bundle' (no such file), '/Users/stephen/Library/Application Support/TextMate/Managed/Bundles/Bundle Support.tmbundle/Support/shared/lib/osx/plist.bundle' (fat file, but missing compatible architecture (have 'unknown,i386,x86_64', need 'arm64')) - /Users/stephen/Library/Application Support/TextMate/Managed/Bundles/Bundle Support.tmbundle/Support/shared/lib/osx/plist.bundle (LoadError)
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    from /Users/stephen/Library/Application Support/TextMate/Managed/Bundles/Bundle Support.tmbundle/Support/shared/lib/textmate.rb:5:in `<top (required)>'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    from /Users/stephen/Library/Application Support/TextMate/Bundles/Python-FMT.tmbundle/Support/python_helper.rb:4:in `<top (required)>'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    from Document Will Save:3:in `<main>'

The problem here is that the provided Bundle Support.tmbundle/Support/shared/lib/textmate.rb imports Bundle Support.tmbundle/Support/shared/lib/osx/plist.bundle, which is a compiled ruby extension, distributed by Textmate as a binary for x86_64, i386, and ppc_7400 (!).

Possible solutions to this:

vigo commented 3 months ago

hmm. i'm on m2 and m3 macs and never had this issue. i'll investigate.

tungol commented 3 months ago

If you can't replicate the issue let me know and I'll see if I can find more specific conditions

vigo commented 3 months ago

i just faced this problem while working on https://github.com/vigo/textmate2-ruff-linter. none of the textmate's cocoa related dialogs, nibs are competible. also, ruby versions are incompetible with cpu. but still, did not get any python package releated issue. is it possible to record a small video that i see whats going on? i also upgraded this bundle and will do small improvements which i implemented in my ruff linter

tungol commented 2 months ago

I'll try to get that video. If it's been a while and I haven't gotten that to you, that means I probably just forgot and you're welcome to ping me about it.