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
(defun spacemacs/python-remove-unused-imports ()
"Use Autoflake to remove unused function"
"autoflake --remove-all-unused-imports -i unused_imports.py"
"Use Autoflake to remove unused imports.
Equivalent to: autoflake --remove-all-unused-imports --inplace <FILE>"
(interactive)
(if (executable-find "autoflake")
(progn
(shell-command (format "autoflake --remove-all-unused-imports -i %s"
(shell-quote-argument (buffer-file-name))))
(if (not (eql 0
(shell-command (format "autoflake --remove-all-unused-imports --inplace %s"
(shell-quote-argument (buffer-file-name))))))
(pop-to-buffer shell-command-buffer-name)
(revert-buffer t t t))
(message "Error: Cannot find autoflake executable.")))
(user-error "Cannot find autoflake executable")))
(defun spacemacs//pyenv-mode-set-local-version ()
"Set pyenv version from \".python-version\" by looking in parent directories."