diff options
author | Michael Albinus <michael.albinus@gmx.de> | 2024-05-07 09:56:05 +0200 |
---|---|---|
committer | Michael Albinus <michael.albinus@gmx.de> | 2024-05-07 09:56:05 +0200 |
commit | 4808c63d43f529f41aac2f2bb14df7ab8f882440 (patch) | |
tree | 1b9e2dfd99435fb3b3a61006334ff2f80c41c7aa /lisp/net | |
parent | 3bc9c38c471983431bc6768dd6cfe9e059e44a3b (diff) | |
download | emacs-4808c63d43f529f41aac2f2bb14df7ab8f882440.tar.gz |
Add Tramp method "apptainer"
* doc/misc/tramp.texi (Top, Configuration): Add "Optional methods".
(Optional methods): New section.
(Inline methods) <androidsu, toolbox, flatpak>: These are optional
methods.
(Inline methods) <apptainer>: Add.
* etc/NEWS: New Tramp method "apptainer".
Some Tramp methods are optional.
Fix typos.
* lisp/net/tramp-androidsu.el (tramp-enable-androidsu-method):
New defun. Call it when `system-type' is `android'.
* lisp/net/tramp-container.el (tramp-apptainer-program): New defcustom.
(tramp-apptainer-method): New defconst.
(tramp-apptainer--completion-function)
(tramp-enable-toolbox-method, tramp-enable-flatpak-method)
(tramp-enable-apptainer-method): New defuns.
* lisp/net/tramp.el (tramp-enable-method): New defun.
* test/lisp/net/tramp-tests.el (tramp--test-container-p):
Add "apptainer".
(tramp--test-supports-processes-p): Extend function.
Diffstat (limited to 'lisp/net')
-rw-r--r-- | lisp/net/tramp-androidsu.el | 32 | ||||
-rw-r--r-- | lisp/net/tramp-container.el | 203 | ||||
-rw-r--r-- | lisp/net/tramp.el | 9 |
3 files changed, 164 insertions, 80 deletions
diff --git a/lisp/net/tramp-androidsu.el b/lisp/net/tramp-androidsu.el index aa7871e6a33..3dcee8e2f8a 100644 --- a/lisp/net/tramp-androidsu.el +++ b/lisp/net/tramp-androidsu.el @@ -77,19 +77,25 @@ may edit files belonging to any and all applications." "Name of the local temporary directory on Android.") ;;;###tramp-autoload -(tramp--with-startup - (add-to-list 'tramp-methods - `(,tramp-androidsu-method - (tramp-login-program "su") - (tramp-login-args (("-") ("%u"))) - (tramp-remote-shell ,tramp-androidsu-local-shell-name) - (tramp-remote-shell-login ("-l")) - (tramp-remote-shell-args ("-c")) - (tramp-tmpdir ,tramp-androidsu-local-tmp-directory) - (tramp-connection-timeout 10) - (tramp-shell-name ,tramp-androidsu-local-shell-name))) - (add-to-list 'tramp-default-user-alist - `(,tramp-androidsu-method nil ,tramp-root-id-string))) +(defun tramp-enable-androidsu-method () + "Enable \"androidsu\" method." + (add-to-list 'tramp-methods + `(,tramp-androidsu-method + (tramp-login-program "su") + (tramp-login-args (("-") ("%u"))) + (tramp-remote-shell ,tramp-androidsu-local-shell-name) + (tramp-remote-shell-login ("-l")) + (tramp-remote-shell-args ("-c")) + (tramp-tmpdir ,tramp-androidsu-local-tmp-directory) + (tramp-connection-timeout 10) + (tramp-shell-name ,tramp-androidsu-local-shell-name))) + + (add-to-list 'tramp-default-user-alist + `(,tramp-androidsu-method nil ,tramp-root-id-string))) + +;;;###tramp-autoload +(when (eq system-type 'android) + (tramp-enable-androidsu-method)) (defvar android-use-exec-loader) ; androidfns.c. diff --git a/lisp/net/tramp-container.el b/lisp/net/tramp-container.el index 30639cbeb85..7559f958838 100644 --- a/lisp/net/tramp-container.el +++ b/lisp/net/tramp-container.el @@ -83,6 +83,15 @@ ;; Where: ;; SANDBOX is the running sandbox to connect to. ;; It could be an application ID, an instance ID, or a PID. +;; +;; +;; +;; Open a file on a running Apptainer instance: +;; +;; C-x C-f /apptainer:INSTANCE:/path/to/file +;; +;; Where: +;; INSTANCE is the running instance to connect to. ;;; Code: @@ -143,6 +152,14 @@ If it is nil, the default context will be used." (string))) ;;;###tramp-autoload +(defcustom tramp-apptainer-program "apptainer" + "Name of the Apptainer client program." + :group 'tramp + :version "30.1" + :type '(choice (const "apptainer") + (string))) + +;;;###tramp-autoload (defconst tramp-docker-method "docker" "Tramp method name to use to connect to Docker containers.") @@ -173,6 +190,10 @@ This is for out-of-band connections.") "Tramp method name to use to connect to Flatpak sandboxes.") ;;;###tramp-autoload +(defconst tramp-apptainer-method "apptainer" + "Tramp method name to use to connect to Apptainer instances.") + +;;;###tramp-autoload (defmacro tramp-skeleton-completion-function (method &rest body) "Skeleton for `tramp-*-completion-function' with multi-hop support. BODY is the backend specific code." @@ -374,6 +395,28 @@ see its function help for a description of the format." (mapcar (lambda (name) (list nil name)) (delq nil names))))) ;;;###tramp-autoload +(defun tramp-apptainer--completion-function (method) + "List Apptainer instances available for connection. + +This function is used by `tramp-set-completion-function', please +see its function help for a description of the format." + (tramp-skeleton-completion-function method + (when-let ((raw-list + (shell-command-to-string (concat program " instance list"))) + ;; Ignore header line. + (lines (cdr (split-string raw-list "\n" 'omit))) + (names (mapcar + (lambda (line) + (when (string-match + (rx bol (group (1+ (not space))) + (1+ space) (1+ (not space)) + (1+ space) (1+ (not space))) + line) + (match-string 1 line))) + lines))) + (mapcar (lambda (name) (list nil name)) (delq nil names))))) + +;;;###tramp-autoload (defvar tramp-default-remote-shell) ;; Silence byte compiler. ;;;###tramp-autoload @@ -453,29 +496,9 @@ see its function help for a description of the format." (tramp-remote-shell-login ("-l")) (tramp-remote-shell-args ("-i" "-c")))) - (add-to-list 'tramp-methods - `(,tramp-toolbox-method - (tramp-login-program ,tramp-toolbox-program) - (tramp-login-args (("run") - ("-c" "%h") - ("%l"))) - (tramp-direct-async (,tramp-default-remote-shell "-c")) - (tramp-remote-shell ,tramp-default-remote-shell) - (tramp-remote-shell-login ("-l")) - (tramp-remote-shell-args ("-c")))) - - (add-to-list 'tramp-default-host-alist `(,tramp-toolbox-method nil "")) - - (add-to-list 'tramp-methods - `(,tramp-flatpak-method - (tramp-login-program ,tramp-flatpak-program) - (tramp-login-args (("enter") - ("%h") - ("%l"))) - (tramp-direct-async (,tramp-default-remote-shell "-c")) - (tramp-remote-shell ,tramp-default-remote-shell) - (tramp-remote-shell-login ("-l")) - (tramp-remote-shell-args ("-c")))) + (add-to-list 'tramp-completion-multi-hop-methods tramp-docker-method) + (add-to-list 'tramp-completion-multi-hop-methods tramp-podman-method) + (add-to-list 'tramp-completion-multi-hop-methods tramp-kubernetes-method) (tramp-set-completion-function tramp-docker-method @@ -495,53 +518,99 @@ see its function help for a description of the format." (tramp-set-completion-function tramp-kubernetes-method - `((tramp-kubernetes--completion-function ,tramp-kubernetes-method))) + `((tramp-kubernetes--completion-function ,tramp-kubernetes-method)))) - (tramp-set-completion-function - tramp-toolbox-method - `((tramp-toolbox--completion-function ,tramp-toolbox-method))) +;;;###tramp-autoload +(defun tramp-enable-toolbox-method () + "Enable connection to Toolbox containers." + (add-to-list 'tramp-methods + `(,tramp-toolbox-method + (tramp-login-program ,tramp-toolbox-program) + (tramp-login-args (("run") + ("-c" "%h") + ("%l"))) + (tramp-direct-async (,tramp-default-remote-shell "-c")) + (tramp-remote-shell ,tramp-default-remote-shell) + (tramp-remote-shell-login ("-l")) + (tramp-remote-shell-args ("-c")))) + + (add-to-list 'tramp-default-host-alist `(,tramp-toolbox-method nil "")) + (add-to-list 'tramp-completion-multi-hop-methods tramp-toolbox-method) + + (tramp-set-completion-function + tramp-toolbox-method + `((tramp-toolbox--completion-function ,tramp-toolbox-method)))) - (tramp-set-completion-function - tramp-flatpak-method - `((tramp-flatpak--completion-function ,tramp-flatpak-method))) +;;;###tramp-autoload +(defun tramp-enable-flatpak-method () + "Enable connection to Flatpak sandboxes." + (add-to-list 'tramp-methods + `(,tramp-flatpak-method + (tramp-login-program ,tramp-flatpak-program) + (tramp-login-args (("enter") + ("%h") + ("%l"))) + (tramp-direct-async (,tramp-default-remote-shell "-c")) + (tramp-remote-shell ,tramp-default-remote-shell) + (tramp-remote-shell-login ("-l")) + (tramp-remote-shell-args ("-c")))) + + (add-to-list 'tramp-completion-multi-hop-methods tramp-flatpak-method) + + (tramp-set-completion-function + tramp-flatpak-method + `((tramp-flatpak--completion-function ,tramp-flatpak-method)))) - (add-to-list 'tramp-completion-multi-hop-methods tramp-docker-method) - (add-to-list 'tramp-completion-multi-hop-methods tramp-podman-method) - (add-to-list 'tramp-completion-multi-hop-methods tramp-kubernetes-method) - (add-to-list 'tramp-completion-multi-hop-methods tramp-toolbox-method) - (add-to-list 'tramp-completion-multi-hop-methods tramp-flatpak-method) - - ;; Default connection-local variables for Tramp. - - (defconst tramp-kubernetes-connection-local-default-variables - '((tramp-config-check . tramp-kubernetes--current-context-data) - ;; This variable will be eval'ed in `tramp-expand-args'. - (tramp-extra-expand-args - . (?a (tramp-kubernetes--container (car tramp-current-connection)) - ?h (tramp-kubernetes--pod (car tramp-current-connection)) - ?x (tramp-kubernetes--context-namespace - (car tramp-current-connection))))) - "Default connection-local variables for remote kubernetes connections.") - - (connection-local-set-profile-variables - 'tramp-kubernetes-connection-local-default-profile - tramp-kubernetes-connection-local-default-variables) - - (connection-local-set-profiles - `(:application tramp :protocol ,tramp-kubernetes-method) - 'tramp-kubernetes-connection-local-default-profile) - - (defconst tramp-flatpak-connection-local-default-variables - `((tramp-remote-path . ,(cons "/app/bin" tramp-remote-path))) - "Default connection-local variables for remote flatpak connections.") - - (connection-local-set-profile-variables - 'tramp-flatpak-connection-local-default-profile - tramp-flatpak-connection-local-default-variables) - - (connection-local-set-profiles - `(:application tramp :protocol ,tramp-flatpak-method) - 'tramp-flatpak-connection-local-default-profile)) +;;;###tramp-autoload +(defun tramp-enable-apptainer-method () + "Enable connection to Apptainer instances." + (add-to-list 'tramp-methods + `(,tramp-apptainer-method + (tramp-login-program ,tramp-apptainer-program) + (tramp-login-args (("shell") + ("instance://%h") + ("%h"))) ; Needed for multi-hop check. + (tramp-remote-shell ,tramp-default-remote-shell) + (tramp-remote-shell-login ("-l")) + (tramp-remote-shell-args ("-c")))) + + (add-to-list 'tramp-completion-multi-hop-methods tramp-apptainer-method) + + (tramp-set-completion-function + tramp-apptainer-method + `((tramp-apptainer--completion-function ,tramp-apptainer-method)))) + +;; Default connection-local variables for Tramp. + +(defconst tramp-kubernetes-connection-local-default-variables + '((tramp-config-check . tramp-kubernetes--current-context-data) + ;; This variable will be eval'ed in `tramp-expand-args'. + (tramp-extra-expand-args + . (?a (tramp-kubernetes--container (car tramp-current-connection)) + ?h (tramp-kubernetes--pod (car tramp-current-connection)) + ?x (tramp-kubernetes--context-namespace + (car tramp-current-connection))))) + "Default connection-local variables for remote kubernetes connections.") + +(connection-local-set-profile-variables + 'tramp-kubernetes-connection-local-default-profile + tramp-kubernetes-connection-local-default-variables) + +(connection-local-set-profiles + `(:application tramp :protocol ,tramp-kubernetes-method) + 'tramp-kubernetes-connection-local-default-profile) + +(defconst tramp-flatpak-connection-local-default-variables + `((tramp-remote-path . ,(cons "/app/bin" tramp-remote-path))) + "Default connection-local variables for remote flatpak connections.") + +(connection-local-set-profile-variables + 'tramp-flatpak-connection-local-default-profile + tramp-flatpak-connection-local-default-variables) + +(connection-local-set-profiles + `(:application tramp :protocol ,tramp-flatpak-method) + 'tramp-flatpak-connection-local-default-profile) (add-hook 'tramp-unload-hook (lambda () diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el index 4c62d1d9f39..f6d02847927 100644 --- a/lisp/net/tramp.el +++ b/lisp/net/tramp.el @@ -1460,6 +1460,15 @@ calling HANDLER.") ;;; Internal functions which must come first: +(defun tramp-enable-method (method) + "Enable optional METHOD if possible." + (interactive "Mmethod: ") + (when-let (((not (assoc method tramp-methods))) + (fn (intern (format "tramp-enable-%s-method" method))) + ((functionp fn))) + (funcall fn) + (message "Tramp method \"%s\" enabled" method))) + ;; Conversion functions between external representation and ;; internal data structure. Convenience functions for internal ;; data structure. |