Skip to content

Commit bead751

Browse files
committed
le-python.el: Send the middleware base64 encoded to remote sessions
1 parent dc99369 commit bead751

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

le-python.el

+24-8
Original file line numberDiff line numberDiff line change
@@ -1023,18 +1023,34 @@ Otherwise, fall back to Jedi (static)."
10231023
(setq lispy--python-middleware-loaded-p nil)
10241024
(lispy--python-middleware-load))
10251025

1026+
(defun lispy--python-slurp (f)
1027+
(with-temp-buffer
1028+
(insert-file-contents f)
1029+
(buffer-string)))
1030+
1031+
(defun lispy--python-setup-cmd ()
1032+
(concat
1033+
"from importlib.machinery import SourceFileLoader;"
1034+
(format "lp=SourceFileLoader('lispy-python', '%s').load_module();"
1035+
lispy--python-middleware-file)
1036+
(format "lp.setup('%s')" lispy--python-init-file)))
1037+
10261038
(defun lispy--python-middleware-load ()
10271039
"Load the custom Python code in \"lispy-python.py\"."
10281040
(unless lispy--python-middleware-loaded-p
1029-
(let ((default-directory (or (locate-dominating-file default-directory ".git")
1030-
default-directory)))
1041+
(let* ((default-directory (or (locate-dominating-file default-directory ".git")
1042+
default-directory))
1043+
out)
10311044
;; send single line so that python.el does no /tmp/*.py magic, which does not work in Docker
1032-
(lispy--eval-python-plain
1033-
(concat
1034-
"from importlib.machinery import SourceFileLoader;"
1035-
(format "lp=SourceFileLoader('lispy-python', '%s').load_module();"
1036-
lispy--python-middleware-file)
1037-
(format "lp.setup('%s')" lispy--python-init-file)))
1045+
(setq out (lispy--eval-python-plain (lispy--python-setup-cmd)))
1046+
(when (string-match "FileNotFoundError" out)
1047+
(let* ((text (lispy--python-slurp lispy--python-middleware-file))
1048+
(ben (replace-regexp-in-string "\n" "" (base64-encode-string text)))
1049+
(setup-cmd (let ((lispy--python-middleware-file "/tmp/lispy.py"))
1050+
(lispy--python-setup-cmd))))
1051+
(lispy--eval-python-plain
1052+
(format "import base64; open('/tmp/lispy.py','w').write(base64.b64decode('%s').decode()); %s"
1053+
ben setup-cmd))))
10381054
(setq lispy--python-middleware-loaded-p t))))
10391055

10401056
(defun lispy--python-arglist (symbol filename line column)

0 commit comments

Comments
 (0)