GNU bug report logs -
#79413
[PATCH] Fix path and environment in remote Python shell
Previous Next
Full log
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Tags: patch
Options such as python-shell-exec-path and
python-shell-process-environment may not be applied for remote Python
shell:
(1) create a python virtual environment on the remote host:
$ python3 -m venv /tmp/test_venv
(2) emacs -Q and then eval the following code:
--8<---------------cut here---------------start------------->8---
(require 'python)
(require 'tramp)
(setq remote-dir "/ssh:<remote>:~/")
;; use the remote virtual environment by setting
;; python-shell-exec-path, python-shell-remote-exec-path, or
;; python-shell-virtualenv-root
(setq python-shell-exec-path (list "/tmp/test_venv/bin"))
;; set environment variables for remote Python process
(setq python-shell-process-environment '("FOO=1"))
;; python-shell-process-environment is not applied remotely when
;; connection-local tramp-remote-process-environment is used
(connection-local-set-profile-variables
'test
`((tramp-remote-process-environment
. ,(append
'("BAR=bar")
tramp-remote-process-environment))))
(connection-local-set-profiles
`(:application tramp :machine ,(file-remote-p remote-dir 'host))
'test)
(find-file remote-dir)
--8<---------------cut here---------------end--------------->8---
(3) M-x run-python
(4) type 'import sys; sys.executable' in the remote python shell
The expected output is '/tmp/test_venv/bin/python', but the actual
output is '/bin/python'.
In emacs 30 and earlier version, the result is correct, with a side
effect that the remote path is changed globally, i.e. (exec-path) in
other remote buffers also contains "/tmp/test_venv/bin".
(5) type 'import os; os.environ.get("FOO")' in the python shell
The result should be '1', but there is no output.
This patch fixes python-shell--tramp-with-environment and adds tests.
The python-tests-remote-path-1 test needs a real ssh remote connection
like REMOTE_TEMPORARY_FILE_DIRECTORY=/ssh:remote:/tmp/.
There is still a corner case: if python-shell-process-environment
contains an environment variable that already exists in the default
process-environment, the environment variable is not applied by tramp
for the remote Python shell. For example, the following test fails:
FOO=1 REMOTE_TEMPORARY_FILE_DIRECTORY=/ssh:remote:/tmp/ \
make python-tests SELECTOR='"python-tests-remote-env"'
where FOO=1 is in both python-shell-process-environment and default
process-environment. This issue may need to be addressed in tramp.
[0001-Fix-path-and-environment-in-remote-Python-shell.patch (text/patch, attachment)]
This bug report was last modified 2 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.