language/python: reduce some differences between macOS and Linux venv

This commit is contained in:
Michael Cho 2024-08-22 21:06:35 -04:00
parent 4482e25cb2
commit 36dc83c9e4
No known key found for this signature in database
GPG Key ID: 55E85E28A7CD1E85

View File

@ -350,6 +350,18 @@ module Language
prefix_file.atomic_write prefix_path prefix_file.atomic_write prefix_path
end end
# Reduce some differences between macOS and Linux venv
lib64 = @venv_root/"lib64"
lib64.make_symlink "lib" unless lib64.exist?
if (cfg_file = @venv_root/"pyvenv.cfg").exist?
cfg = cfg_file.read
framework = "Frameworks/Python.framework/Versions"
cfg.match(%r{= *(#{HOMEBREW_CELLAR}/(python@[\d.]+)/[^/]+(?:/#{framework}/[\d.]+)?/bin)}) do |match|
cfg.sub! match[1].to_s, Formula[match[2]].opt_bin
cfg_file.atomic_write cfg
end
end
# Remove unnecessary activate scripts # Remove unnecessary activate scripts
(@venv_root/"bin").glob("[Aa]ctivate*").map(&:unlink) (@venv_root/"bin").glob("[Aa]ctivate*").map(&:unlink)
end end