@@ -10,38 +10,47 @@ 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+ odie "Need exactly 2 python dependencies!" if pythons . count != 2
22+ oldest_python , python = pythons . sort_by ( &:version )
23+ python_exe = python . opt_libexec /"bin/python"
24+ system python_exe , "-m" , "pip" , "install" , *std_pip_args , "."
25+
26+ # Pure python setuptools installation can be used on different Python versions
27+ site_packages = prefix /Language ::Python . site_packages ( python_exe )
28+ python . versioned_formulae . each do |extra_python |
29+ next if extra_python . version < oldest_python . version
30+
31+ # Cannot use Python.site_packages as that requires formula to be installed
32+ extra_site_packages = lib /"python#{ extra_python . version . major_minor } /site-packages"
33+ site_packages . find do |path |
34+ next unless path . file?
35+
36+ target = extra_site_packages /path . relative_path_from ( site_packages )
37+ target . dirname . install_symlink path
38+ end
3939 end
40+
41+ # Ensure uniform bottles
42+ setuptools_site_packages = site_packages /"setuptools"
43+ inreplace_files = %W[
44+ #{ setuptools_site_packages } /_distutils/compilers/C/unix.py
45+ #{ setuptools_site_packages } /_vendor/platformdirs/unix.py
46+ ] + setuptools_site_packages . glob ( "_vendor/platformdirs-*dist-info/METADATA" )
47+ inreplace inreplace_files , "/usr/local" , HOMEBREW_PREFIX
48+ inreplace setuptools_site_packages /"_vendor/platformdirs/macos.py" , "/opt/homebrew" , HOMEBREW_PREFIX
4049 end
4150
4251 test do
4352 pythons . each do |python |
44- system python , "-c" , "import setuptools"
53+ system python . opt_libexec / "bin/python" , "-c" , "import setuptools"
4554 end
4655 end
4756end
0 commit comments