From 04b76fd0ce3fdc8446e68067c29415ff3890e0ae Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sat, 16 Apr 2022 02:57:21 +0200 Subject: [PATCH] fix(python): HTTP request from pip-requirements-mode pip-requirements-mode fetches the pypi.org package list via HTTP request, which blocks. This can sometimes take unbearably long in cases where the user has a slow or no internet connection. This fix defers this behavior until the first time completion is invoked. Fix: #5998 --- modules/lang/python/config.el | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/modules/lang/python/config.el b/modules/lang/python/config.el index e58093855..c1b7dab99 100644 --- a/modules/lang/python/config.el +++ b/modules/lang/python/config.el @@ -311,6 +311,24 @@ :after cython-mode) +(use-package! pip-requirements + :defer t + :config + ;; HACK `pip-requirements-mode' performs a sudden HTTP request to + ;; https://pypi.org/simple, which causes unexpected hangs (see #5998). This + ;; advice defers this behavior until the first time completion is invoked. + ;; REVIEW More sensible behavior should be PRed upstream. + (defadvice! +python--init-completion-a (&rest args) + "Call `pip-requirements-fetch-packages' first time completion is invoked." + :before #'pip-requirements-complete-at-point + (unless pip-packages (pip-requirements-fetch-packages))) + (defadvice! +python--inhibit-pip-requirements-fetch-packages-a (fn &rest args) + "No-op `pip-requirements-fetch-packages', which can be expensive." + :around #'pip-requirements-mode + (letf ((#'pip-requirements-fetch-packages #'ignore)) + (apply fn args)))) + + ;; ;;; LSP