From 333dfb7a17b5781d2f1274b8193c831cd3c824a7 Mon Sep 17 00:00:00 2001 From: Mokke Meguru Date: Mon, 8 Jun 2020 20:25:30 +0900 Subject: [PATCH 1/5] Update dap-python for running in pipenv We have many options for executing the python program. At first, I want to add "pipenv" into the option. --- dap-python.el | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/dap-python.el b/dap-python.el index 17b5b0f1..d152574c 100644 --- a/dap-python.el +++ b/dap-python.el @@ -70,6 +70,17 @@ as the pyenv version then also return nil. This works around https://github.com/ executable)) (executable-find command))) +(defun dap-python--pipenv-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 "pipenv") + (let + ((pipenv-string (shell-command-to-string (concat "pipenv run which " command)))) + (executable-find (string-trim pipenv-string))) + (executable-find command)) + (cl-defstruct dap-python--point (line (:type integer) :named t) (character (:type integer) :named t)) @@ -180,7 +191,14 @@ 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)) + (virtualenv-type (plist-get conf :virtualenv)) + (python-executable + (cond ((= virtualenv-type "pyenv") + (dap-python--pyenv-executable-find dap-python-executable)) + ((= virtualenv-type "pipenv") + (dap-python--pipenv-executable-find dap-python-executable)) + (t + (executable-find dap-python-executable)))) (python-args (or (plist-get conf :args) "")) (program (or (plist-get conf :target-module) (plist-get conf :program) @@ -237,6 +255,7 @@ as the pyenv version then also return nil. This works around https://github.com/ :module nil :program nil :request "launch" + :virtualenv "pyenv" :name "Python :: Run file (buffer)")) (dap-register-debug-template "Python :: Run pytest (buffer)" @@ -246,6 +265,7 @@ as the pyenv version then also return nil. This works around https://github.com/ :program nil :module "pytest" :request "launch" + :virtualenv "pyenv" :name "Python :: Run pytest (buffer)")) (dap-register-debug-provider "python-test-at-point" 'dap-python--populate-test-at-point) @@ -253,7 +273,9 @@ as the pyenv version then also return nil. This works around https://github.com/ (list :type "python-test-at-point" :args "" :module "pytest" + :virtualenv "pyenv" :request "launch" + :virtualenv "pyenv" :name "Python :: Run pytest (at point)")) (provide 'dap-python) From edcbd303116f5f18f4f80c55f8220c744a29db35 Mon Sep 17 00:00:00 2001 From: Mokke Meguru Date: Mon, 8 Jun 2020 22:51:37 +0900 Subject: [PATCH 2/5] Update dap-python.el Co-authored-by: Eric Dallo --- dap-python.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dap-python.el b/dap-python.el index d152574c..6e46d51c 100644 --- a/dap-python.el +++ b/dap-python.el @@ -265,7 +265,7 @@ as the pyenv version then also return nil. This works around https://github.com/ :program nil :module "pytest" :request "launch" - :virtualenv "pyenv" + :virtualenv "pyenv" :name "Python :: Run pytest (buffer)")) (dap-register-debug-provider "python-test-at-point" 'dap-python--populate-test-at-point) From 9a9fc4c6396381ba96930a84fc4ba83a166848e8 Mon Sep 17 00:00:00 2001 From: Mokke Meguru Date: Mon, 8 Jun 2020 22:51:59 +0900 Subject: [PATCH 3/5] Update dap-python.el Co-authored-by: Eric Dallo --- dap-python.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dap-python.el b/dap-python.el index 6e46d51c..89ea45ac 100644 --- a/dap-python.el +++ b/dap-python.el @@ -255,7 +255,7 @@ as the pyenv version then also return nil. This works around https://github.com/ :module nil :program nil :request "launch" - :virtualenv "pyenv" + :virtualenv "pyenv" :name "Python :: Run file (buffer)")) (dap-register-debug-template "Python :: Run pytest (buffer)" From b806e0bf6812bf7606238b519b1a4c6b10633265 Mon Sep 17 00:00:00 2001 From: Mokke Meguru Date: Mon, 8 Jun 2020 22:54:18 +0900 Subject: [PATCH 4/5] Update dap-python.el --- dap-python.el | 1 - 1 file changed, 1 deletion(-) diff --git a/dap-python.el b/dap-python.el index 89ea45ac..d517931d 100644 --- a/dap-python.el +++ b/dap-python.el @@ -273,7 +273,6 @@ as the pyenv version then also return nil. This works around https://github.com/ (list :type "python-test-at-point" :args "" :module "pytest" - :virtualenv "pyenv" :request "launch" :virtualenv "pyenv" :name "Python :: Run pytest (at point)")) From 5e30288ccd3ee16c166e3effc3a05e67a5ac7a50 Mon Sep 17 00:00:00 2001 From: Mokke Meguru Date: Mon, 8 Jun 2020 22:54:54 +0900 Subject: [PATCH 5/5] Update dap-python.el --- dap-python.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dap-python.el b/dap-python.el index d517931d..5005f18d 100644 --- a/dap-python.el +++ b/dap-python.el @@ -193,9 +193,9 @@ as the pyenv version then also return nil. This works around https://github.com/ (debug-port (dap--find-available-port)) (virtualenv-type (plist-get conf :virtualenv)) (python-executable - (cond ((= virtualenv-type "pyenv") + (cond ((string= virtualenv-type "pyenv") (dap-python--pyenv-executable-find dap-python-executable)) - ((= virtualenv-type "pipenv") + ((string= virtualenv-type "pipenv") (dap-python--pipenv-executable-find dap-python-executable)) (t (executable-find dap-python-executable))))