From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Michael Albinus Newsgroups: gmane.emacs.devel Subject: Re: Buffer-local process environments Date: Sun, 09 May 2021 18:38:31 +0200 Message-ID: <87v97reubc.fsf@gmx.de> References: <87eeets6jf.fsf@gmail.com> <8735v99f4i.fsf@gmail.com> <87y2d1xada.fsf@gmx.de> <877dkkcjrj.fsf@gmail.com> <87tunoyzzd.fsf@gmx.de> <87eeerby1n.fsf@gmail.com> <87a6pfepo6.fsf@gmx.de> <874kflmzn3.fsf@gmail.com> <87wns9glm1.fsf@gmx.de> <87y2co4hto.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="17582"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: Stefan Monnier , emacs-devel@gnu.org To: Augusto Stoffel Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sun May 09 18:40:41 2021 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lfmTx-0004Rq-RH for ged-emacs-devel@m.gmane-mx.org; Sun, 09 May 2021 18:40:41 +0200 Original-Received: from localhost ([::1]:41766 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lfmTw-0006Cf-Ri for ged-emacs-devel@m.gmane-mx.org; Sun, 09 May 2021 12:40:40 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:56292) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lfmS2-0004nu-88 for emacs-devel@gnu.org; Sun, 09 May 2021 12:38:44 -0400 Original-Received: from mout.gmx.net ([212.227.15.18]:51335) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lfmS0-0005rm-1X for emacs-devel@gnu.org; Sun, 09 May 2021 12:38:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1620578313; bh=cQc/oDAw4IandighQk702P+vnYydYqt6aIrEFu4VRH8=; h=X-UI-Sender-Class:From:To:Cc:Subject:References:Date:In-Reply-To; b=FwjsCZdcP1ZSRyV1cga7/WqcCFkw23IhXDoMjSR8aS1H0FJT3/aC6bK9CVNjB1MXE PTngZhsCSc9ZG8f/APb/uYEB9HQRAU8MV64KK1cPZJVPOzGjBbn9T26trJhvapy4KG WgNghC1hISqRr4KkFVQvq0PEUucfrHkdf27iePGs= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Original-Received: from gandalf.gmx.de ([212.91.243.204]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MIMbO-1llIlx0cho-00ELGB; Sun, 09 May 2021 18:38:33 +0200 In-Reply-To: <87y2co4hto.fsf@gmail.com> (Augusto Stoffel's message of "Sun, 09 May 2021 07:06:11 +0200") X-Provags-ID: V03:K1:/Vjq/KCIYUhhzsZ69rwXQ7XlrL2aDLtG6UJzvnA+0ynLGMZYcpy jp1pQf/WYVpqH5vFRn2lWXOQgUPQCD3Bi97grb0/SOMQrYNXJHXZZv4dgnSrMQdghYKjNJA m7DCJ6VwD3yG+sSYcxmflsYQZmTgUA6UqWkbbEDppW+q0/DRzyNNzlT/V4NtnWlENPMAwvB 5fYeymj0aUX6stHsiqWsQ== X-UI-Out-Filterresults: notjunk:1;V03:K0:V8ERzT9/0fg=:IUEwXcUVLsX1djwleJofYm MVqDqb+zfDANCU+Qpx5m0RoqdqliY5RPW7s0wBokwFKr5z7R6xvhx77kFpl9l8EW5RZhlyMgG vw9E16+RruGklzpTMYoLmp3Kfd1R/7V5Xu+NVoUBjEHkOgxh+PMOX/3JWpVVS9XsnHLRuOiSi YeC4Qzqg8FAzwwJns8o7WQLwOGyyYGzaCIGvPvqHCdhvUuxjIeleHDuyHsKmsOLXK0Xd09HvI Tv94DPIfxWjTd7Topkv/bqBPaWma+qyht4KVUoo6XjBIwBZFULsQ4eHOFGU5CBKNINjXs+7g8 tWRwL+fqIDljnSHlZqIDzP63Vjuu9r3GWZpxlQcJ3qSHCIXJwtjKeNaKfdcg+kh5/3oW5Vhte Heclu59ec6FF3LnFqVgk333YzLCjSc76tlhP/mGOdMiI3crZJpObFn/cr2UnSv/nKzK0ueEIU YiI1BfrKmSb5a6iym+ZpX1NR63AmhF9k9FYSBF4bc0PSTSmtt0uQYqwSfNJzZJw9fj1pO19UR oSxri0uo7L5GoTMecYnR9jRH1KMIRCez+GYHw5L+G25gv09HvSWHSnXYwxmG+D9D6IHLTTudi SjSjQNX7vnmeRz02vbL1hOYWAz+4RWI64XitwxW79rG96T7JBGQNpBu3NBB3NEvMvxwBXdXDX XQ6aoS1twmmDMmkloQHTOnq8/laeztrkH/QRRSRY7tqCl93lkWxe69J8MTBz1v4bmJyh8IhUP dUBhGh0U7+9RCWgpzADf6NecSriarUK3fR8Kuh2d0PM82+hrY3mpjRz73XnHZe4xAWe7h1VU Received-SPF: pass client-ip=212.227.15.18; envelope-from=michael.albinus@gmx.de; helo=mout.gmx.net X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:269083 Archived-At: Augusto Stoffel writes: > Hi Michael, Hi Augusto, >>> 2. Introduce a blacklist of variables that are never exported to a >>> remote. This can be done by extending >>> `tramp-remote-process-environment' to follow the same convention of >>> `process-environment' that an entry of the form VAR, without the >>> =3DVALUE, means removing the variable. >> >> There are already such variables to be unset. These are the variables >> without any value, like "HISTORY=3D" > > This only works for entries in the default toplevel value of > `process-environment'. Not for things added buffer-locally or > in a let-binding. Yes, this is a bug (rather a missing feature) of Tramp. It is implemented for synchronous processes, but not for asynchronous processes. I'm aware of this, but I haven't found the mood to implement it until now. > The heuristic that every env var which is not in the default toplevel > value of `process-environment' will be exported to the remote works > pretty well. But it needs a simple way to be overridden, since it can't > read the user's mind. Sure. Tramp shall not read the user's mind. (As side remark, my wife expects always that I read her mind. I fail miserably, usually.) >> TERM is handled special. All Tramp connections add "TERM=3Ddumb", >> hard-coded. Since this shall not be changed by a user, it isn't >> configurable here. > > Not all connections add "TERM=3Ddumb". Here's a counterexample: > > (let ((default-directory "/sudo::/") > (process-environment `("TERM=3Ddumber" > ,@process-environment))) > (shell-command "echo $TERM" t)) > =3D> dumber > > How do I tell Tramp not to export TERM=3Ddumber to the remote in this > case? You can always shoot yourself in your feed. > To be clear: this may be a dumb example, but there are plenty of > interesting use-cases involving PATH, PYTHONPATH, and so on, which are > analogous. How can I set PYTHONPATH buffer-locally, but disallow Tramp > to export this variable to a remote? Set it only, when the buffer is not remote. Something like (unless (file-remote-p default-directory) ...) >>> As another example, python.el would append "PYTHONPATH" and >>> "PYTHONHOME" globally to `tramp-remote-process-environment', since >>> these variables hold directory names. >> >> Yes, if python.el developers prefer that. However, I doubt, that this >> value is always the same for all different remote hosts, the value migh= t >> differ depending on the OS the remote host is running. > > That's precisely what I meant: you *do not* want to export those variabl= es > to a remote. But currently Tramp effectively forbids anyone to set > PYTHONPATH buffer-locally, because this will cause them to be exported. No. See above. > My suggestion is easier to implement than explain. So let me repeat it > in the form of a little (possibly incomplete) patch: > > diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el > index 015f458a63..3749f84e21 100644 > --- a/lisp/net/tramp.el > +++ b/lisp/net/tramp.el > @@ -3938,21 +3938,23 @@ tramp-handle-make-process > (when (string-match-p "=3D" elt) elt)) > tramp-remote-process-environment)) > ;; We use as environment the difference to toplevel > ;; `process-environment'. > (env (dolist (elt process-environment env) > (when > (and > (string-match-p "=3D" elt) > (not > (member > - elt (default-toplevel-value 'process-environment)))) > + elt (default-toplevel-value 'process-environment))) > + (not (member (car (split-string elt "=3D")) > + tramp-remote-process-environmen= t))) > (setq env (cons elt env))))) > (env (setenv-internal > env "INSIDE_EMACS" (tramp-inside-emacs) 'keep)) > (env (mapcar #'tramp-shell-quote-argument (delq nil env))) > ;; Quote command. > (command (mapconcat #'tramp-shell-quote-argument command " ")) > ;; Set cwd and environment variables. > (command > (append `("cd" ,localname "&&" "(" "env") env `(,command ")"))= )) > I see. Interesting. But this still means, that you use something global in tramp-remote-process-environment for all remote processes. What, if you want to set PYTHONPATH for hosta, and not for hostb? Best regards, Michael.