Skip to content

Commit 113acb2

Browse files
committed
Use default-directory as :dir when executing a source block
`default-directory` is already set according to :dir when executing a source block. This prevents `org-babel-expand-body:jupyter` from attempting to re-expand the value of the :dir header argument. See #302.
1 parent db450a9 commit 113acb2

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

ob-jupyter.el

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,15 @@ the PARAMS alist."
473473
(jupyter-current-client (buffer-local-value 'jupyter-current-client buf))
474474
(lang (jupyter-kernel-language jupyter-current-client))
475475
(vars (org-babel-variable-assignments:jupyter params lang))
476-
(code (org-babel-expand-body:jupyter body params vars lang)))
476+
(code (progn
477+
(when-let* ((dir (alist-get :dir params)))
478+
;; `default-directory' is already set according
479+
;; to :dir when executing a source block. Set
480+
;; :dir to the absolute path so that
481+
;; `org-babel-expand-body:jupyter' does not try
482+
;; to re-expand the path. See #302.
483+
(setf (alist-get :dir params) default-directory))
484+
(org-babel-expand-body:jupyter body params vars lang))))
477485
(pcase-let ((`(,req ,maybe-result)
478486
(org-babel-jupyter--execute code async-p)))
479487
;; KLUDGE: Remove the file result-parameter so that

test/jupyter-test.el

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2862,7 +2862,18 @@ os.path.abspath(os.getcwd())"
28622862
;; See #302
28632863
(jupyter-org-test-src-block
28642864
"print(r\"\\r\")"
2865-
": \\r\n")))))
2865+
": \\r\n")))
2866+
(ert-info ("Relative directory")
2867+
;; See #302
2868+
(let* ((temporary-file-directory jupyter-test-temporary-directory)
2869+
(dir (make-temp-file "dir-header-arg" t)))
2870+
;; FIXME: Don't use an internal function here.
2871+
(jupyter-org-test
2872+
(let ((default-directory (file-name-directory dir)))
2873+
(jupyter-org-test-src-block-1
2874+
"print(\"hi\")"
2875+
": hi\n" nil
2876+
`((:dir . ,(file-name-base dir))))))))))
28662877

28672878
(ert-deftest jupyter-org--find-mime-types ()
28682879
:tags '(org mime)

0 commit comments

Comments
 (0)