From mboxrd@z Thu Jan 1 00:00:00 1970 From: iyzsong@member.fsf.org (=?utf-8?B?5a6L5paH5q2m?=) Subject: Re: Python and propagation Date: Thu, 18 Feb 2016 23:03:31 +0800 Message-ID: <87fuwq2h8c.fsf@member.fsf.org> References: 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]:41111) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aWQ7b-0002Kv-3f for guix-devel@gnu.org; Thu, 18 Feb 2016 10:04:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aWQ7X-00079f-1Y for guix-devel@gnu.org; Thu, 18 Feb 2016 10:03:59 -0500 Received: from smtp2.openmailbox.org ([62.4.1.36]:60496) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aWQ7W-00079V-Su for guix-devel@gnu.org; Thu, 18 Feb 2016 10:03:54 -0500 In-Reply-To: (Ricardo Wurmus's message of "Thu, 18 Feb 2016 13:21:48 +0100") 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: Ricardo Wurmus Cc: guix-devel Ricardo Wurmus writes: > [...] > > 2) avoid PYTHONPATH, patch all Python files invasively! > > Python does not have any feature that is comparable to RUNPATH. It is > only concerned with finding libraries/modules by *name* in one of the > directories specified by the PYTHONPATH environment variable. > > But actually the PYTHONPATH variable is not the only means to affect the > search path for modules. It is possible to change the search path > programmatically: > > import sys > sys.path.append("/gnu/store/cabba9e...-numpy.../lib/...") > import numpy > > The first two lines add an explicit store item path to the search path; > the third line just imports the numpy module by name (as usual). Even > without setting the PYTHONPATH to include the numpy in the profile the > third line won=E2=80=99t fail. > I packaged python-hy, and it does find all depends without propagations. In its output, the trick is done by =E2=80=98python-hy-0.11.1.pth=E2=80=99 = and =E2=80=98site.py=E2=80=99. After read: I try: --8<---------------cut here---------------start------------->8--- $ mkdir -p /tmp/o $ mkdir -p /tmp/a $ echo /tmp/a > /tmp/o/x.pth $ cat > /tmp/o/sitecustomize.py << EOF > import os, site > dir =3D os.path.dirname(os.path.abspath(__fil__)) > site.addsitedir(dir) > EOF $ PYTHONPATH=3D/tmp/o python3 -c 'import sys; print(sys.path) --8<---------------cut here---------------end--------------->8--- And =E2=80=98/tmp/a=E2=80=99 is at the end of the list. So, I think if we get all the pth files correct, no need to use propagate-inputs :-)