From 113acb239d9e300a459be46be313f1fc4a264023 Mon Sep 17 00:00:00 2001 From: Nathaniel Nicandro Date: Fri, 26 Nov 2021 12:50:38 -0600 Subject: [PATCH] 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. --- ob-jupyter.el | 10 +++++++++- test/jupyter-test.el | 13 ++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/ob-jupyter.el b/ob-jupyter.el index 9456261..f538532 100644 --- a/ob-jupyter.el +++ b/ob-jupyter.el @@ -473,7 +473,15 @@ the PARAMS alist." (jupyter-current-client (buffer-local-value 'jupyter-current-client buf)) (lang (jupyter-kernel-language jupyter-current-client)) (vars (org-babel-variable-assignments:jupyter params lang)) - (code (org-babel-expand-body:jupyter body params vars lang))) + (code (progn + (when-let* ((dir (alist-get :dir params))) + ;; `default-directory' is already set according + ;; to :dir when executing a source block. Set + ;; :dir to the absolute path so that + ;; `org-babel-expand-body:jupyter' does not try + ;; to re-expand the path. See #302. + (setf (alist-get :dir params) default-directory)) + (org-babel-expand-body:jupyter body params vars lang)))) (pcase-let ((`(,req ,maybe-result) (org-babel-jupyter--execute code async-p))) ;; KLUDGE: Remove the file result-parameter so that diff --git a/test/jupyter-test.el b/test/jupyter-test.el index a82a76f..757e397 100644 --- a/test/jupyter-test.el +++ b/test/jupyter-test.el @@ -2862,7 +2862,18 @@ os.path.abspath(os.getcwd())" ;; See #302 (jupyter-org-test-src-block "print(r\"\\r\")" - ": \\r\n"))))) + ": \\r\n"))) + (ert-info ("Relative directory") + ;; See #302 + (let* ((temporary-file-directory jupyter-test-temporary-directory) + (dir (make-temp-file "dir-header-arg" t))) + ;; FIXME: Don't use an internal function here. + (jupyter-org-test + (let ((default-directory (file-name-directory dir))) + (jupyter-org-test-src-block-1 + "print(\"hi\")" + ": hi\n" nil + `((:dir . ,(file-name-base dir)))))))))) (ert-deftest jupyter-org--find-mime-types () :tags '(org mime)