libcst-powered Python refactors (qualify imports, split triple-quoted strings) as a CLI and an LSP server.
Project description
parsing
A small CLI of libcst-powered Python source transforms.
Install
uv sync
Or as a tool:
uv tool install .
Commands
qualify
Rewrites from X import a, b into import X and qualifies the resulting references.
parsing qualify path/to/file.py -m os.path=op
parsing qualify path/to/file.py --all --in-place
parsing qualify path/to/file.py --interactive # pick imports via fzf
| Flag | Description |
|---|---|
-m, --module name[=alias] |
Module to qualify; repeatable. |
-a, --all |
Collapse every from X import a, b, ... with 2+ names. |
-i, --in-place |
Write changes back to the file. |
-I, --interactive |
Pick imports via fzf, then prompt for a nickname per selection. |
split-strings
Splits standalone single-line triple-quoted string statements (docstrings, block-comment-style strings) onto multiple lines. Only standalone string-expression statements are rewritten — x = """foo""" is left alone, since splitting it would change the string value.
parsing split-strings path/to/file.py --in-place
| Flag | Description |
|---|---|
-i, --in-place |
Write changes back to the file. |
Neovim integration
Drop the snippet below into your Neovim config (e.g. ~/.config/nvim/lua/parsing.lua, then require("parsing") from init.lua). It binds <leader>p to run parsing qualify -Ii on the current buffer inside a floating terminal so fzf and the nickname prompts work normally. The buffer is reloaded from disk when the command exits.
local M = {}
function M.run()
local file = vim.api.nvim_buf_get_name(0)
if file == "" or vim.bo.buftype ~= "" then
vim.notify("parsing: current buffer is not a file", vim.log.levels.WARN)
return
end
vim.cmd("silent! write")
local ui = vim.api.nvim_list_uis()[1]
local width = math.floor(ui.width * 0.8)
local height = math.floor(ui.height * 0.8)
local buf = vim.api.nvim_create_buf(false, true)
local win = vim.api.nvim_open_win(buf, true, {
relative = "editor",
width = width,
height = height,
col = math.floor((ui.width - width) / 2),
row = math.floor((ui.height - height) / 2),
style = "minimal",
border = "rounded",
title = " parsing qualify -Ii ",
title_pos = "center",
})
vim.fn.jobstart({ "parsing", "qualify", "-Ii", file }, {
term = true,
on_exit = function(_, code)
if vim.api.nvim_win_is_valid(win) then
vim.api.nvim_win_close(win, true)
end
if code == 0 then
vim.cmd("checktime")
else
vim.notify("parsing exited with code " .. code, vim.log.levels.WARN)
end
end,
})
vim.cmd("startinsert")
end
vim.keymap.set("n", "<leader>p", M.run, { desc = "parsing: interactive qualify imports" })
return M
Requires parsing and fzf on PATH, and Neovim 0.10+ for jobstart({ term = true }) (on older versions swap that call for vim.fn.termopen).
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file parsing_lsp-1.0.0.tar.gz.
File metadata
- Download URL: parsing_lsp-1.0.0.tar.gz
- Upload date:
- Size: 18.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1c6a4370ad83ab83d1817411419db216eb89c49d0c64a9d2cb8abe72a4daadd4
|
|
| MD5 |
c6d178b14007b60b910e86e578c85234
|
|
| BLAKE2b-256 |
d5a254aa216db197a666f54a54ba7c8e4c0f580efae84c21d139ab2745d220e5
|
File details
Details for the file parsing_lsp-1.0.0-py3-none-any.whl.
File metadata
- Download URL: parsing_lsp-1.0.0-py3-none-any.whl
- Upload date:
- Size: 7.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5d01a2fc19c81a0a2ad305a56fd9b257ec0eb94bba164e292051406d06093bce
|
|
| MD5 |
44d17b935deff4e764e0fc73842d946d
|
|
| BLAKE2b-256 |
3a04e7d389f0bae15dcc2b7b350d8780adc23a7e0a06e73b4aa4a936a6bb0e00
|