Skip to content

Commit 0206b14

Browse files
committed
python-setuptool: build once and symlink
1 parent dc6db63 commit 0206b14

File tree

1 file changed

+26
-21
lines changed

1 file changed

+26
-21
lines changed

Formula/p/python-setuptools.rb

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,38 +10,43 @@ class PythonSetuptools < Formula
1010
sha256 cellar: :any_skip_relocation, all: "90d1373d4b921632e3da896be98326b463867c0a4f9e742c6a98c09caae96fd7"
1111
end
1212

13-
depends_on "[email protected]" => [:build, :test]
14-
depends_on "[email protected]" => [:build, :test]
1513
depends_on "[email protected]" => [:build, :test]
14+
depends_on "[email protected]" => :test # keep on oldest python to support (externally managed and not EOL)
1615

1716
def pythons
18-
deps.map(&:to_formula)
19-
.select { |f| f.name.match?(/^python@\d\.\d+$/) }
20-
.map { |f| f.opt_libexec/"bin/python" }
17+
deps.filter_map { |dep| dep.to_formula if dep.name.start_with?("python@") }
2118
end
2219

2320
def install
24-
inreplace_paths = %w[
25-
_distutils/compilers/C/unix.py
26-
_vendor/platformdirs/unix.py
27-
]
28-
29-
pythons.each do |python|
30-
system python, "-m", "pip", "install", *std_pip_args, "."
31-
32-
# Ensure uniform bottles
33-
setuptools_site_packages = prefix/Language::Python.site_packages(python)/"setuptools"
34-
inreplace setuptools_site_packages/"_vendor/platformdirs/macos.py", "/opt/homebrew", HOMEBREW_PREFIX
35-
36-
inreplace_files = inreplace_paths.map { |file| setuptools_site_packages/file }
37-
inreplace_files += setuptools_site_packages.glob("_vendor/platformdirs-*dist-info/METADATA")
38-
inreplace inreplace_files, "/usr/local", HOMEBREW_PREFIX
21+
oldest_python, python = pythons.sort_by(&:version)
22+
python_exe = python.opt_libexec/"bin/python"
23+
system python_exe, "-m", "pip", "install", *std_pip_args, "."
24+
25+
# Pure python setuptools installation can be used on different Python versions
26+
site_packages = prefix/Language::Python.site_packages(python_exe)
27+
python.versioned_formulae.each do |extra_python|
28+
next if extra_python.version < oldest_python.version
29+
30+
# Cannot use Python.site_packages as that requires formula to be installed
31+
extra_site_packages = lib/"python#{extra_python.version.major_minor}/site-packages"
32+
site_packages.find do |path|
33+
(extra_site_packages/path.relative_path_from(site_packages)).dirname.install_symlink path if path.file?
34+
end
3935
end
36+
37+
# Ensure uniform bottles
38+
setuptools_site_packages = site_packages/"setuptools"
39+
inreplace_files = %W[
40+
#{setuptools_site_packages}/_distutils/compilers/C/unix.py
41+
#{setuptools_site_packages}/_vendor/platformdirs/unix.py
42+
] + setuptools_site_packages.glob("_vendor/platformdirs-*dist-info/METADATA")
43+
inreplace inreplace_files, "/usr/local", HOMEBREW_PREFIX
44+
inreplace setuptools_site_packages/"_vendor/platformdirs/macos.py", "/opt/homebrew", HOMEBREW_PREFIX
4045
end
4146

4247
test do
4348
pythons.each do |python|
44-
system python, "-c", "import setuptools"
49+
system python.opt_libexec/"bin/python", "-c", "import setuptools"
4550
end
4651
end
4752
end

0 commit comments

Comments
 (0)