unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Ricardo Wurmus <ricardo.wurmus@mdc-berlin.de>
To: Christopher Allan Webber <cwebber@dustycloud.org>
Cc: guix-devel <guix-devel@gnu.org>
Subject: Re: Python and propagation
Date: Thu, 25 Feb 2016 11:24:41 +0100	[thread overview]
Message-ID: <idjbn752il2.fsf@bimsb-sys02.mdc-berlin.net> (raw)
In-Reply-To: <87fuwpprfx.fsf@dustycloud.org>


Christopher Allan Webber <cwebber@dustycloud.org> 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’t understand the issues, primarily because I don’t 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’s something else entirely.

I only proposed manipulating the load path before an “import” statement
because that’s how we can make the “import” statement succeed even if
the PYTHONPATH at programme start does not contain the directory holding
a needed library’s files.  “import” doesn’t allow us to use full paths,
so the idea was to “wrap” the “import” statement in an environment in
which the load path has been sufficiently augmented.  It would not be
feasible to replace every “import foo” statement with something like
this:

    old_load_path = sys.path
    sys.path.append("/gnu/store/cabba9e...-foo.../lib/...")
    import foo
    sys.path = 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 — do they have a
global, process-wide effect?  (That would be inconvenient as it’s hard
to reason about a change like this, because ordering becomes important.)

How exactly to manipulate the load path — I don’t know.  We could indeed
recursively load .pth files if they exist, thereby adding things to the
search path.  (I did this in “(@@ (gnu packages music) solfege)” 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 “yes”, I think.

> And the reverse question: can gmg_frobnicator import back into
> MediaGoblin and its dependencies?

I don’t know what “import back into” means.

I’m not a Python programmer, so I cannot come up with a simple example
project that would allow us to test such an invasive substitution
scheme.  Is anyone else here willing to give this a try?

~~ Ricardo

  reply	other threads:[~2016-02-25 10:24 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-18 12:21 Python and propagation Ricardo Wurmus
2016-02-18 14:28 ` Andreas Enge
2016-02-18 14:45   ` Ricardo Wurmus
2016-02-18 15:03     ` Andreas Enge
2016-02-18 14:56   ` Jookia
2016-02-18 15:03 ` 宋文武
2016-02-19  1:26   ` 宋文武
2016-02-18 22:38 ` Christopher Allan Webber
2016-02-25 10:24   ` Ricardo Wurmus [this message]
2016-02-25 16:13     ` Christopher Allan Webber
2016-02-24 22:09 ` Ludovic Courtès
2016-04-04 22:08 ` Danny Milosavljevic
  -- strict thread matches above, loose matches on Subject: below --
2016-02-22 17:08 Federico Beffa

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=idjbn752il2.fsf@bimsb-sys02.mdc-berlin.net \
    --to=ricardo.wurmus@mdc-berlin.de \
    --cc=cwebber@dustycloud.org \
    --cc=guix-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).