language/python: avoid modifying all Python symlinks

Homebrew Python will always have a realpath in HOMEBREW_CELLAR. Instead,
check if the symlink target points to HOMEBREW_CELLAR.
This commit is contained in:
Michael Cho 2024-08-22 19:19:17 -04:00
parent 4482e25cb2
commit 0e8db0155a
No known key found for this signature in database
GPG Key ID: 55E85E28A7CD1E85

View File

@ -330,8 +330,9 @@ module Language
# Robustify symlinks to survive python patch upgrades
@venv_root.find do |f|
next unless f.symlink?
next unless (rp = f.realpath.to_s).start_with? HOMEBREW_CELLAR
next unless f.readlink.expand_path.to_s.start_with? HOMEBREW_CELLAR
rp = f.realpath.to_s
version = rp.match %r{^#{HOMEBREW_CELLAR}/python@(.*?)/}o
version = "@#{version.captures.first}" unless version.nil?