fix(python/autoflake): deal with non-zero exit, and better docs

Co-authored-by: Lucius Hu <lebensterben@users.noreply.github.com>
This commit is contained in:
lin.sun 2023-01-09 19:33:42 -08:00 committed by GitHub
parent 43d76ebe42
commit d10056b2d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 6 deletions

View File

@ -217,15 +217,16 @@ ROOT-DIR should be the path for the environemnt, `nil' for clean up"
;; from https://www.snip2code.com/Snippet/127022/Emacs-auto-remove-unused-import-statemen ;; from https://www.snip2code.com/Snippet/127022/Emacs-auto-remove-unused-import-statemen
(defun spacemacs/python-remove-unused-imports () (defun spacemacs/python-remove-unused-imports ()
"Use Autoflake to remove unused function" "Use Autoflake to remove unused imports.
"autoflake --remove-all-unused-imports -i unused_imports.py" Equivalent to: autoflake --remove-all-unused-imports --inplace <FILE>"
(interactive) (interactive)
(if (executable-find "autoflake") (if (executable-find "autoflake")
(progn (if (not (eql 0
(shell-command (format "autoflake --remove-all-unused-imports -i %s" (shell-command (format "autoflake --remove-all-unused-imports --inplace %s"
(shell-quote-argument (buffer-file-name)))) (shell-quote-argument (buffer-file-name))))))
(pop-to-buffer shell-command-buffer-name)
(revert-buffer t t t)) (revert-buffer t t t))
(message "Error: Cannot find autoflake executable."))) (user-error "Cannot find autoflake executable")))
(defun spacemacs//pyenv-mode-set-local-version () (defun spacemacs//pyenv-mode-set-local-version ()
"Set pyenv version from \".python-version\" by looking in parent directories." "Set pyenv version from \".python-version\" by looking in parent directories."