all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Ricardo Wurmus <ricardo.wurmus@mdc-berlin.de>
To: Andreas Enge <andreas@enge.fr>
Cc: guix-devel <guix-devel@gnu.org>
Subject: Re: Python and propagation
Date: Thu, 18 Feb 2016 15:45:36 +0100	[thread overview]
Message-ID: <idj4md65b73.fsf@bimsb-sys02.mdc-berlin.net> (raw)
In-Reply-To: <20160218142823.GA1618@solar>


Andreas Enge <andreas@enge.fr> writes:

> On Thu, Feb 18, 2016 at 01:21:48PM +0100, Ricardo Wurmus wrote:
>> 2) avoid PYTHONPATH, patch all Python files invasively!
>>     import sys
>>     sys.path.append("/gnu/store/cabba9e...-numpy.../lib/...")
>
> That sounds great! It appears to me as if you have found the equivalent of
> a RUNPATH for python scripts.
>
> It could more or less be done like the patch-shebangs phase. To me it
> does not look difficult to implement. Assume it is done in a separate
> phase after patching shebangs:
>
> - Create a list of all the python inputs of the package; these are the
>   inputs the package name of which starts with "python-". Or the directory
>   names "/gnu/store/xxx-python-xxx", depending on what is available in
>   the phase.

I think this might have to operate on the bag.  I’m not sure if a Python
package can (or should be able to expect to) import a package that it
has not declared as a direct input.  So far we have just propagated
inputs, which makes it unclear if an input in the bag is really directly
used by the Python package itself.

If we only used direct inputs (each of which would alter the “sys.path”
for its own needs on load) we would probably have to clean up the inputs
of many Python packages, because we can no longer rely on the
side-effect of propagation (which blurs the line between what a package
is and what a bag is).  I would consider this a good thing, but it
sounds like a lot of work.

> - Construct the corresponding string to add to the python scripts.
> - Look for files starting with a shebang and having "python" as part
>   of the interpreter. Then add the string after the first, shebang line
>   in all these files.

I think this must be done to all Python files, not just scripts.  If I
install just numpy and I want to use it as a library it should be able
to find all its (fixed) dependencies by itself.  So even though the
entry point for numpy does not have a shebang, it should also contain
the magic string on its first line to set the “sys.path”.

> Or is it more complicated than that?

Maybe it is, but I don’t know enough about Python to answer the
following questions:

* What is the cumulative effect of setting or appending to “sys.path”?
  Does this affect performance?  Can we do this at compile time only?
  (Probably not as we do not guarantee that “.py” files are compiled to
  “.pyc”.)

* What happens when we have more than one package modifying the
  “sys.path”?  Is the effect local to the package or global for the
  Python process?  Will a package that only sets “sys.path” to find the
  modules it imports affect the operation of modules and their own
  imports?

* Should we overwrite “sys.path” rather than appending to it?  Would
  that still allow users to override pieces with PYTHONPATH?  Should
  they be able to do so?

* Could the load order of Python files become important (e.g. when one
  file in one package sets a different store item for a Python module
  than another)?

~~ Ricardo

  reply	other threads:[~2016-02-18 14:45 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 [this message]
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
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

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

  git send-email \
    --in-reply-to=idj4md65b73.fsf@bimsb-sys02.mdc-berlin.net \
    --to=ricardo.wurmus@mdc-berlin.de \
    --cc=andreas@enge.fr \
    --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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.