From 86bf3bb1550d4fedfdffc25a6a165ba583e15cad Mon Sep 17 00:00:00 2001 From: Clay Harrison Date: Fri, 18 Jul 2025 16:09:17 +0200 Subject: [PATCH 1/6] Let executable-find work over remote --- micromamba.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/micromamba.el b/micromamba.el index 69c7268..c8108b4 100644 --- a/micromamba.el +++ b/micromamba.el @@ -49,7 +49,7 @@ "Micromamba (environment manager) integration for Emacs." :group 'python) -(defcustom micromamba-executable (executable-find "micromamba") +(defcustom micromamba-executable (executable-find "micromamba" 1) "Path to micromamba executable." :type 'string :group 'micromamba) From 72b425c06924a3f5de4031a654b9ec7d2e646161 Mon Sep 17 00:00:00 2001 From: Clay Harrison Date: Fri, 18 Jul 2025 16:09:32 +0200 Subject: [PATCH 2/6] Add safe-shell-command and use it for getting json (broken) --- micromamba.el | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/micromamba.el b/micromamba.el index c8108b4..7267c31 100644 --- a/micromamba.el +++ b/micromamba.el @@ -87,6 +87,12 @@ (defvar eshell-path-env) +(defun safe-shell-command (args &optional output-buffer error-buffer) + (apply 'shell-command (mapconcat 'shell-quote-argument args " ") + output-buffer error-buffer nil)) + +;; (safe-shell-command (#'micromamba-executable "env" "list" "--json")) + (defun micromamba--call-json (&rest args) "Call micromamba and parse the return value as JSON. @@ -94,7 +100,9 @@ Pass ARGS as arguments to the program." (unless micromamba-executable (user-error "Micromamba-executable is not set!")) (with-temp-buffer - (apply #'call-process micromamba-executable nil t nil args) + (if (file-remote-p default-directory) + (safe-shell-command (cons micromamba-executable args) (current-buffer)) + (apply #'call-process micromamba-executable nil t nil args)) (goto-char (point-min)) (json-read))) From 2cfbe35ec292083edf9aadc44be675c32c6a9134 Mon Sep 17 00:00:00 2001 From: claytharrison Date: Sat, 19 Jul 2025 16:22:44 +0200 Subject: [PATCH 3/6] Get activation/deactivation params without errors --- micromamba.el | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/micromamba.el b/micromamba.el index 7267c31..297b15e 100644 --- a/micromamba.el +++ b/micromamba.el @@ -87,11 +87,11 @@ (defvar eshell-path-env) -(defun safe-shell-command (args &optional output-buffer error-buffer) +(defun micromamba--safe-shell-command (args &optional output-buffer error-buffer) + "Run a shell command with ARGS OUTPUT-BUFFER ERROR-BUFFER." (apply 'shell-command (mapconcat 'shell-quote-argument args " ") output-buffer error-buffer nil)) -;; (safe-shell-command (#'micromamba-executable "env" "list" "--json")) (defun micromamba--call-json (&rest args) "Call micromamba and parse the return value as JSON. @@ -101,7 +101,7 @@ Pass ARGS as arguments to the program." (user-error "Micromamba-executable is not set!")) (with-temp-buffer (if (file-remote-p default-directory) - (safe-shell-command (cons micromamba-executable args) (current-buffer)) + (micromamba--safe-shell-command (cons micromamba-executable args) (current-buffer)) (apply #'call-process micromamba-executable nil t nil args)) (goto-char (point-min)) (json-read))) @@ -236,8 +236,10 @@ Return `micromamba-fallback-environment' if not found." The parameters value is an alist as defined by `micromamba--parse-script-buffer'." (with-temp-buffer - (call-process micromamba-executable nil t nil - "shell" "activate" prefix "-s" "bash") + (if (file-remote-p default-directory) + (micromamba--safe-shell-command (list micromamba-executable "shell" "activate" prefix "-s" "bash") (current-buffer)) + (call-process micromamba-executable nil t nil + "shell" "activate" prefix "-s" "bash")) (goto-char (point-min)) (micromamba--parse-script-buffer))) @@ -247,8 +249,12 @@ The parameters value is an alist as defined by The parameters value is an alist as defined by `micromamba--parse-script-buffer'." (with-temp-buffer - (call-process micromamba-executable nil t nil - "shell" "deactivate" "-s" "bash") + (if (file-remote-p default-directory) + (micromamba--safe-shell-command (list + micromamba-executable "run" "micromamba" "shell" "deactivate" "-s" "bash") (current-buffer)) + (call-process micromamba-executable nil t nil + "shell" "deactivate" "-s" "bash")) + (goto-char (point-min)) (micromamba--parse-script-buffer))) From e5596b4b4b113ad75c6667aa64601d9b13dcf9e8 Mon Sep 17 00:00:00 2001 From: claytharrison Date: Sat, 19 Jul 2025 16:42:39 +0200 Subject: [PATCH 4/6] Cleanup a bit --- micromamba.el | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/micromamba.el b/micromamba.el index 297b15e..01cb552 100644 --- a/micromamba.el +++ b/micromamba.el @@ -237,7 +237,7 @@ The parameters value is an alist as defined by `micromamba--parse-script-buffer'." (with-temp-buffer (if (file-remote-p default-directory) - (micromamba--safe-shell-command (list micromamba-executable "shell" "activate" prefix "-s" "bash") (current-buffer)) + (micromamba--safe-shell-command (list micromamba-executable "shell" "activate" prefix "-s" "bash")) (call-process micromamba-executable nil t nil "shell" "activate" prefix "-s" "bash")) (goto-char (point-min)) @@ -250,8 +250,7 @@ The parameters value is an alist as defined by `micromamba--parse-script-buffer'." (with-temp-buffer (if (file-remote-p default-directory) - (micromamba--safe-shell-command (list - micromamba-executable "run" "micromamba" "shell" "deactivate" "-s" "bash") (current-buffer)) + (micromamba--safe-shell-command (list micromamba-executable "run" "micromamba" "shell" "deactivate" "-s" "bash")) (call-process micromamba-executable nil t nil "shell" "deactivate" "-s" "bash")) From 3c63a7ddd2ee44221116d0f07620f0820ffe41c0 Mon Sep 17 00:00:00 2001 From: claytharrison Date: Sat, 19 Jul 2025 18:48:12 +0200 Subject: [PATCH 5/6] Get rid of safe-shell-command, not needed --- micromamba.el | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/micromamba.el b/micromamba.el index 01cb552..b673f13 100644 --- a/micromamba.el +++ b/micromamba.el @@ -87,12 +87,6 @@ (defvar eshell-path-env) -(defun micromamba--safe-shell-command (args &optional output-buffer error-buffer) - "Run a shell command with ARGS OUTPUT-BUFFER ERROR-BUFFER." - (apply 'shell-command (mapconcat 'shell-quote-argument args " ") - output-buffer error-buffer nil)) - - (defun micromamba--call-json (&rest args) "Call micromamba and parse the return value as JSON. @@ -101,7 +95,7 @@ Pass ARGS as arguments to the program." (user-error "Micromamba-executable is not set!")) (with-temp-buffer (if (file-remote-p default-directory) - (micromamba--safe-shell-command (cons micromamba-executable args) (current-buffer)) + (shell-command (mapconcat 'identity (cons micromamba-executable args) " ") (current-buffer)) (apply #'call-process micromamba-executable nil t nil args)) (goto-char (point-min)) (json-read))) @@ -237,7 +231,11 @@ The parameters value is an alist as defined by `micromamba--parse-script-buffer'." (with-temp-buffer (if (file-remote-p default-directory) - (micromamba--safe-shell-command (list micromamba-executable "shell" "activate" prefix "-s" "bash")) + (shell-command + (mapconcat 'identity + (list micromamba-executable "shell" + "activate" prefix "-s" "bash") " ") + (current-buffer)) (call-process micromamba-executable nil t nil "shell" "activate" prefix "-s" "bash")) (goto-char (point-min)) @@ -250,7 +248,12 @@ The parameters value is an alist as defined by `micromamba--parse-script-buffer'." (with-temp-buffer (if (file-remote-p default-directory) - (micromamba--safe-shell-command (list micromamba-executable "run" "micromamba" "shell" "deactivate" "-s" "bash")) + (shell-command + (mapconcat 'identity + (list micromamba-executable "run" + "micromamba" "shell" + "deactivate" "-s" "bash") " ") + (current-buffer)) (call-process micromamba-executable nil t nil "shell" "deactivate" "-s" "bash")) From 2ef6ac7e1917c45af51f4a2f7165bcbe4360a552 Mon Sep 17 00:00:00 2001 From: claytharrison Date: Sat, 19 Jul 2025 20:12:23 +0200 Subject: [PATCH 6/6] Simplify/improve concatenation for shell-command --- micromamba.el | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/micromamba.el b/micromamba.el index b673f13..c80f55d 100644 --- a/micromamba.el +++ b/micromamba.el @@ -95,7 +95,7 @@ Pass ARGS as arguments to the program." (user-error "Micromamba-executable is not set!")) (with-temp-buffer (if (file-remote-p default-directory) - (shell-command (mapconcat 'identity (cons micromamba-executable args) " ") (current-buffer)) + (shell-command (mapconcat #'shell-quote-argument (cons micromamba-executable args) " ") (current-buffer)) (apply #'call-process micromamba-executable nil t nil args)) (goto-char (point-min)) (json-read))) @@ -232,9 +232,8 @@ The parameters value is an alist as defined by (with-temp-buffer (if (file-remote-p default-directory) (shell-command - (mapconcat 'identity - (list micromamba-executable "shell" - "activate" prefix "-s" "bash") " ") + (concat micromamba-executable " shell" + " activate " prefix " -s" " bash") (current-buffer)) (call-process micromamba-executable nil t nil "shell" "activate" prefix "-s" "bash")) @@ -249,10 +248,9 @@ The parameters value is an alist as defined by (with-temp-buffer (if (file-remote-p default-directory) (shell-command - (mapconcat 'identity - (list micromamba-executable "run" - "micromamba" "shell" - "deactivate" "-s" "bash") " ") + (concat micromamba-executable " run" + " micromamba" " shell" + " deactivate" " -s" " bash") (current-buffer)) (call-process micromamba-executable nil t nil "shell" "deactivate" "-s" "bash"))