Restore ability to specify dir to source env from

This commit is contained in:
Jeremy Dormitzer 2020-03-19 15:44:01 -04:00
parent 490cd7a4b0
commit 495ef0aced

View File

@ -512,12 +512,13 @@ Pretty-print JSON:
Load environment variables into Emacs from a shell script:
#+BEGIN_SRC emacs-lisp
(defun extract-vars-from-env-file (file)
(cl-defun extract-vars-from-env-file (file &key dir)
"Extracts an alist of variable name to value from
a bash script that exports environment variables."
(let ((var-re "\\(.+?\\)=\\(.+\\)$")
(env '()))
(with-temp-buffer
(cd (expand-file-name (or dir (file-name-directory file))))
(shell-command (concat "source " file " > /dev/null && env")
(current-buffer))
(goto-char (point-min))
@ -532,7 +533,7 @@ Load environment variables into Emacs from a shell script:
(dolist (binding env)
(setenv (car binding) (cdr binding)))))
(defmacro with-env-from-file (file &rest body)
(cl-defmacro with-env-from-file (file &rest body)
(declare (indent 1))
(let ((env-var (make-symbol "the-env"))
(path-var (make-symbol "the-path")))
@ -550,8 +551,8 @@ Load environment variables into Emacs from a shell script:
process-environment)))
,@body)))
(defun call-with-env-from-file (file callback)
(let* ((env (extract-vars-from-env-file file))
(cl-defun call-with-env-from-file (file callback &key dir)
(let* ((env (extract-vars-from-env-file file :dir dir))
(path (assoc "PATH" env))
(exec-path
(if path
@ -4844,13 +4845,13 @@ Some functions to make my day job easier.
(kill-matching-buffers "\\.log$" nil t)
(message "Killed log buffers"))
(defun python-service-setup (venv &optional env-file)
(cl-defun python-service-setup (venv &optional env-file &key env-dir)
(lambda (done)
(call-with-venv
venv
(if env-file
(lambda ()
(call-with-env-from-file env-file done))
(call-with-env-from-file env-file done :dir env-dir))
done))))
(defun call-with-lola-env (callback)
@ -5004,7 +5005,8 @@ Some functions to make my day job easier.
:cwd "~/lola/python-services"
:stop-signal 'int
:init-async (python-service-setup "python-services-gHe3SIKn"
"~/lola/python-services/priceline/.env"))
"~/lola/python-services/priceline/.env"
:env-dir "~/lola/python-services"))
(prodigy-define-service
:name "threev-service"
@ -5014,7 +5016,8 @@ Some functions to make my day job easier.
:cwd "~/lola/python-services"
:stop-signal 'int
:init-async (python-service-setup "python-services-gHe3SIKn"
"~/lola/python-services/threev/.env"))
"~/lola/python-services/threev/.env"
:env-dir "~/lola/python-services"))
(prodigy-define-service
:name "email-template-service"