languages/python: add black-and-isort formatter

Adds two additional formatters for python:

- isort, to only sort imports
- black-and-isort, which runs black + isort in a compatible manner
This commit is contained in:
Kalle Jepsen 2023-10-20 09:58:03 +02:00
parent 897493a65f
commit e3b55d9798
2 changed files with 30 additions and 0 deletions

View file

@ -73,3 +73,5 @@ https://github.com/jacekpoz[jacekpoz]:
https://github.com/ksonj[ksonj]:
* Add support to change mappings to utility/surround
* Add black-and-isort python formatter

View file

@ -39,6 +39,34 @@ with builtins; let
)
'';
};
isort = {
package = pkgs.black;
nullConfig = ''
table.insert(
ls_sources,
null_ls.builtins.formatting.isort.with({
command = "${cfg.format.package}/bin/isort",
})
)
'';
};
black-and-isort = {
package = pkgs.writeShellApplication {
name = "black";
text = ''
black --quiet - "$@" | isort --profile black -
'';
runtimeInputs = [pkgs.black pkgs.isort];
};
nullConfig = ''
table.insert(
ls_sources,
null_ls.builtins.formatting.black.with({
command = "${cfg.format.package}/bin/black",
})
)
'';
};
};
defaultDebugger = "debugpy";