tree-sitter / tree-sitter-python

Python grammar for tree-sitter
MIT License
372 stars 138 forks source link

feature: pre-compiled binary wheels for M chip macOS (arm64) #262

Closed Co1lin closed 2 months ago

Co1lin commented 7 months ago

Did you check the tree-sitter docs?

Is your feature request related to a problem? Please describe.

https://github.com/tree-sitter/py-tree-sitter says "Build from source" will be deprecated and in v0.22.0. However, on arm mac, running pip install tree-sitter-python reports "No matching distribution found for tree-sitter-python". I think there is no pre-built wheels for M chip mac.

Describe the solution you'd like

Release the binary for the M chip mac.

Describe alternatives you've considered

/

Additional context

No response

ObserverOfTime commented 6 months ago

Building from source via tree-sitter is deprecated but you can still build from source via pip.

pip install git+https://github.com/tree-sitter/tree-sitter-python

A macOS arm64 wheel will be available in the next release. Maybe a source distribution as well.

Gby56 commented 5 months ago

Hello, just checking, could it be possible to get an sdist otherwise ? I assume that would make arm-based fallback to source and build locally ? That's what I've been doing in my pyproject.toml

tree-sitter-python = [
    {platform = "darwin", git="https://github.com/tree-sitter/tree-sitter-python", tag="v0.21.0"},
    {platform = "linux", version="0.21.0"}
]
kiyoon commented 5 months ago
pip install git+https://github.com/tree-sitter/tree-sitter-python

I tried this and still can't install it. How do I resolve this?

  File "/Users/kiyoon/.config/dotfiles/nvim/find_python_import_in_project.py", line 6, in <module>
    import tree_sitter_python as tspython
  File "/Users/kiyoon/bin/miniforge3/envs/PPMI/lib/python3.11/site-packages/tree_sitter_python/__init__.py", line 3, in <module>
    from ._binding import language
ImportError: dlopen(/Users/kiyoon/bin/miniforge3/envs/PPMI/lib/python3.11/site-packages/tree_sitter_python/_binding.abi3.so, 0x0002): tried: '/Users/kiyoon/bin/miniforge3/envs/PPMI/lib/python3.11/site-packages/tree_sitter_python/_binding.abi3.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e' or 'arm64')), '/System/Volumes/Preboot/Cryptexes/OS/Users/kiyoon/bin/miniforge3/envs/PPMI/lib/python3.11/site-packages/tree_sitter_python/_binding.abi3.so' (no such file), '/Users/kiyoon/bin/miniforge3/envs/PPMI/lib/python3.11/site-packages/tree_sitter_python/_binding.abi3.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e' or 'arm64'))
tusharsadhwani commented 5 months ago

@kiyoon for intel mac you should be able to pip install tree-sitter normally. Does that not work?

kiyoon commented 5 months ago

@tusharsadhwani Mine is M1, and it seems like the shared object that is being installed is for intel. pip install tree-sitter-python didn't work for me.

🕙 21:02:13 ❯ pip install tree-sitter-python
ERROR: Could not find a version that satisfies the requirement tree-sitter-python (from versions: none)
ERROR: No matching distribution found for tree-sitter-python

🕙 21:02:15 ✖  uv pip install tree-sitter-python
  × No solution found when resolving dependencies:
  ╰─▶ Because only tree-sitter-python==0.21.0 is available and tree-sitter-python==0.21.0 has no wheels are available with a matching platform, we can conclude that all versions of tree-sitter-python cannot be used.
      And because you require tree-sitter-python, we can conclude that the requirements are unsatisfiable.
ObserverOfTime commented 5 months ago

I tried this and still can't install it. How do I resolve this?

Something is using the wrong architecture. Could be python, pip, conda, or your compiler.

kiyoon commented 5 months ago

I think it's my compiler because I had similar problem with rust. But I don't know how to fix it..

kiyoon commented 5 months ago

I temporarily forked the repo and modified the CI to publish the wheel files on the Release page. I don't know what's wrong with my compiler, but this worked for me.

https://github.com/kiyoon/tree-sitter-python/releases

ObserverOfTime commented 2 months ago

The wheel is included in 0.23.0

perseoGI commented 2 months ago

After having successfully installed 0.23.0 in a M chip MacOS, I'm getting this error:

import tree_sitter_python as tspython
from tree_sitter import Language, Parser, Point, Tree

PY_LANGUAGE = Language(tspython.language())

Error:

PY_LANGUAGE = Language(tspython.language())
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: an integer is required

ERROR: an integer is required

Any clue why is this happening? With a previous installation of this dependency using git protocol I didn't get this error:

tree-sitter-python @ git+https://github.com/tree-sitter/tree-sitter-python@71778c2a472ed00a64abf4219544edbf8e4b86d7
ericwb commented 2 months ago

@perseoGI #280 was opened on that issue. For some reason the issue is closed even though it has not been resolved yet.

perseoGI commented 2 months ago

@perseoGI #280 was opened on that issue. For some reason the issue is closed even though it has not been resolved yet.

Did you find a good approach to use python-tree-sitter with python grammar which does not involve using git protocol?

ericwb commented 2 months ago

Unfortunately, no. I'm still waiting for all these bugs to get straightened out.

ObserverOfTime commented 2 months ago

You need tree-sitter==0.23.0

jiezhuzzz commented 2 months ago

@ObserverOfTime The bug persists in version 0.23.

perseoGI commented 2 months ago

It finally works in my setup using this tree-sitter related requirements:

lsp-tree-sitter==0.0.15
tree-sitter==0.23.0
tree-sitter-python==0.23.0

I had to adjust some query.matches results due to some breaking change were introduced on the API in the latest tree-sitter relese. Thank you!