3 ms·
Something I find really interesting about this is the way the tool is packaged. You can install the CLI utility in four different ways: https://ast-grep.github
by simonw 3y ago
Something I find really interesting about this is the way the tool is packaged.
You can install the CLI utility in four different ways: https://ast-grep.github.io/guide/quick-start.html#installation https://ast-grep.github.io/guide/quick-start.html#installati...
# via Homebrew
brew install ast-grep
# via Cargo
cargo install ast-grep
# via npm
npm i @ast-grep/cli -g
# via pip
pip install ast-grep-cli
# I tested and pipx works too:
pipx install ast-grep-cli
I really like this - it means the tool is available to people with familiarity of any of those four distribution mechanisms.
You can also download pre-built binaries from their releases page: https://github.com/ast-grep/ast-grep/releases/tag/0.14.2 https://github.com/ast-grep/ast-grep/releases/tag/0.14.2
On top of that, they offer API bindings for it in three different languages:
- Rust (not yet stable): https://docs.rs/ast-grep-core/latest/ast_grep_core/ https://docs.rs/ast-grep-core/latest/ast_grep_core/
- JavaScript/TypeScript: https://ast-grep.github.io/guide/api-usage/js-api.html https://ast-grep.github.io/guide/api-usage/js-api.html
- Python: https://ast-grep.github.io/guide/api-usage/py-api.html https://ast-grep.github.io/guide/api-usage/py-api.html
It's rare to see a tool/library offer this depth of language support out of the box.
- simonw 3y agoI was curious so I had a look at how the "pip install ast-grep-cli" command works. It downloads a wheel for the correct platform from https://pypi.org/project/ast-grep-cli/#files https://pypi.org/project/ast-grep-cli/#files The wheel just contains the two binaries (sg and ast-grep) and no Python code: $ unzip -l ast_grep_cli-0.14.2-py3-none-macosx_10_7_x86_64.whl Archive: ast_grep_cli-0.14.2-py3-none-macosx_10_7_x86_64.whl Length Date Time Name --------- ---------- ----- ---- 6207 12-03-2023 07:34 ast_grep_cli-0.14.2.dist-info/METADATA 102 12-03-2023 07:34 ast_grep_cli-0.14.2.dist-info/WHEEL 1077 12-03-2023 07:34 ast_grep_cli-0.14.2.dist-info/license_files/LICENSE 1077 12-03-2023 07:34 ast_grep_cli-0.14.2.dist-info/license_files/LICENSE 32865880 12-03-2023 07:34 ast_grep_cli-0.14.2.data/scripts/sg 32865880 12-03-2023 07:34 ast_grep_cli-0.14.2.data/scripts/ast-grep 639 12-03-2023 07:34 ast_grep_cli-0.14.2.dist-info/RECORD --------- ------- 65740862 7 files I haven't seen pip and wheels used to distribute a purely binary tool like this before.
- charliermarsh 3y agoThis is how Ruff works too! (Ruff is also a standalone binary with no Python dependency.) If you're interested, I recommend checking out Maturin, which makes this pretty easy -- you can ship any standalone Rust binary as a Python package by zipping it into a wheel.
- herrington_d 3y agoI confess I stole the pip recipe from Charlie :D https://github.com/astral-sh/ruff/blob/main/.github/workflows/release.yaml https://github.com/astral-sh/ruff/blob/main/.github/workflow...