Procházet zdrojové kódy

Wip with-venv

master
10sr před 5 roky
rodič
revize
33b8120ed9
Podepsáno: 10sr ID GPG klíče: 7BEC428194130EB2
1 změnil soubory, kde provedl 41 přidání a 0 odebrání
  1. +41
    -0
      emacs.el

+ 41
- 0
emacs.el Zobrazit soubor

@@ -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


Načítá se…
Zrušit
Uložit