From 20c3bc59e781b05474f081b7810a83647d40557c Mon Sep 17 00:00:00 2001 From: Mokke Meguru Date: Mon, 8 Jun 2020 23:22:00 +0900 Subject: [PATCH 1/2] Remove pyenv support See. https://github.com/emacs-lsp/dap-mode/pull/293 --- dap-python.el | 27 ++++----------------------- 1 file changed, 4 insertions(+), 23 deletions(-) diff --git a/dap-python.el b/dap-python.el index 17b5b0f1..783b0bb0 100644 --- a/dap-python.el +++ b/dap-python.el @@ -48,28 +48,6 @@ For example you may set it to `xterm -e' which will pop xterm console when you a :risky t :type 'string) -(defun dap-python--pyenv-executable-find (command) - "Find executable taking pyenv shims into account. -If the executable is a system executable and not in the same path -as the pyenv version then also return nil. This works around https://github.com/pyenv/pyenv-which-ext -" - (if (executable-find "pyenv") - (progn - (let ((pyenv-string (shell-command-to-string (concat "pyenv which " command))) - (pyenv-version-names (split-string (string-trim (shell-command-to-string "pyenv version-name")) ":")) - (executable nil) - (i 0)) - (if (not (string-match "not found" pyenv-string)) - (while (and (not executable) - (< i (length pyenv-version-names))) - (if (string-match (elt pyenv-version-names i) (string-trim pyenv-string)) - (setq executable (string-trim pyenv-string))) - (if (string-match (elt pyenv-version-names i) "system") - (setq executable (string-trim (executable-find command)))) - (setq i (1+ i)))) - executable)) - (executable-find command))) - (cl-defstruct dap-python--point (line (:type integer) :named t) (character (:type integer) :named t)) @@ -180,7 +158,7 @@ as the pyenv version then also return nil. This works around https://github.com/ "Populate CONF with the required arguments." (let* ((host "localhost") (debug-port (dap--find-available-port)) - (python-executable (dap-python--pyenv-executable-find dap-python-executable)) + (python-executable (plist-get conf :python-exec-path)) (python-args (or (plist-get conf :args) "")) (program (or (plist-get conf :target-module) (plist-get conf :program) @@ -237,6 +215,7 @@ as the pyenv version then also return nil. This works around https://github.com/ :module nil :program nil :request "launch" + :python-exec-path "/usr/bin/python" :name "Python :: Run file (buffer)")) (dap-register-debug-template "Python :: Run pytest (buffer)" @@ -246,6 +225,7 @@ as the pyenv version then also return nil. This works around https://github.com/ :program nil :module "pytest" :request "launch" + :python-exec-path "/usr/bin/python" :name "Python :: Run pytest (buffer)")) (dap-register-debug-provider "python-test-at-point" 'dap-python--populate-test-at-point) @@ -254,6 +234,7 @@ as the pyenv version then also return nil. This works around https://github.com/ :args "" :module "pytest" :request "launch" + :python-exec-path "/usr/bin/python" :name "Python :: Run pytest (at point)")) (provide 'dap-python) From a0acc100f2530ac858975b0399441aa9a36f11c6 Mon Sep 17 00:00:00 2001 From: Mokke Meguru Date: Mon, 8 Jun 2020 23:29:11 +0900 Subject: [PATCH 2/2] Add pyenv support and move solving-path function Path will be solved in the template. It's good for customizing. --- dap-python.el | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/dap-python.el b/dap-python.el index 783b0bb0..84d99f7a 100644 --- a/dap-python.el +++ b/dap-python.el @@ -48,6 +48,28 @@ For example you may set it to `xterm -e' which will pop xterm console when you a :risky t :type 'string) +(defun dap-python--pyenv-executable-find (command) + "Find executable taking pyenv shims into account. +If the executable is a system executable and not in the same path +as the pyenv version then also return nil. This works around https://github.com/pyenv/pyenv-which-ext +" + (if (executable-find "pyenv") + (progn + (let ((pyenv-string (shell-command-to-string (concat "pyenv which " command))) + (pyenv-version-names (split-string (string-trim (shell-command-to-string "pyenv version-name")) ":")) + (executable nil) + (i 0)) + (if (not (string-match "not found" pyenv-string)) + (while (and (not executable) + (< i (length pyenv-version-names))) + (if (string-match (elt pyenv-version-names i) (string-trim pyenv-string)) + (setq executable (string-trim pyenv-string))) + (if (string-match (elt pyenv-version-names i) "system") + (setq executable (string-trim (executable-find command)))) + (setq i (1+ i)))) + executable)) + (executable-find command))) + (cl-defstruct dap-python--point (line (:type integer) :named t) (character (:type integer) :named t)) @@ -215,7 +237,7 @@ For example you may set it to `xterm -e' which will pop xterm console when you a :module nil :program nil :request "launch" - :python-exec-path "/usr/bin/python" + :python-exec-path (dap-python--pyenv-executable-find dap-python-executable) :name "Python :: Run file (buffer)")) (dap-register-debug-template "Python :: Run pytest (buffer)" @@ -225,7 +247,7 @@ For example you may set it to `xterm -e' which will pop xterm console when you a :program nil :module "pytest" :request "launch" - :python-exec-path "/usr/bin/python" + :python-exec-path (dap-python--pyenv-executable-find dap-python-executable) :name "Python :: Run pytest (buffer)")) (dap-register-debug-provider "python-test-at-point" 'dap-python--populate-test-at-point) @@ -234,7 +256,7 @@ For example you may set it to `xterm -e' which will pop xterm console when you a :args "" :module "pytest" :request "launch" - :python-exec-path "/usr/bin/python" + :python-exec-path (dap-python--pyenv-executable-find dap-python-executable) :name "Python :: Run pytest (at point)")) (provide 'dap-python)