emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Async Python src block behavior with :dir header property
@ 2024-01-31  7:29 Nasser Alkmim
  2024-01-31 11:23 ` Ihor Radchenko
  0 siblings, 1 reply; 24+ messages in thread
From: Nasser Alkmim @ 2024-01-31  7:29 UTC (permalink / raw)
  To: emacs-orgmode

Hi,

I'm in the latest Emacs GUI.
This works, the =return figname= apparently can recognizee that we are in the =:dir=.

#+begin_src python :dir asyncpy :return figname :results file value
import matplotlib.pyplot as plt
plt.figure(figsize=(4*.5, 3*.5))
plt.plot([1, 2])
figname = 'fig.svg'
plt.savefig(figname, transparent=True, bbox_inches='tight')
#+end_src


This does not work.
Even though the python execution is in the right directory and the file is saved correctly.
The =return= does not produces the right file path considering the directory.

#+begin_src python :dir asyncpy :async :session :return figname :results file value
import matplotlib.pyplot as plt
plt.figure(figsize=(4*.5, 3*.5))
plt.plot([1, 2])
figname = 'fig.svg'
plt.savefig(figname, transparent=True, bbox_inches='tight')
#+end_src

If we inform the right path to the return statement, it works.

#+begin_src python :dir asyncpy :async :session :epilogue figdir='asyncpy/'+figname :return figdir :results file value
import matplotlib.pyplot as plt
plt.figure(figsize=(4*.5, 3*.5))
plt.plot([1, 2])
figname = 'fig.svg'
plt.savefig(figname, transparent=True, bbox_inches='tight')
#+end_src

Another alternative, we can use the =os= package to get the current directory.

#+header: :epilogue import os;figdir=os.getcwd()+'/'+figname 
#+begin_src python :dir asyncpy :async :session :return figdir :results file value
import matplotlib.pyplot as plt
plt.figure(figsize=(4*.5, 3*.5))
plt.plot([1, 2])
figname = 'fig.svg'
plt.savefig(figname, transparent=True, bbox_inches='tight')
#+end_src

Is this behavior as expected?
Is there a better way to have the figures from the python block with async execution?

-- 
Nasser Alkmim 
 +43 677 6408 9171


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

end of thread, other threads:[~2024-02-13 14:27 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-31  7:29 Async Python src block behavior with :dir header property Nasser Alkmim
2024-01-31 11:23 ` Ihor Radchenko
2024-01-31 12:17   ` Nasser Alkmim
2024-01-31 12:47     ` Ihor Radchenko
2024-01-31 15:00       ` Nasser Alkmim
2024-01-31 16:21         ` Ihor Radchenko
2024-02-01  4:16           ` Jack Kamm
2024-02-01  8:40             ` Nasser Alkmim
2024-02-01 11:59             ` Ihor Radchenko
2024-02-03  1:20               ` Jack Kamm
2024-02-03 15:51                 ` Ihor Radchenko
2024-02-04  1:26                   ` Jack Kamm
2024-02-04 16:30                     ` Ihor Radchenko
2024-02-05  0:59                       ` Jack Kamm
2024-02-05 14:10                         ` Ihor Radchenko
2024-02-06  6:56                           ` Jack Kamm
2024-02-06 14:06                             ` Ihor Radchenko
2024-02-08  3:08                               ` Jack Kamm
2024-02-08 15:43                                 ` Ihor Radchenko
2024-02-08 17:46                                   ` Bruno Barbier
2024-02-10 18:14                                   ` Jack Kamm
2024-02-10 21:01                                     ` Ihor Radchenko
2024-02-13  9:43                                       ` Nasser Alkmim
2024-02-13 14:31                                         ` 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).