[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Async Python src block behavior with :dir header property
From: |
Jack Kamm |
Subject: |
Re: Async Python src block behavior with :dir header property |
Date: |
Wed, 31 Jan 2024 20:16:51 -0800 |
Ihor Radchenko <yantar92@posteo.net> writes:
> [ CCing ob-python maintainer ]
>
> Nasser Alkmim <nasser.alkmim@gmail.com> writes:
>
>> Here is a clearer description of the unwanted behavior:
>>
>> 1. emacs -Q ~/Desktop/testasync.org
>>
>> Then evaluate (require 'ob-python) and paste this source block:
>>
>> #+begin_src python :dir otherdir :async yes :session pysession :return
>> figname :results file value :mkdirp yes
>> import matplotlib.pyplot as plt
>> plt.figure(figsize=(1, 1))
>> plt.plot([1, 2])
>> figname = 'fig.svg'
>> plt.savefig(figname)
>> #+end_src
>>
>> Execute the source block, which results in
>>
>> #+RESULTS:
>> [[file:fig.svg]]
>
> I don't even see this.
> Confirmed.
Does the attached patch fix the issue?
It seems the problem is with async sessions generally (not just
ob-python), and happens because `org-babel-comint-async-filter' does not
set `default-directory' before calling `org-babel-insert-result', unlike
`org-babel-execute-src-block'.
>From 1430a27e4416d5e88094a64360015a6a2ae7315c Mon Sep 17 00:00:00 2001
From: Jack Kamm <jackkamm@gmail.com>
Date: Wed, 31 Jan 2024 20:06:00 -0800
Subject: [PATCH] ob-comint: Make file results from async sessions respect :dir
header
* lisp/ob-comint.el (org-babel-comint-async-filter): Set
default-directory before calling `org-babel-insert-result'
https://list.orgmode.org/875xz9o4nj.fsf@localhost/T/#t
---
lisp/ob-comint.el | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)
diff --git a/lisp/ob-comint.el b/lisp/ob-comint.el
index 7d258ea0e..ecce18a95 100644
--- a/lisp/ob-comint.el
+++ b/lisp/ob-comint.el
@@ -248,7 +248,14 @@ (defun org-babel-comint-async-filter (string)
(let* ((info (org-babel-get-src-block-info))
(params (nth 2 info))
(result-params
- (cdr (assq :result-params params))))
+ (cdr (assq :result-params params)))
+ (tmp-file (expand-file-name tmp-file))
+ (dir (cdr (assq :dir params)))
+ (default-directory
+ (if dir
+ (file-name-as-directory
+ (expand-file-name dir))
+ default-directory)))
(org-babel-insert-result
(funcall file-callback
(nth
@@ -291,7 +298,13 @@ (defun org-babel-comint-async-filter (string)
(let* ((info (org-babel-get-src-block-info))
(params (nth 2 info))
(result-params
- (cdr (assq :result-params params))))
+ (cdr (assq :result-params params)))
+ (dir (cdr (assq :dir params)))
+ (default-directory
+ (if dir
+ (file-name-as-directory
+ (expand-file-name dir))
+ default-directory)))
(org-babel-insert-result
res-str result-params info))
t))))
--
2.43.0