-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tramp support? #30
Comments
@mtekman that's certainly an interesting idea, although I'm personally not sure what you would want to use it for remotely. When you activate a conda environment remotely, all of the functionality you might get from it (e.g. interactive Python REPL, documentation & IDE support) would have to be sent to / from the server, which doesn't sound very appealing to me. Can you share some more about your use case, so I can understand better what functionality you'd like to have over the remote connection? |
@necaris When debugging an R script via ESS-mode (which works in TRAMP) the mode defaults to using the default path, which does not contain the conda packages I need to properly debug the script. |
@mtekman thank you for the clarification! I don't know ESS personally, but from a quick search it seems like when running ESS over Tramp, Emacs is connecting to a remote R process via SSH, rather than running shell commands on the remote server? |
@necaris By my understanding, it spawns an R process over SSH on the remote server, and all local instructions are transferred to and then executed on the remote server, and then the results are transported back to the local machine. Controlling what conda environment the Edit: Corrected machine |
@mtekman now I'm confused. Do you need to have the conda environments on the remote machine, where the script is running, or the local machine where you might want to debug the results? The way it works right now, using the appropriate conda environment locally should be as easy as calling However, I'm not sure how to start telling Emacs / ESS-mode how to activate the conda environment on the remote machine... |
Apologies, on the remote machine. |
Interestered for this feature too. It could be a great improvment :) |
Also interested in this. I'm envisioning activating a conda env on a remote machine so that I can use a remote python language server with lsp-mode, and that path variables would be correct. |
I was poking through the source a few days ago, and one issue is that the current package looks for a specific conda installation directory: (defcustom conda-env-home-directory "~/anaconda"
"Location of the directory containing the environments directory."
:type 'directory
:group 'conda) Given that different remote machines are configured differently, there is no catch-all solution to setting this for hosts, unless the user sets this for all their hosts: (defcustom conda-env-home-directory
'((home . "~/anaconda") (remote1 . "~/miniconda") (remote2 . "~/miniconda3"))
"Alist of locations containing the environments directory."
:type 'alist
:group 'conda) Either the package looks in all these locations for an |
@jsigman just for clarification, you're saying you'd like to activate the conda environment and run the language server all on the remote machine, and communicate with it from your local Emacs? This seems similar to @mtekman's use case of wanting to run exclusively remote commands -- so we're basically saying that all of the "conda activate" (etc) commands we need to run have to run on the remote end of a specific TRAMP connection? I'm wondering if we can use something like the solution described here to activate an environment when the TRAMP connection is established, and otherwise use builtin Emacs methods for running commands within the ( |
lsp and the python-shell-interpreter already work with tramp when ;; remove "/ssh:host:" from conda dir
(setq conda-tramp-path (replace-regexp-in-string ".*:" ""
(format "%s/bin" conda-env-current-dir)))
(add-to-list 'tramp-remote-path conda-tramp-path)
(add-to-list 'tramp-remote-path 'tramp-own-remote-path) ;; for some strange emacs reason this has to be added, otherwise tramp-remote-path is ignored ( So the functionality, that would have to be added, is:
I don't know about all the other functionality though, e.g., eshell ... |
@necaris You are understanding correctly, and I would love to try to help with this. For me, it's about getting lsp-mode to work on a restrictive server. I might try to catch up on this package some more this weekend. |
@fcupo thank you for doing all that research! So it looks like we need to:
|
Anyone still interested in helping with this? |
@necaris Looks like it's been a minute since there was some discussion on this, but I'm chiming in to say I have the exact same use case as @jsigman, and came across this thread looking for solutions. No promises at the moment, but assuming I find some time and have strong enough emacs-fu I'd love to help out |
@renzmann let me know if you need any help! |
Hey @necaris! Before I tried to change up too many things I thought I'd take down some notes for potential discussion. I think the main barrier to TRAMP right now would be the caching mechanism, like when we poll for Lines 116 to 122 in cb9544e
This setup assumes a pretty different working model than how I and some of the users above would be using conda, which would have a different executable path to ;; Made up executable paths
(setq conda--executable-path-alist
'(("/ssh:my-host:" . "/usr/local/bin/conda")
("/ssh:another-host:" . "~/.conda/bin/conda")
(nil . "/opt/conda/bin/conda")) I think we can reliably get the different hostnames via (defun conda--get-executable-path ()
;; caching steps omitted for brevity
(cond
((executable-find "conda" 'remote))
((executable-find "mamba" 'remote)))) With that step out of the way, I think it's then a matter of patching variables with the correct connection/host component to get the downstream components working, as mentioned above. |
@renzmann that all seems sensible to me! The main concern I have is that it shouldn't require any extra work for the common case of a local environment 😄 |
Hi, I'm an elisp beginner so unfortunately this isn't much of a contribution towards a robust solution of this issue in the package, but I wanted to put my workaround here for anyone else who happens to come here needing one. (with thanks to @f-kretschmer for their comment here a few years back) I haven't tested this extensively with eglot, etc, my only use-case is to be able to execute org-mode src blocks in the correct remote environment, and it works for that. I think it's using the remote language server for eglot too but I'm not entirely sure to easily tell if that's the case. Maybe it will work for the other stuff too. (setq remote-conda-anaconda-home-list
'(("remote01" "/ssh:me@remote01:/home/me/conda/special_conda")
("remote02" "/ssh:me@remote02:/home/me/miniforge3")))
(setq remote-conda-env-home-directory-list
'(("remote01" "/ssh:me@remote01:/home/me/conda/special_conda")
("remote02" "/ssh:me@remote02:/home/me/miniforge3")))
(setq remote-conda-env-subdirectory-list
'(("remote01" "envs")
("remote02" "envs")))
(defun conda-tramp-activate (conda-env)
"Activate a conda environment on a remote host."
(interactive "sConda environment: ")
(let ((hostname (file-remote-p default-directory 'host)))
(setq conda-anaconda-home (cadr (assoc hostname remote-conda-anaconda-home-list)))
(setq conda-env-home-directory (cadr (assoc hostname remote-conda-env-home-directory-list)))
(setq conda-env-subdirectory (cadr (assoc hostname remote-conda-env-subdirectory-list)))
;; check if dir conda-env exists in conda-env-home-directory/conda-env-subdirectory
(if (not (file-exists-p (f-join conda-env-home-directory conda-env-subdirectory conda-env)))
(error "Conda environment %s does not exist on remote host %s" conda-env hostname))
(setq conda-env-current-path (f-join conda-anaconda-home conda-env-subdirectory conda-env))
(setq conda-tramp-path (replace-regexp-in-string ".*:" ""
(format "%s/bin" conda-env-current-path)))
(add-to-list 'tramp-remote-path 'tramp-own-remote-path) ;; need to do this BEFORE the next line or else python won't find the right remote env and will just use the base env
(add-to-list 'tramp-remote-path conda-tramp-path)
(tramp-cleanup-this-connection))
) |
Is there any interest in getting this to work on remote machines via TRAMP?
I find that "conda-env-list" does not produce any output
The text was updated successfully, but these errors were encountered: