From e3b55d979874046b2dd99eb3d0349616317c9394 Mon Sep 17 00:00:00 2001 From: Kalle Jepsen Date: Fri, 20 Oct 2023 09:58:03 +0200 Subject: [PATCH] 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 --- docs/release-notes/rl-0.5.adoc | 2 ++ modules/languages/python.nix | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/docs/release-notes/rl-0.5.adoc b/docs/release-notes/rl-0.5.adoc index 530e9ee..e14bd44 100644 --- a/docs/release-notes/rl-0.5.adoc +++ b/docs/release-notes/rl-0.5.adoc @@ -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 diff --git a/modules/languages/python.nix b/modules/languages/python.nix index a30f800..cdabdf0 100644 --- a/modules/languages/python.nix +++ b/modules/languages/python.nix @@ -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";