Selaa lähdekoodia

Wip with-venv

master
10sr 6 vuotta sitten
vanhempi
commit
33b8120ed9
Allekirjoittanut: 10sr GPG Key ID: 7BEC428194130EB2
1 muutettua tiedostoa jossa 41 lisäystä ja 0 poistoa
  1. +41
    -0
      emacs.el

+ 41
- 0
emacs.el Näytä tiedosto

@@ -2007,6 +2007,47 @@ initializing."
(tabulated-list-print nil nil))


;;;;;;;;;;;;;;;;;;;;;;;
;; with-venv

(defmacro with-venv-dir (dir &rest body)
"Set python environment to DIR and execute BODY."
`(progn
(message "%S" ,dir)
,@body))

(defmacro with-venv (&rest body)
"Execute BODY with venv enabled.

This function tries to find suitable venv dir, or raise error when none found."
`(with-venv-dir ,(with-venv-find-venv-dir) ,@body))

(defvar-local with-venv-venv-dir
nil
"Venv directory path.")

(defun with-venv-find-venv-dir (&optional dir)
"Try to find venv dir for DIR or raise error when none found."
(with-temp-buffer
(when dir
(cd dir))
(or
;; If set explicitly use it
with-venv-venv-dir
;; Check pipenv
(let ((status (call-process "pipenv" nil t nil "--venv")))
(goto-char (point-min))
(and (eq status 0)
(buffer-substring-no-properties (point-at-bol)
(point-at-eol))))
;; Search for .venv dir
(locate-dominating-file default-directory
".venv")))


;; (with-venv (:dir default-directory) (message "a"))
;; (with-venv () (message "a"))

;; Local Variables:
;; flycheck-disabled-checkers: (emacs-lisp-checkdoc)
;; flycheck-checker: emacs-lisp


Ladataan…
Peruuta
Tallenna