From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Augusto Stoffel Newsgroups: gmane.emacs.devel Subject: Re: Buffer-local process environments Date: Sun, 09 May 2021 07:06:11 +0200 Message-ID: <87y2co4hto.fsf@gmail.com> 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> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="20170"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) Cc: Stefan Monnier , emacs-devel@gnu.org To: Michael Albinus Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sun May 09 07:08: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 1lfbgG-000578-Rm for ged-emacs-devel@m.gmane-mx.org; Sun, 09 May 2021 07:08:40 +0200 Original-Received: from localhost ([::1]:46542 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lfbgF-0004Em-1v for ged-emacs-devel@m.gmane-mx.org; Sun, 09 May 2021 01:08:39 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:47506) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lfbdz-0003Sj-DW for emacs-devel@gnu.org; Sun, 09 May 2021 01:06:19 -0400 Original-Received: from mail-ej1-x62d.google.com ([2a00:1450:4864:20::62d]:39664) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lfbdw-00089I-Ve for emacs-devel@gnu.org; Sun, 09 May 2021 01:06:19 -0400 Original-Received: by mail-ej1-x62d.google.com with SMTP id f24so19653698ejc.6 for ; Sat, 08 May 2021 22:06:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:message-id:user-agent :mime-version; bh=SARtmOR1R1VFAPWyz7CBNbZCpjkUYnIzEBrtpPBCYhE=; b=bGXQe/+yc2tw4g5uk8A95W/q5Uwqc/hH4FLwlGXnD+cBdNPo4qfzp3uGeSPO4+at1n VNRWkSLs9RRXYC48bKu4OQ2ne4w1xaiIGxfeVBKjaI4SevC3YlSsSiFNtEcRBiYkbDBM hcwYwAX5NqboE2uk/dayBUtYFk7imP6hbucZE2rXEyLj0+MAL6BEkZ/aEn//7vY6nE2y 8+1XjgO4duj+GXN7FLT1XsWXD2AcWDmyg9tYBcy0r3AK/UqegaZn1NL4Ok26eueeiZBD NyhuVmo43f0izEocXgWEBEBiDp+tl9xjeGValgVG9qnM4xQjnpUYpke/i7jhnDjvVomg RoUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:message-id :user-agent:mime-version; bh=SARtmOR1R1VFAPWyz7CBNbZCpjkUYnIzEBrtpPBCYhE=; b=uRhdwpQrs69BPmWyTrYpxPjqRiOplfdAPwwSpcqUlE+CDCAHA5y3K2zMo/vVtuBCpg BkQbXYzfENVSr/Lay643LCgoM2nD4m/grz6KjPUhlzB68P7HpAZpO8QJ7mmf+8ITwu90 vJFy4WkomEnxrd91skIkqyBb6HO4vBp48lsZ5L4PkKsuxdkL7kq9Lq5v/7T92kbsuQuQ UoPkYyB1gMgKFyHaomdKXm8CzGQ7FlKrf9swxQq++/H5j8jKB2A/SyHX/fGRWIdogGlP 1HD6bn+NHzVtNIXU60RBBvtNoXMFVXh75/AcuynfpopUJsfhpzmOdV2S79jc/jqaZhW0 IxTA== X-Gm-Message-State: AOAM530Dp2sbe+g/5DMk8VMvYrg9ZPO8LB+8lMGS+BTZwo2wysir4PqH M5WNxG3VEb/N6Jkq2bbn/8WoPMamkv8bLw== X-Google-Smtp-Source: ABdhPJxsIGrWneZCke/0jFWsBjJChCG/brP5ajcGvCD4usntQTiXVqTDc/gnXsuwDzq82MVzyReVvg== X-Received: by 2002:a17:906:8a59:: with SMTP id gx25mr19133930ejc.63.1620536773522; Sat, 08 May 2021 22:06:13 -0700 (PDT) Original-Received: from ars3 ([2a02:908:2211:8540::68a]) by smtp.gmail.com with ESMTPSA id w19sm7874178edd.52.2021.05.08.22.06.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 May 2021 22:06:12 -0700 (PDT) Received-SPF: pass client-ip=2a00:1450:4864:20::62d; envelope-from=arstoffel@gmail.com; helo=mail-ej1-x62d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, 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:269069 Archived-At: --=-=-= Content-Type: text/plain On Sat, 8 May 2021 at 19:51, Michael Albinus wrote: Hi Michael, > We have already a white list, which is tramp-remote-process-environment. > I'm reluctant to add package specific entries there by default, it would > be an endless story. PAGER is included as being a general purpose > environment variable, BZR_LOG and HGPLAIN are not. If packages believe > they shall be added, this could be done in vc-bzr.el or vc-hg.el. Tramp > is a stupid library, it shouldn't try to be clever. Fair enough. Let's cross out the first idea then. >> 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 >> =VALUE, means removing the variable. > > There are already such variables to be unset. These are the variables > without any value, like "HISTORY=" This only works for entries in the default toplevel value of `process-environment'. Not for things added buffer-locally or in a let-binding. 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. > TERM is handled special. All Tramp connections add "TERM=dumb", > hard-coded. Since this shall not be changed by a user, it isn't > configurable here. Not all connections add "TERM=dumb". Here's a counterexample: (let ((default-directory "/sudo::/") (process-environment `("TERM=dumber" ,@process-environment))) (shell-command "echo $TERM" t)) => dumber How do I tell Tramp not to export TERM=dumber to the remote in this case? 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? >> 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 might > differ depending on the OS the remote host is running. That's precisely what I meant: you *do not* want to export those variables to a remote. But currently Tramp effectively forbids anyone to set PYTHONPATH buffer-locally, because this will cause them to be exported. My suggestion is easier to implement than explain. So let me repeat it in the form of a little (possibly incomplete) patch: --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=tramp-env.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 "=" 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 "=" elt) (not (member - elt (default-toplevel-value 'process-environment)))) + elt (default-toplevel-value 'process-environment))) + (not (member (car (split-string elt "=")) + tramp-remote-process-environment))) (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 ")")))) --=-=-=--