From 178456df0682b6bf80cf00be60fff817967bc1a7 Mon Sep 17 00:00:00 2001 From: Evie Litherland-Smith Date: Wed, 15 May 2024 11:47:20 +0100 Subject: [PATCH] Python switch to black and flake8 for ruff (+ isort) Add black profile option to isort formatter call Keep option for flake8 as checker if ruff not available (e.g. on another machine) --- init.el | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/init.el b/init.el index 000b985..e640e10 100644 --- a/init.el +++ b/init.el @@ -926,9 +926,10 @@ :custom (apheleia-remote-algorithm 'local) :config (add-to-list 'apheleia-formatters '(alejandra . ("alejandra"))) + (add-to-list 'apheleia-formatters '(isort . ("isort" "--profile" "black" "-"))) (add-to-list 'apheleia-mode-alist '(nix-mode . alejandra)) - (add-to-list 'apheleia-mode-alist '(python-mode . (black isort))) - (add-to-list 'apheleia-mode-alist '(python-ts-mode . (black isort)))) + (add-to-list 'apheleia-mode-alist '(python-mode . (ruff isort))) + (add-to-list 'apheleia-mode-alist '(python-ts-mode . (ruff isort)))) (use-package flymake :bind (("C-c C-." . flymake-goto-next-error) @@ -1025,15 +1026,15 @@ Calls `project-remember-project-under' for ~/.config/, (use-package python :hook ((python-base-mode . (lambda () (my/enable-fill-column 88))) - (python-base-mode . (lambda () (add-hook 'flymake-diagnostic-functions - 'flymake-collection-mypy nil t)))) + (python-base-mode . (lambda () (add-hook 'flymake-diagnostic-functions 'flymake-collection-mypy nil t)))) :custom - ;; Set max line length for compatibility with black formatter (python-flymake-command - (cond ((executable-find "flake8") '("flake8" "--max-line-length" "88" "-")) + (cond ((executable-find "ruff") ("ruff" "check" "--output-format" "pylint" "-")) + ((executable-find "flake8") ("flake8" "--max-line-length" "88" "-")) (t ("pyflakes")))) (python-check-command - (cond ((executable-find "flake8") "flake8 --max-line-length 88") + (cond ((executable-find "ruff") "ruff check --output-format pylint") + ((executable-find "flake8") "flake8 --max-line-length 88") (t "pyflakes"))) :config (setq python-ts-mode-hook python-mode-hook))