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 python customization
(lsp-register-custom-settings (lsp-register-custom-settings
'(("pylsp.plugins.pyls_mypy.enabled" t t) '(("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.yapf.enabled" t t)
("pylsp.plugins.pylint.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. ;; Enable virtualenv support.
(when(feature-p 'pyvenv) (when(feature-p 'pyvenv)
(pyvenv-mode t)) (pyvenv-mode t))
(when(feature-p 'anaconda-mode) (when(feature-p 'anaconda-mode)
(anaconda-mode t)) (anaconda-mode t))
;; Enable smart parenthesis handling. ;; Enable smart parenthesis handling.
(user/smartparens-enable) (user/smartparens-enable)
@@ -39,8 +50,8 @@
:mode ("SCon\(struct\|script\)$" . python-mode) :mode ("SCon\(struct\|script\)$" . python-mode)
:interpreter ("python[0-9.]*" . python-mode) :interpreter ("python[0-9.]*" . python-mode)
:hook :hook
(python-mode-hook . lsp)
(python-mode-hook . user--python-mode-hook) (python-mode-hook . user--python-mode-hook)
(python-mode-hook . lsp-deferred)
(python-mode-hook . (lambda () (python-mode-hook . (lambda ()
(add-hook 'before-save-hook #'user--python-format-before-save nil t))) (add-hook 'before-save-hook #'user--python-format-before-save nil t)))
@@ -48,7 +59,7 @@
(validate-setq (validate-setq
;; Don't try to guess the indentation. ;; Don't try to guess the indentation.
python-indent-guess-indent-offset nil) python-indent-guess-indent-offset nil)
(with-executable 'ipython3 (with-executable 'ipython3
(validate-setq (validate-setq
;; Set IPython as default interpreter. ;; Set IPython as default interpreter.
@@ -56,8 +67,8 @@
python-shell-interpreter-args "" python-shell-interpreter-args ""
python-shell-prompt-regexp "In \\[[0-9]+\\]: " python-shell-prompt-regexp "In \\[[0-9]+\\]: "
python-shell-prompt-output-regexp "Out\\[[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-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-string-code "';'.join(get_ipython().Completer.all_completions('''%s'''))\n"))
(with-executable 'bpython (with-executable 'bpython
(defun user/bpython-term() (defun user/bpython-term()
@@ -72,6 +83,14 @@
;; https://github.com/pythonic-emacs/anaconda-mode ;; https://github.com/pythonic-emacs/anaconda-mode
;; Code navigation, documentation lookup and completion for Python. ;; Code navigation, documentation lookup and completion for Python.
(use-package anaconda-mode) (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 ;; https://github.com/tsgates/pylookup
;; Emacs mode for searching python documents with convenience ;; Emacs mode for searching python documents with convenience
(use-package pylookup (use-package pylookup
@@ -119,7 +138,7 @@
:ensure t :ensure t
:config :config
(pyvenv-mode 1)) (pyvenv-mode 1))
;; https://github.com/emacsorphanage/helm-pydoc ;; https://github.com/emacsorphanage/helm-pydoc
;; helm-pydoc.el is pydoc helm interface ;; helm-pydoc.el is pydoc helm interface
(use-package helm-pydoc (use-package helm-pydoc