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.
This commit is contained in:
		
							parent
							
								
									d91de53caa
								
							
						
					
					
						commit
						223cc96e5b
					
				
					 1 changed files with 16 additions and 6 deletions
				
			
		| 
						 | 
					@ -18,6 +18,7 @@
 | 
				
			||||||
# along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.
 | 
					# along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import os
 | 
					import os
 | 
				
			||||||
 | 
					import site
 | 
				
			||||||
import sys
 | 
					import sys
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Commentary:
 | 
					# 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
 | 
					matching_sites = [p for p in all_sites_norm
 | 
				
			||||||
                  if p.endswith(site_packages_prefix)]
 | 
					                  if p.endswith(site_packages_prefix)]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Insert sites matching the current version into sys.path, right before
 | 
					if matching_sites:
 | 
				
			||||||
# Python's own site.  This way, the user can override the libraries provided
 | 
					    # Deduplicate the entries, append them to sys.path, and handle any
 | 
				
			||||||
# by Python itself.
 | 
					    # .pth files they contain.
 | 
				
			||||||
sys_path_absolute = [os.path.realpath(p) for p in sys.path]
 | 
					    for s in matching_sites:
 | 
				
			||||||
index = sys_path_absolute.index(python_site)
 | 
					        site.addsitedir(s)
 | 
				
			||||||
sys.path[index:index] = matching_sites
 | 
					
 | 
				
			||||||
 | 
					    # 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])
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Reference in a new issue