all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Phil <phil@beadling.co.uk>
To: help-guix@gnu.org
Subject: Avoiding PYTHONPATH - latest?
Date: Mon, 30 Nov 2020 00:22:54 +0000	[thread overview]
Message-ID: <85360rr8v5.fsf@beadling.co.uk> (raw)

Hi all,

I've been having an argument with myself over the last 4 days about if
Guix's use of PYTHONPATH is a necessary evil or avoidable on a foreign OS.

I've found references to a similar discussion last year, and reference
to using a 'fake virtual environment' (does anyone have a reference to
the other thread referenced where fake venvs are demonstrated as not
working):

https://lists.gnu.org/archive/html/guix-devel/2019-06/msg00204.html
https://lists.gnu.org/archive/html/guix-devel/2019-06/msg00221.html

I had what I think is a similar idea over the weekend and tried it out.

Reading the mechanics of venvs as per PEP:
https://www.python.org/dev/peps/pep-0405

I decided to see if I added a fake pyvenv.cfg to the python.scm package
could allow for us to drop the use of PYTHONPATH completely.

Now the results are very preliminary, and I am essentially replacing
one hack with another (I'm not creating a venv after-all) - it does seem
to work just adding this to the python-3.8's phases: 

(add-after 'install 'add-pyvenv-cfg
           (lambda* (#:key outputs #:allow-other-keys)
                     ;; guix-daemon --build-users-group=guixbuild --chroot-directory=/path/to/guix_chroot_extra
                     (let ((out (assoc-ref outputs "out")))
                       (display (string-append "\nOutput Directory: \n" out "\n"))
                       (install-file "/path/to/guix_chroot_extra/pyvenv.cfg" out)
                       (substitute* (string-append out "/pyvenv.cfg")
                                    (("^home.*") (string-append "home = " out "\n"))
                                    (("^version.*") (string-append "version = 3.8.2\n"))))))

The native-search-paths can then have PYTHONPATH removed (I emulated
this by unset'ing it after creating a profile with the modified version
of the python package).

Starting python and looking at sys.path I could see this worked, both in
the cases where lib and bin symlink their counterpart
directories in the store, and also work when real lib and bin
directories in the profile contain symlinks to the store at the file level.

It seems so simple I'm sure it's been tried and found to misbehave, as I
hands-up accept it's misuse venv's funtionality (using pyvenv.cfg
without setting VIRTUAL_ENV is not defined behaviour).

But the current PYTHONPATH implementation immediately runs into problems
when you use venvs for development, via the cannonical "pip install -e
.".  The use of PYTHONPATH means that venvs are not created pure, they
inherit Guix's python env which is the exact opposite to what any
non-Guix python developer would expect.

Ironically when sharing environment setup responsibilities between
profiles and venvs like this, inheriting the profile's PYTHONPATH is
often useful - but it's still unexpected.

The PYTHONPATH, if I've understood correctly, is for user-level tweaks,
so hijacking it for system use may cause issues.

I was wondering what the current thoughts were on how Guix could
workaround using PYTHONPATH to set base system paths?

Thanks,
Phil.


             reply	other threads:[~2020-11-30  0:23 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-30  0:22 Phil [this message]
2020-11-30  9:41 ` Avoiding PYTHONPATH - latest? Phil
2020-12-03 11:06   ` 宋文武
2020-11-30 13:05 ` zimoun
2020-11-30 15:04   ` Phil
2020-12-01 12:39     ` zimoun
2020-12-01 13:28       ` Phil
2020-12-01 14:54         ` zimoun
2020-12-01 18:46           ` Phil

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=85360rr8v5.fsf@beadling.co.uk \
    --to=phil@beadling.co.uk \
    --cc=help-guix@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.