[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
01/145: sitecustomize.py: Honor .pth files.
From: |
guix-commits |
Subject: |
01/145: sitecustomize.py: Honor .pth files. |
Date: |
Mon, 10 Jan 2022 11:43:59 -0500 (EST) |
apteryx pushed a commit to branch version-1.4.0
in repository guix.
commit c4fc72f92a03b9d9569d4100b959f01bc5113ee0
Author: Maxim Cournoyer <maxim.cournoyer@gmail.com>
AuthorDate: Fri Dec 3 22:36:26 2021 -0500
sitecustomize.py: Honor .pth files.
Fixes <https://issues.guix.gnu.org/52269>.
* gnu/packages/aux-files/python/sitecustomize.py: Use site.addsitedirs to
add
the site directories; this takes care of the .pth files. Make sure the
added
items still appear before Python's own 'site-packages' directory.
---
gnu/packages/aux-files/python/sitecustomize.py | 22 ++++++++++++++++------
1 file changed, 16 insertions(+), 6 deletions(-)
diff --git a/gnu/packages/aux-files/python/sitecustomize.py
b/gnu/packages/aux-files/python/sitecustomize.py
index 71e328b9ac..e2348e0356 100644
--- a/gnu/packages/aux-files/python/sitecustomize.py
+++ b/gnu/packages/aux-files/python/sitecustomize.py
@@ -18,6 +18,7 @@
# along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
import os
+import site
import sys
# Commentary:
@@ -47,9 +48,18 @@ all_sites_norm = [os.path.normpath(p) for p in all_sites_raw]
matching_sites = [p for p in all_sites_norm
if p.endswith(site_packages_prefix)]
-# Insert sites matching the current version into sys.path, right before
-# Python's own site. This way, the user can override the libraries provided
-# by Python itself.
-sys_path_absolute = [os.path.realpath(p) for p in sys.path]
-index = sys_path_absolute.index(python_site)
-sys.path[index:index] = matching_sites
+if matching_sites:
+ # Deduplicate the entries, append them to sys.path, and handle any
+ # .pth files they contain.
+ for s in matching_sites:
+ site.addsitedir(s)
+
+ # Move the entries that were appended to sys.path in front of
+ # Python's own site-packages directory. This enables Guix
+ # packages to override Python's bundled packages, such as 'pip'.
+ python_site_index = sys.path.index(python_site)
+ new_site_start_index = sys.path.index(matching_sites[0])
+ if python_site_index < new_site_start_index:
+ sys.path = (sys.path[:python_site_index]
+ + sys.path[new_site_start_index:]
+ + sys.path[python_site_index:new_site_start_index])
- branch version-1.4.0 created (now 3b6e2a686c), guix-commits, 2022/01/10
- 01/145: sitecustomize.py: Honor .pth files.,
guix-commits <=
- 13/145: gnu: avahi: Make all arguments unconditional., guix-commits, 2022/01/10
- 05/145: gnu: python-wheel: Update to 0.37.0., guix-commits, 2022/01/10
- 04/145: gnu: python-packaging-bootstrap: Update to 21.3., guix-commits, 2022/01/10
- 03/145: gnu: mesa: Update to 21.3.2., guix-commits, 2022/01/10
- 07/145: gnu: python-tomli: Update to 2.0.0., guix-commits, 2022/01/10
- 14/145: gnu: autoconf-2.69: Repatriate unpatch-shebangs phase from 2.71., guix-commits, 2022/01/10
- 11/145: utils: Fix wrap-script argument handling., guix-commits, 2022/01/10
- 12/145: gnu: python-3.9: Update to 3.9.9., guix-commits, 2022/01/10
- 19/145: gnu: gobject-introspection: Unconditionally use flex and bison., guix-commits, 2022/01/10
- 22/145: gnu: cairo: Use bash-minimal unconditionally., guix-commits, 2022/01/10