From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ricardo Wurmus Subject: Re: Python and propagation Date: Thu, 25 Feb 2016 11:24:41 +0100 Message-ID: References: <87fuwpprfx.fsf@dustycloud.org> Mime-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:41433) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aYt6O-0001Fz-3X for guix-devel@gnu.org; Thu, 25 Feb 2016 05:24:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aYt6J-0007dc-0F for guix-devel@gnu.org; Thu, 25 Feb 2016 05:24:56 -0500 Received: from venus.bbbm.mdc-berlin.de ([141.80.25.30]:53090) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aYt6I-0007dR-Jl for guix-devel@gnu.org; Thu, 25 Feb 2016 05:24:50 -0500 In-Reply-To: <87fuwpprfx.fsf@dustycloud.org> List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org To: Christopher Allan Webber Cc: guix-devel Christopher Allan Webber writes: > Ricardo Wurmus writes: >> 2) avoid PYTHONPATH, patch all Python files invasively! [...] > So... that may work! Except... well, I've raised this on another > thread, but I worry about late-binding based plugins or programs that > themselves call other python scripts (same with Guile, etc). The > previous example I gave was, what if I write a Haunt extension library, > and I need to call "haunt.scm" and pull in that stuff? > > http://lists.gnu.org/archive/html/help-guix/2016-02/msg00032.html > > What also about MediaGoblin plugins? MediaGoblin allows you to define > plugins for different media types, and etc. I don=E2=80=99t understand the issues, primarily because I don=E2=80=99t = understand if the load path is a global mutable variable for the Python process, or if it is local to the file, or if maybe it=E2=80=99s something else entirely= . I only proposed manipulating the load path before an =E2=80=9Cimport=E2=80= =9D statement because that=E2=80=99s how we can make the =E2=80=9Cimport=E2=80=9D state= ment succeed even if the PYTHONPATH at programme start does not contain the directory holding a needed library=E2=80=99s files. =E2=80=9Cimport=E2=80=9D doesn=E2=80=99= t allow us to use full paths, so the idea was to =E2=80=9Cwrap=E2=80=9D the =E2=80=9Cimport=E2=80=9D st= atement in an environment in which the load path has been sufficiently augmented. It would not be feasible to replace every =E2=80=9Cimport foo=E2=80=9D statement with som= ething like this: old_load_path =3D sys.path sys.path.append("/gnu/store/cabba9e...-foo.../lib/...") import foo sys.path =3D old_load_path so sys.path is instead just changed once per file. It would be worth figuring out how far these changes to sys.path reach =E2=80=94 do they ha= ve a global, process-wide effect? (That would be inconvenient as it=E2=80=99s= hard to reason about a change like this, because ordering becomes important.) How exactly to manipulate the load path =E2=80=94 I don=E2=80=99t know. = We could indeed recursively load .pth files if they exist, thereby adding things to the search path. (I did this in =E2=80=9C(@@ (gnu packages music) solfege)=E2= =80=9D to make pygtk work, for example.) Or we could create a list of paths at build time. > If you're adding a "gmg_frobnicator" plugin, can MediaGoblin find > gmg_frobnicator on its PYTHONPATH when run? It would not affect the loading of plugins, as far as I imagine it, because plugins would deal with their search paths by themselves (e.g. a user adds them to the PYTHONPATH). Since we only augment the load path instead of replacing it, $PYTHONPATH will always be available. So the answer to this question is =E2=80=9Cyes=E2=80=9D, I think. > And the reverse question: can gmg_frobnicator import back into > MediaGoblin and its dependencies? I don=E2=80=99t know what =E2=80=9Cimport back into=E2=80=9D means. I=E2=80=99m not a Python programmer, so I cannot come up with a simple ex= ample project that would allow us to test such an invasive substitution scheme. Is anyone else here willing to give this a try? ~~ Ricardo