@@ -410,22 +410,22 @@ def sitecustomize
410410 sys.path.extend(library_packages)
411411 # the Cellar site-packages is a symlink to the HOMEBREW_PREFIX
412412 # site_packages; prefer the shorter paths
413- long_prefix = re.compile(r'#{ rack } /(?: [0-9\\ ._abrc]+/Frameworks/Python\\ .framework/Versions/#{ version . major_minor } /)?lib/python#{ version . major_minor } /site-packages')
413+ long_prefix = re.compile(r'#{ rack } /[0-9\\ ._abrc]+/(?: Frameworks/Python\\ .framework/Versions/#{ version . major_minor } /)?lib/python#{ version . major_minor } /site-packages')
414414 sys.path = [long_prefix.sub('#{ site_packages } ', p) for p in sys.path]
415415 # Set the sys.executable to use the opt_prefix. Only do this if PYTHONEXECUTABLE is not
416416 # explicitly set and we are not in a virtualenv:
417417 if 'PYTHONEXECUTABLE' not in os.environ and sys.prefix == sys.base_prefix:
418418 sys.executable = sys._base_executable = '#{ opt_bin } /python#{ version . major_minor } '
419419 if 'PYTHONHOME' not in os.environ:
420- cellar_prefix = re.compile(r'#{ rack } /[0-9\\ ._abrc]+/ ')
420+ cellar_prefix = re.compile(r'#{ rack } /[0-9\\ ._abrc]+(?=/|$) ')
421421 if os.path.realpath(sys.base_prefix).startswith('#{ rack } '):
422- new_prefix = cellar_prefix.sub('#{ opt_prefix } / ', sys.base_prefix)
422+ new_prefix = cellar_prefix.sub('#{ opt_prefix } ', sys.base_prefix)
423423 site.PREFIXES[:] = [new_prefix if x == sys.base_prefix else x for x in site.PREFIXES]
424424 if sys.prefix == sys.base_prefix:
425425 sys.prefix = new_prefix
426426 sys.base_prefix = new_prefix
427427 if os.path.realpath(sys.base_exec_prefix).startswith('#{ rack } '):
428- new_exec_prefix = cellar_prefix.sub('#{ opt_prefix } / ', sys.base_exec_prefix)
428+ new_exec_prefix = cellar_prefix.sub('#{ opt_prefix } ', sys.base_exec_prefix)
429429 site.PREFIXES[:] = [new_exec_prefix if x == sys.base_exec_prefix else x for x in site.PREFIXES]
430430 if sys.exec_prefix == sys.base_exec_prefix:
431431 sys.exec_prefix = new_exec_prefix
@@ -499,6 +499,11 @@ def caveats
499499
500500 system bin /"pip#{ version . major_minor } " , "list" , "--format=columns"
501501
502+ # Check our sitecustomize.py
503+ assert_match HOMEBREW_CELLAR . to_s , shell_output ( "#{ python3 } -Sc 'import sys; print(sys.base_prefix)'" )
504+ refute_match HOMEBREW_CELLAR . to_s , shell_output ( "#{ python3 } -c 'import sys; print(sys.base_prefix)'" )
505+ refute_match site_packages_cellar . to_s , shell_output ( "#{ python3 } -c 'import sys; print(sys.path)'" )
506+
502507 # Verify our sysconfig patches
503508 sysconfig_path = "import sysconfig; print(sysconfig.get_paths(\" osx_framework_library\" )[\" data\" ])"
504509 assert_equal HOMEBREW_PREFIX . to_s , shell_output ( "#{ python3 } -c '#{ sysconfig_path } '" ) . strip
0 commit comments