[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Python and propagation
From: |
宋文武 |
Subject: |
Re: Python and propagation |
Date: |
Thu, 18 Feb 2016 23:03:31 +0800 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) |
Ricardo Wurmus <address@hidden> 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’t fail.
>
I packaged python-hy, and it does find all depends without propagations.
In its output, the trick is done by ‘python-hy-0.11.1.pth’ and ‘site.py’.
After read:
<https://docs.python.org/2/library/site.html>
<http://stackoverflow.com/questions/15208615/using-pth-files>
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 = os.path.dirname(os.path.abspath(__fil__))
> site.addsitedir(dir)
> EOF
$ PYTHONPATH=/tmp/o python3 -c 'import sys; print(sys.path)
--8<---------------cut here---------------end--------------->8---
And ‘/tmp/a’ is at the end of the list.
So, I think if we get all the pth files correct, no need to use
propagate-inputs :-)