jaxtyping + LSP.
shapels provides shape inference for torch tensors inside your editor.
But what does that mean? In the example above, shapels tracks the tensor dimensions and is able to report the wrong matrix multiplication that would have caused a runtime error.
Not only that: when hovering over a tensor, it reports the shape of that tensor through static analysis, even if no annotation was provided. It's effectively replacing
print(f"x -> {x.shape}")but before running any code, in your editor of choice.
If you are not using VSCode, go to the latest release page, download the binary for your platform, unzip it and put it in your path.
shapels's VScode extension comes with the binaries prebundled so this step is not needed.
The first step is to install Rust:
# Unix-like OS
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | shAfter cloning this repository, it can be installed with cargo:
git clone https://github.com/carrascomj/shapels.git
cd shapels
cargo install --path .Just install it from the extensions marketplace, it comes with the shapels binary
prebundled for your platform.
But why don't you try neovim?
Add it to your config (you must have shapels in you path):
vim.lsp.config('shapels', {cmd={'shapels'}, root_markers={'pyproject.toml', 'setup.py', 'setup.cfg'}, filetypes={'python'}})
vim.lsp.enable('shapels')But why don't you try helix?
Add it to your languages.toml (you must have shapels in you path):
[language-server]
shapels = {command = "shapels"}
[[language]]
name = "python"
scope = "source.python"
injection-regex = "py(thon)?"
file-types = ["py", "pyi", "py3", "pyw", "ptl", "rpy", "cpy", "ipy", "pyt", { glob = ".python_history" }, { glob = ".pythonstartup" }, { glob = ".pythonrc" }, { glob = "*SConstruct" }, { glob = "*SConscript" }, { glob = "*sconstruct" }]
shebangs = ["python", "uv"]
roots = ["pyproject.toml", "setup.py", "poetry.lock", "pyrightconfig.json"]
comment-token = "#"
# WARN: probably you have other LS already here, just add shapels to the list
language-servers = ["shapels"]
indent = { tab-width = 4, unit = " " } But why don't you try Emacs?
It's a language server: it takes input from stdin and sends output to stdout; you probably know how to handle that.
Licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
