emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [BUG] org babel python execute from local buffer to remote session [9.5.4 (9.5.4-ge0b05b @ /home/moutsopoulosg/.emacs.d/elpa/org-9.5.4/)]
       [not found] <CABU1Ay-kU+SkJ2iCu-00XhSmtk7PahsMFM_uWknnx7tW-fLD6A.ref@mail.gmail.com>
@ 2022-08-26  8:58 ` George Moutsopoulos
  2022-08-27  3:05   ` Tim Cross
  2022-08-28  4:13   ` Ihor Radchenko
  0 siblings, 2 replies; 3+ messages in thread
From: George Moutsopoulos @ 2022-08-26  8:58 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 1323 bytes --]

Hi all. I often need to run some code on a remote ssh session, because
only there I can access a database and the environment is hard to
replicate, while I want to keep the code I run on my local machine.

The remote session is initialised with run-python after I change
default-directory and use pythonic-activate. Sending commands from a
local python buffer using python.el works without issues. It would be nice
if I can do
the same from a local org-mode buffer from a python source block.

It does not work because org-babel-python-evaluate-session has two
org-babel-temp-file commands that run in the context of the local
buffer. If I replace them with
(let* ((tmp-src-file (with-current-buffer session (org-babel-temp-file
"python-"))) ...) ...)
and
(let* ((tmp-results-file (with-current-buffer session
(org-babel-temp-file "python-"))) ...) ...)
then executing the code works again. I have also changed similarly
org-babel-python-async-evaluate-session
although I haven't tested async.

I am hoping this is a change worth making at source, or maybe there is
a better way to achieve the same.

Thank you.


Emacs  : GNU Emacs 28.1 (build 2, x86_64-pc-linux-gnu, GTK+ Version
3.24.20, cairo version 1.16.0)
 of 2022-06-24
Package: Org mode version 9.5.4 (9.5.4-ge0b05b @
/home/moutsopoulosg/.emacs.d/elpa/org-9.5.4/)

[-- Attachment #2: Type: text/html, Size: 1462 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [BUG] org babel python execute from local buffer to remote session [9.5.4 (9.5.4-ge0b05b @ /home/moutsopoulosg/.emacs.d/elpa/org-9.5.4/)]
  2022-08-26  8:58 ` [BUG] org babel python execute from local buffer to remote session [9.5.4 (9.5.4-ge0b05b @ /home/moutsopoulosg/.emacs.d/elpa/org-9.5.4/)] George Moutsopoulos
@ 2022-08-27  3:05   ` Tim Cross
  2022-08-28  4:13   ` Ihor Radchenko
  1 sibling, 0 replies; 3+ messages in thread
From: Tim Cross @ 2022-08-27  3:05 UTC (permalink / raw)
  To: George Moutsopoulos; +Cc: emacs-orgmode


George Moutsopoulos <gmoutso@yahoo.co.uk> writes:

> Hi all. I often need to run some code on a remote ssh session, because
> only there I can access a database and the environment is hard to
> replicate, while I want to keep the code I run on my local machine.
>
> The remote session is initialised with run-python after I change
> default-directory and use pythonic-activate. Sending commands from a
> local python buffer using python.el works without issues. It would be nice if I can do
> the same from a local org-mode buffer from a python source block.
>

Jujst in case it may be useful, I have found it easiest to use ssh
tunnels in this sort of scenario. If you create an ssh tunnel for the
port you connect to the database with, you can access the database as if
it was running locally.

One advantage of this method is that you can use all the normal tools
and any language, your not restricted to python. I find this useful as
it allows me to use org-mode to manage my database using just sql as
well as using other languages (I don't use python, preferring other
scripting languages, but same basic principals). I mainly use postgres
and with the ssh tunnel approach, I can run the postgres clients locally
and have them connect to remote databases which would normally not be
possible due to firewalls etc. I've done the same with Oracle and
suspect most other dbms would work (as well as other 'services',
provided there is a tcp socket).

The other advantage is that it avoids the need to modify org mode (or
any other tool). You can even use the full power of Emacs' sql mode.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [BUG] org babel python execute from local buffer to remote session [9.5.4 (9.5.4-ge0b05b @ /home/moutsopoulosg/.emacs.d/elpa/org-9.5.4/)]
  2022-08-26  8:58 ` [BUG] org babel python execute from local buffer to remote session [9.5.4 (9.5.4-ge0b05b @ /home/moutsopoulosg/.emacs.d/elpa/org-9.5.4/)] George Moutsopoulos
  2022-08-27  3:05   ` Tim Cross
@ 2022-08-28  4:13   ` Ihor Radchenko
  1 sibling, 0 replies; 3+ messages in thread
From: Ihor Radchenko @ 2022-08-28  4:13 UTC (permalink / raw)
  To: George Moutsopoulos; +Cc: emacs-orgmode

George Moutsopoulos <gmoutso@yahoo.co.uk> writes:

> Hi all. I often need to run some code on a remote ssh session, because
> only there I can access a database and the environment is hard to
> replicate, while I want to keep the code I run on my local machine.
>
> The remote session is initialised with run-python after I change
> default-directory and use pythonic-activate. Sending commands from a
> local python buffer using python.el works without issues. It would be nice
> if I can do
> the same from a local org-mode buffer from a python source block.

Could you please elaborate how you change the default-directory?
The canonical way to tell Org babel which directory to use is :dir
header argument. AFAIK, python process and files should all be created
in the right context then.

-- 
Ihor Radchenko,
Org mode contributor,
Learn more about Org mode at https://orgmode.org/.
Support Org development at https://liberapay.com/org-mode,
or support my work at https://liberapay.com/yantar92


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-08-28  4:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <CABU1Ay-kU+SkJ2iCu-00XhSmtk7PahsMFM_uWknnx7tW-fLD6A.ref@mail.gmail.com>
2022-08-26  8:58 ` [BUG] org babel python execute from local buffer to remote session [9.5.4 (9.5.4-ge0b05b @ /home/moutsopoulosg/.emacs.d/elpa/org-9.5.4/)] George Moutsopoulos
2022-08-27  3:05   ` Tim Cross
2022-08-28  4:13   ` Ihor Radchenko

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).