From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms8.migadu.com with LMTPS id qEYMHnZgvmXlgAAAe85BDQ:P1 (envelope-from ) for ; Sat, 03 Feb 2024 16:49:10 +0100 Received: from aspmx1.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2.migadu.com with LMTPS id qEYMHnZgvmXlgAAAe85BDQ (envelope-from ) for ; Sat, 03 Feb 2024 16:49:10 +0100 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=FKHdpHTY; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org"; dmarc=pass (policy=none) header.from=posteo.net ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1706975350; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=dQGZLJDTvZaU3Lai+IeAiIPHPruTW0qfdpcIUQ6068o=; b=CSJ8M+zgIQaY7MYJz1dWtWL+dIEFvWeCVYRZTLq/l+NxxjaXzbQZxj7aLtzfz5RjsdJrfd ruvrSLCMBoK3hEDIPcTFt0bzDdlPhtGyb4SV9cGlvRPttqcwc1lq/uwgFs4pPI29tqiXhz FOuaZ5zROdSKqx2DmmthBcRNRykSKEHYo/MzgeMxIDRkhvbbtvExIzMwtTOJ3tN7Kp0+/2 UAXM3wws03RIBDenWkTcuYgh6F+vtdZ4+94ctMWim1S6ZXazaQFUudup3CnBhRR11aVHc/ WS1uiyBZ6ZxqBKfatSIjpUdFisurvS5fRl5jSh281/4wEaUcZoxii3hhQj661w== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=FKHdpHTY; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org"; dmarc=pass (policy=none) header.from=posteo.net ARC-Seal: i=1; s=key1; d=yhetil.org; t=1706975350; a=rsa-sha256; cv=none; b=VTzrFuoT4cey8EdA4ljGsLRLsoZMhIPFGHax3s173QAQsAFnX+hKKYBeK/f8HSz2vDUezz 1kT9T1zXvzmuQk7Xmw3f3N2wEz7wsbHCLyH0aNMXlNKpT5FdXIb/6rSpRfZXkvy9hmL3YH IhWr3ZuJhqG6C67Vtogh0TituUZO6remFL6Q7Ti1DSPdqPIz4wRXjZWybWdajYEiHX1EdF 73+1R2XQupBpp2peTEpPKNpj2FrFLTX0vTCpwnx19uYFyp5SQNnrhKSAXpYvZSSGP0FJD8 G91+Xq6zXbzsAI6fB5X6YoKPqNYhWEq5qrcTpTPRghgVpz89LmJejfMLyfK9HA== Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 8E5FE3DDD7 for ; Sat, 3 Feb 2024 16:49:09 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rWIFa-0000NB-Gx; Sat, 03 Feb 2024 10:48:14 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rWIFX-0000Mk-L2 for emacs-orgmode@gnu.org; Sat, 03 Feb 2024 10:48:11 -0500 Received: from mout01.posteo.de ([185.67.36.65]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rWIFV-000193-D4 for emacs-orgmode@gnu.org; Sat, 03 Feb 2024 10:48:11 -0500 Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id 99614240028 for ; Sat, 3 Feb 2024 16:48:04 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1706975284; bh=AAxSfJ6CMDW+2mpriWOsm0pOJirSOeAXE7WCA8amHcM=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type: From; b=FKHdpHTY2J4nzs/WeNduiaas+kBQ7meaUL3y+ucS9AXq0D2pNbQ+78CEPfCIGwkTE HuS/Z9cKZyh+djxUBqMhXyBK7oMw+WavQw5ewegfZycDbDhX76gwTLTYfMP/24m9gx X+T7XGBetUTPpsrwvR0lqhoxdbyouzGxqVpZ6aR8LzxSItn/ti0s8Nwzwka+gSz7QU fsVgS+U2UDULYypeljm5SBReOL8JQgfWqoicL4yhSif6ivoHWP8c7lLjl18nbmncgq v6ynRqRLq9ieXb0D0Ll/EbfZ2JRl2bq9I+LIFDzvie6rvOXDpcSOuaAU7m9gZMl937 g3D5hpJtHT8Rg== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4TRxql4Swsz6tyd; Sat, 3 Feb 2024 16:48:03 +0100 (CET) From: Ihor Radchenko To: Jack Kamm Cc: Nasser Alkmim , emacs-orgmode@gnu.org Subject: Re: Async Python src block behavior with :dir header property In-Reply-To: <87mssi8ht2.fsf@gmail.com> References: <87il3a55bg.fsf@gmail.com> <8734udvjai.fsf@localhost> <86plxhely9.fsf@gmail.com> <8734udoejo.fsf@localhost> <86y1c5cztv.fsf@gmail.com> <875xz9o4nj.fsf@localhost> <87plxg95u4.fsf@gmail.com> <87msskmm47.fsf@localhost> <87mssi8ht2.fsf@gmail.com> Date: Sat, 03 Feb 2024 15:51:32 +0000 Message-ID: <87plxdmtq3.fsf@localhost> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=185.67.36.65; envelope-from=yantar92@posteo.net; helo=mout01.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: emacs-orgmode-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US X-Migadu-Spam-Score: -9.88 X-Migadu-Queue-Id: 8E5FE3DDD7 X-Spam-Score: -9.88 X-Migadu-Scanner: mx11.migadu.com X-TUID: 2C9gR/67BZqb --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Jack Kamm writes: > Ihor Radchenko writes: > >> The patch generally looks reasonable, although I am slightly concerned >> about interaction between :dir and session we describe in the manual: >> >> When =E2=80=98dir=E2=80=99 is used with =E2=80=98session=E2=80=99, O= rg sets the starting directory >> for a new session. But Org does not alter the directory of an alrea= dy >> existing session. > > I agree it's a problem -- if there are multiple blocks with the same > session but different ":dir" arguments, then a ":file" result of the > second block will be relative to the wrong :dir. > > This seems like a longstanding problem, and affects both async and > non-async session blocks. Maybe something like the attached? > Ideally, ":dir" should be set at session level rather than block > level. This could be done via PROPERTY if there is only one session in > the file or subtree, but there isn't a mechanism for this more > generally. Or we can ask babel backends to respect :dir and issue the necessary "cd" command in the session for the duration of the code block evaluation. > Perhaps the simplest solution is to add a check to org-lint, requiring > all blocks with the same session to have the same :dir. Or this. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-org-babel-execute-src-block-Force-dir-according-to-l.patch >From 1e87de13d44a1bb31985622bfc9c9a6df6b7548c Mon Sep 17 00:00:00 2001 Message-ID: <1e87de13d44a1bb31985622bfc9c9a6df6b7548c.1706975370.git.yantar92@posteo.net> From: Ihor Radchenko Date: Sat, 3 Feb 2024 16:47:57 +0100 Subject: [PATCH] org-babel-execute-src-block: Force :dir according to live session * lisp/ob-core.el (org-babel-execute-src-block): Force eval directory to follow live session buffer, if any. This is consistent with what we promise in the manual. Link: https://orgmode.org/list/87mssi8ht2.fsf@gmail.com --- lisp/ob-core.el | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/lisp/ob-core.el b/lisp/ob-core.el index 1de3af6ad..2cd542012 100644 --- a/lisp/ob-core.el +++ b/lisp/ob-core.el @@ -840,14 +840,17 @@ (defun org-babel-execute-src-block (&optional arg info params executor-type) (dir (cdr (assq :dir params))) (mkdirp (cdr (assq :mkdirp params))) (default-directory - (cond - ((not dir) default-directory) - ((member mkdirp '("no" "nil" nil)) - (file-name-as-directory (expand-file-name dir))) - (t - (let ((d (file-name-as-directory (expand-file-name dir)))) - (make-directory d 'parents) - d)))) + (cond + ((not dir) default-directory) + ((when-let ((session (assq :session params))) + (when (org-babel-comint-buffer-livep session) + (buffer-local-value 'default-directory (get-buffer session))))) + ((member mkdirp '("no" "nil" nil)) + (file-name-as-directory (expand-file-name dir))) + (t + (let ((d (file-name-as-directory (expand-file-name dir)))) + (make-directory d 'parents) + d)))) (cmd (intern (concat "org-babel-execute:" lang))) result exec-start-time) (unless (fboundp cmd) -- 2.43.0 --=-=-= Content-Type: text/plain -- Ihor Radchenko // yantar92, Org mode contributor, Learn more about Org mode at . Support Org development at , or support my work at --=-=-=--