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