Subject: [bug#64573] [PATCH 2/3] gnu: python-pip: Enable user site even with PYTHONNOUSERSITE

From: Wojtek Kosior <[email-masked]>
Date: Tue, 11 Jul 2023 20:14:39 +0200

* gnu/packages/python-build.scm (python-pip): Patch pip to allow installing to
user site dir when PYTHONNOUSERSITE is set by Guix wrapper script to
'GUIX_WRAPPER' string.
---
 gnu/packages/python-build.scm | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/gnu/packages/python-build.scm b/gnu/packages/python-build.scm
index 154c97e9e4..54d12f3fdc 100644
--- a/gnu/packages/python-build.scm
+++ b/gnu/packages/python-build.scm
@@ -269,7 +269,15 @@ (define-public python-pip
          "0jnk639v9h7ghslm4jnlic6rj3v29nygflx1hgxxndg5gs4kk1a0"))))
     (build-system python-build-system)
     (arguments
-     '(#:tests? #f))          ; there are no tests in the pypi archive.
+     `(#:tests? #f            ;there are no tests in the pypi archive
+       #:phases
+       (modify-phases %standard-phases
+         (add-after 'unpack 'allow-installing-to-user-site
+           (lambda _
+             (substitute* "src/pip/_internal/commands/install.py"
+               (("( *if not site\\.ENABLE_USER_SITE):" match if-clause)
+                (string-append if-clause
+                               " and not os.environ['PYTHONNOUSERSITE'] == 'GUIX_WRAPPER':"))))))))
     (home-page "https://pip.pypa.io/")
     (synopsis "Package manager for Python software")
     (description
-- 
2.40.1