Python mode cleanup and pip-requirements package add.

Remove max line length from Python mode linter (use projects configuration files instead).
Use the setup.cfg instead of pyproject.toml to compute the project root dir.
Add the synxtaxic coloration for pip-requirements (pip-requirements package).
Defer the lsp server startup.
This commit is contained in:
2022-06-13 08:00:57 +02:00
parent 74f18cbcab
commit 14ad96d4da

View File

@@ -13,17 +13,28 @@
;; lsp python customization
(lsp-register-custom-settings
'(("pylsp.plugins.pyls_mypy.enabled" t t)
("pylsp.plugins.flake8.maxLineLength" 100)
;; ("pylsp.plugins.flake8.maxLineLength" 100)
;; ("pylsp.plugins.pycodestyle.maxLineLength" 100)
("pylsp.plugins.yapf.enabled" t t)
("pylsp.plugins.pylint.enabled" t t)))
;; locate the root pyproject.toml to force pylint rcfile
;; (let* ((filename "pyproject.toml")
(let* ((filename "setup.cfg")
(found (locate-dominating-file default-directory filename)))
(when found
(let ((pyproject (format "%s%s" (replace-regexp-in-string "~" (getenv "HOME") found) filename)))
(setq-local lsp-pylsp-plugins-pylint-args (vector (format "--rcfile=%s" pyproject))))))
(message (format "lsp-pylsp-plugins-pylint-args=%s" lsp-pylsp-plugins-pylint-args))
;; Enable virtualenv support.
(when(feature-p 'pyvenv)
(pyvenv-mode t))
(when(feature-p 'anaconda-mode)
(anaconda-mode t))
;; Enable smart parenthesis handling.
(user/smartparens-enable)
@@ -39,8 +50,8 @@
:mode ("SCon\(struct\|script\)$" . python-mode)
:interpreter ("python[0-9.]*" . python-mode)
:hook
(python-mode-hook . lsp)
(python-mode-hook . user--python-mode-hook)
(python-mode-hook . lsp-deferred)
(python-mode-hook . (lambda ()
(add-hook 'before-save-hook #'user--python-format-before-save nil t)))
@@ -48,7 +59,7 @@
(validate-setq
;; Don't try to guess the indentation.
python-indent-guess-indent-offset nil)
(with-executable 'ipython3
(validate-setq
;; Set IPython as default interpreter.
@@ -56,8 +67,8 @@
python-shell-interpreter-args ""
python-shell-prompt-regexp "In \\[[0-9]+\\]: "
python-shell-prompt-output-regexp "Out\\[[0-9]+\\]: "
python-shell-completion-setup-code "from IPython.core.completerlib import module_completion"
python-shell-completion-string-code "';'.join(get_ipython().Completer.all_completions('''%s'''))\n"))
python-shell-completion-setup-code "from IPython.core.completerlib import module_completion"))
;; python-shell-completion-string-code "';'.join(get_ipython().Completer.all_completions('''%s'''))\n"))
(with-executable 'bpython
(defun user/bpython-term()
@@ -72,6 +83,14 @@
;; https://github.com/pythonic-emacs/anaconda-mode
;; Code navigation, documentation lookup and completion for Python.
(use-package anaconda-mode)
;; https://github.com/Wilfred/pip-requirements.el
;; Major mode for editing pip requirements files
;; TODO: Find why completion does not run.
(use-package pip-requirements
:ensure t
)
;; https://github.com/tsgates/pylookup
;; Emacs mode for searching python documents with convenience
(use-package pylookup
@@ -119,7 +138,7 @@
:ensure t
:config
(pyvenv-mode 1))
;; https://github.com/emacsorphanage/helm-pydoc
;; helm-pydoc.el is pydoc helm interface
(use-package helm-pydoc