From 265541d135c410ca9f045670c9e441eb48a6dd37 Mon Sep 17 00:00:00 2001 From: Ohad Livne Date: Wed, 4 Jun 2025 22:44:48 +0300 Subject: [PATCH] Automatically format Python files --- .config/emacs/init.el | 12 ++++++++++++ .local/bin/make-venv | 6 +++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/.config/emacs/init.el b/.config/emacs/init.el index 8bd2a71..d0dadd7 100644 --- a/.config/emacs/init.el +++ b/.config/emacs/init.el @@ -168,6 +168,18 @@ ("C-c C-l" . nil)) :hook ((python-mode . load-python-env))) +; Requires the Python package "black" +(use-package blacken + :hook (python-mode . blacken-mode)) + +; Requires the Python package "isort" +(use-package py-isort + :hook (before-save . (lambda () + (when (bound-and-true-p blacken-mode) + (py-isort-before-save)))) + :config + (setq py-isort-options '("--profile" "black"))) + ;; Jupyter notebook integration (use-package ein :bind (("C-z j" . ein:run) diff --git a/.local/bin/make-venv b/.local/bin/make-venv index 3de0439..942a9b5 100755 --- a/.local/bin/make-venv +++ b/.local/bin/make-venv @@ -2,5 +2,9 @@ python3 -m venv .venv . .venv/bin/activate -pip install 'python-lsp-server[rope]' python-lsp-ruff +pip install \ + black \ + isort \ + 'python-lsp-server[rope]' \ + python-lsp-ruff pip install -e .