Skip to content
Closed
Changes from 1 commit
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
24 changes: 23 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 ((= virtualenv-type "pyenv")
Copy link
Member

@ericdallo ericdallo Jun 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think string= is better for string comparison.
Is there any reason for virtualenv-type to be a string? a symbol could fit better, what do you think?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I afraid that symbol will pollute global variables... (I know emacs-lisp a bit.)
string= is better

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the symbol is correct in terms of emacs lisp, please tell me.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Symbols don't pollute the global namespace, unless you intern them, which you needn't do. A symbol ('foo) is just a lisp object like an int, string, .... You could use (eq virtualenv-type 'pyenv) instead of (= virtualenv-type "pyenv"), the latter invalid anyway since = can only compare ints and markers.

(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)
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,14 +265,17 @@ 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)
(dap-register-debug-template "Python :: Run pytest (at point)"
(list :type "python-test-at-point"
:args ""
:module "pytest"
:virtualenv "pyenv"
:request "launch"
:virtualenv "pyenv"
:name "Python :: Run pytest (at point)"))

(provide 'dap-python)
Expand Down