Skip to content

Commit ee5e991

Browse files
committed
Set pythonpath process property for remote processes.
1 parent 17f4796 commit ee5e991

File tree

2 files changed

+41
-16
lines changed

2 files changed

+41
-16
lines changed

pythonic.el

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,12 @@ It will use `python-shell-exec-path' for PATH variable,
9090
(pythonic-set-path-variable)
9191
(pythonic-set-extra-variables)))
9292

93+
(defun pythonic-get-pythonpath ()
94+
"Get appropriate PYTHONPATH variable for pythonic process."
95+
(if (pythonic-remote-p)
96+
(pythonic-get-pythonpath-variable-tramp)
97+
(pythonic-get-pythonpath-variable)))
98+
9399
(defun pythonic-get-pythonpath-variable ()
94100
"Get PYTHONPATH variable from `python-shell-extra-pythonpaths' variable."
95101
(s-join path-separator
@@ -99,26 +105,30 @@ It will use `python-shell-exec-path' for PATH variable,
99105
(-remove 's-blank?)
100106
(-distinct))))
101107

108+
(defun pythonic-get-pythonpath-variable-tramp ()
109+
"Get PYTHONPATH variable form `python-shell-extra-pythonpaths' on the remote host."
110+
(let ((connection (tramp-dissect-file-name (pythonic-tramp-connection))))
111+
(s-join path-separator
112+
(--> (progn
113+
(tramp-send-command connection "echo $PYTHONPATH")
114+
(with-current-buffer (tramp-get-connection-buffer connection)
115+
(buffer-string)))
116+
(s-trim it)
117+
(s-split ":" it t)
118+
(--remove (member it python-shell-extra-pythonpaths) it)
119+
(append python-shell-extra-pythonpaths it)))))
120+
102121
(defun pythonic-set-pythonpath-variable ()
103122
"Set PYTHONPATH variable from `python-shell-extra-pythonpaths' variable."
104123
(setenv "PYTHONPATH" (pythonic-get-pythonpath-variable)))
105124

106125
(defun pythonic-set-pythonpath-variable-tramp ()
107126
"Set PYTHONPATH variable from `python-shell-extra-pythonpaths' variable on remote host."
108-
(let ((connection (tramp-dissect-file-name (pythonic-tramp-connection))))
109-
(tramp-send-command
110-
connection
111-
(format
112-
"export PYTHONPATH=%s"
113-
(s-join ":"
114-
(--> (progn
115-
(tramp-send-command connection "echo $PYTHONPATH")
116-
(with-current-buffer (tramp-get-connection-buffer connection)
117-
(buffer-string)))
118-
(s-trim it)
119-
(s-split ":" it t)
120-
(--remove (member it python-shell-extra-pythonpaths) it)
121-
(append python-shell-extra-pythonpaths it)))))))
127+
(tramp-send-command
128+
(tramp-dissect-file-name (pythonic-tramp-connection))
129+
(format
130+
"export PYTHONPATH=%s"
131+
(pythonic-get-pythonpath-variable-tramp))))
122132

123133
(defun pythonic-get-path ()
124134
"Return appropriate PATH variable for pythonic process."
@@ -199,7 +209,7 @@ process flag."
199209
(process-put process 'default-directory default-directory)
200210
(process-put process 'environment python-shell-process-environment)
201211
(process-put process 'path (pythonic-get-path))
202-
(process-put process 'pythonpath (pythonic-get-pythonpath-variable))
212+
(process-put process 'pythonpath (pythonic-get-pythonpath))
203213
process)))
204214

205215
;;;###autoload

test/pythonic-test.el

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,6 @@ remote host."
320320
"Set `python-shell-exec-path' as `path' process property on remote process."
321321
(unwind-protect
322322
(let* ((python-shell-interpreter "/ssh:test@localhost:/path/to/the/python")
323-
(home (f-expand "~"))
324323
(python-shell-exec-path '("/home/test/bin")))
325324
(should (equal "/home/test/bin:/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
326325
(process-get
@@ -340,6 +339,22 @@ remote host."
340339
(start-pythonic :process "out" :args '("-V"))
341340
'pythonpath)))))
342341

342+
(ert-deftest test-start-pythonic-pythonpath-property-tramp ()
343+
"Set `python-shell-extra-pythonpaths' as `pythonpath' process property on remote host.
344+
Respect remote PYTHONPATH value."
345+
(unwind-protect
346+
(let* ((python-shell-interpreter "/ssh:test@localhost:/path/to/the/python")
347+
(python-shell-extra-pythonpaths '("/home/test/modules")))
348+
(tramp-send-command ["ssh" "test" "localhost" "" nil]
349+
"export PYTHONPATH=/home/me/modules")
350+
(should (equal "/home/test/modules:/home/me/modules"
351+
(process-get
352+
(start-pythonic :process "out" :args '("-V"))
353+
'pythonpath))))
354+
(kill-buffer "*tramp/ssh test@localhost*")
355+
(setq tramp-current-connection)
356+
(sleep-for 0.5)))
357+
343358
(ert-deftest test-start-pythonic-default-directory-property ()
344359
"Set `pythonic-default-directory' result as `default-directory' process property."
345360
(let ((default-directorys "~"))

0 commit comments

Comments
 (0)