language/python: fix virtualenv symlinks for versioned Python

This commit is contained in:
Bo Anderson 2020-03-10 14:17:30 +00:00
parent b6812d2dfb
commit 2594e7093e

View File

@ -220,14 +220,21 @@ module Language
next unless f.symlink?
next unless (rp = f.realpath.to_s).start_with? HOMEBREW_CELLAR
new_target = rp.sub %r{#{HOMEBREW_CELLAR}/python/[^/]+}, Formula["python"].opt_prefix
version = rp.match %r{^#{HOMEBREW_CELLAR}/python@(.*?)/}
version = "@#{version.captures.first}" unless version.nil?
new_target = rp.sub %r{#{HOMEBREW_CELLAR}/python#{version}/[^/]+}, Formula["python#{version}"].opt_prefix
f.unlink
f.make_symlink new_target
end
Pathname.glob(@venv_root/"lib/python*/orig-prefix.txt").each do |prefix_file|
prefix_path = prefix_file.read
prefix_path.sub! %r{^#{HOMEBREW_CELLAR}/python/[^/]+}, Formula["python"].opt_prefix
version = prefix_path.match %r{^#{HOMEBREW_CELLAR}/python@(.*?)/}
version = "@#{version.captures.first}" unless version.nil?
prefix_path.sub! %r{^#{HOMEBREW_CELLAR}/python#{version}/[^/]+}, Formula["python#{version}"].opt_prefix
prefix_file.atomic_write prefix_path
end
end