Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update dap-python for running in pipenv #293

Closed
wants to merge 5 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion dap-python.el
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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 ((string= virtualenv-type "pyenv")
(dap-python--pyenv-executable-find dap-python-executable))
((string= 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)
Expand Down Expand Up @@ -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)"
Expand All @@ -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)
Expand All @@ -254,6 +274,7 @@ as the pyenv version then also return nil. This works around https://github.com/
:args ""
:module "pytest"
:request "launch"
:virtualenv "pyenv"
MokkeMeguru marked this conversation as resolved.
Show resolved Hide resolved
:name "Python :: Run pytest (at point)"))

(provide 'dap-python)
Expand Down