From d579a60445c9082badfd962ce53b87cce240f0e9 Mon Sep 17 00:00:00 2001 From: Amar1729 Date: Sun, 24 Sep 2023 08:28:52 -0400 Subject: [PATCH 1/7] libcython: extract at 0.29.30 --- libcython@0.29.30.rb | 52 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 libcython@0.29.30.rb diff --git a/libcython@0.29.30.rb b/libcython@0.29.30.rb new file mode 100644 index 0000000..ec2e92a --- /dev/null +++ b/libcython@0.29.30.rb @@ -0,0 +1,52 @@ +class LibcythonAT02930 < Formula + desc "Compiler for writing C extensions for the Python language" + homepage "https://cython.org/" + url "https://files.pythonhosted.org/packages/d4/ad/7ce0cccd68824ac9623daf4e973c587aa7e2d23418cd028f8860c80651f5/Cython-0.29.30.tar.gz" + sha256 "2235b62da8fe6fa8b99422c8e583f2fb95e143867d337b5c75e4b9a1a865f9e3" + license "Apache-2.0" + + livecheck do + formula "cython" + end + + keg_only <<~EOS + this formula is mainly used internally by other formulae. + Users are advised to use `pip` to install cython + EOS + + depends_on "python@3.10" => [:build, :test] + depends_on "python@3.9" => [:build, :test] + + def pythons + deps.map(&:to_formula) + .select { |f| f.name.match?(/python@\d\.\d+/) } + .map(&:opt_bin) + .map { |bin| bin/"python3" } + end + + def install + pythons.each do |python| + ENV.prepend_create_path "PYTHONPATH", libexec/Language::Python.site_packages(python) + system python, *Language::Python.setup_install_args(libexec), + "--install-lib=#{libexec/Language::Python.site_packages(python)}" + end + end + + test do + phrase = "You are using Homebrew" + (testpath/"package_manager.pyx").write "print '#{phrase}'" + (testpath/"setup.py").write <<~EOS + from distutils.core import setup + from Cython.Build import cythonize + + setup( + ext_modules = cythonize("package_manager.pyx") + ) + EOS + pythons.each do |python| + ENV.prepend_path "PYTHONPATH", libexec/Language::Python.site_packages(python) + system python, "setup.py", "build_ext", "--inplace" + assert_match phrase, shell_output("#{python} -c 'import package_manager'") + end + end +end From d85a8a02eb675f6eff4e21b853742b4523885f6f Mon Sep 17 00:00:00 2001 From: Amar1729 Date: Sun, 24 Sep 2023 08:29:43 -0400 Subject: [PATCH 2/7] libcython: restrict to python@3.9 --- libcython@0.29.30.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libcython@0.29.30.rb b/libcython@0.29.30.rb index ec2e92a..da74d4f 100644 --- a/libcython@0.29.30.rb +++ b/libcython@0.29.30.rb @@ -14,14 +14,14 @@ class LibcythonAT02930 < Formula Users are advised to use `pip` to install cython EOS - depends_on "python@3.10" => [:build, :test] + # depends_on "python@3.10" => [:build, :test] depends_on "python@3.9" => [:build, :test] def pythons deps.map(&:to_formula) .select { |f| f.name.match?(/python@\d\.\d+/) } .map(&:opt_bin) - .map { |bin| bin/"python3" } + .map { |bin| bin/"python3.9" } end def install From 26b0b9328b140964958fea5b5703c131560e73ea Mon Sep 17 00:00:00 2001 From: Amar1729 Date: Sun, 24 Sep 2023 08:30:03 -0400 Subject: [PATCH 3/7] numpy: extract at 1.23.3 --- numpy@1.23.3.rb | 58 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 numpy@1.23.3.rb diff --git a/numpy@1.23.3.rb b/numpy@1.23.3.rb new file mode 100644 index 0000000..e36cd6b --- /dev/null +++ b/numpy@1.23.3.rb @@ -0,0 +1,58 @@ +class NumpyAT1233 < Formula + desc "Package for scientific computing with Python" + homepage "https://www.numpy.org/" + url "https://files.pythonhosted.org/packages/0a/88/f4f0c7a982efdf7bf22f283acf6009b29a9cc5835b684a49f8d3a4adb22f/numpy-1.23.3.tar.gz" + sha256 "51bf49c0cd1d52be0a240aa66f3458afc4b95d8993d2d04f0d91fa60c10af6cd" + license "BSD-3-Clause" + head "https://github.com/numpy/numpy.git", branch: "main" + + depends_on "gcc" => :build # for gfortran + depends_on "libcython" => :build + depends_on "python@3.10" => [:build, :test] + depends_on "python@3.9" => [:build, :test] + depends_on "openblas" + + fails_with gcc: "5" + + def pythons + deps.map(&:to_formula) + .select { |f| f.name.match?(/^python@\d\.\d+$/) } + .sort_by(&:version) # so that `bin/f2py` and `bin/f2py3` use python3.10 + .map { |f| f.opt_libexec/"bin/python" } + end + + def install + openblas = Formula["openblas"] + ENV["ATLAS"] = "None" # avoid linking against Accelerate.framework + ENV["BLAS"] = ENV["LAPACK"] = openblas.opt_lib/shared_library("libopenblas") + + config = <<~EOS + [openblas] + libraries = openblas + library_dirs = #{openblas.opt_lib} + include_dirs = #{openblas.opt_include} + EOS + + Pathname("site.cfg").write config + + pythons.each do |python| + site_packages = Language::Python.site_packages(python) + ENV.prepend_path "PYTHONPATH", Formula["libcython"].opt_libexec/site_packages + + system python, "setup.py", "build", "--fcompiler=#{Formula["gcc"].opt_bin}/gfortran", + "--parallel=#{ENV.make_jobs}" + system python, *Language::Python.setup_install_args(prefix, python) + end + end + + test do + pythons.each do |python| + system python, "-c", <<~EOS + import numpy as np + t = np.ones((3,3), int) + assert t.sum() == 9 + assert np.dot(t, t).sum() == 27 + EOS + end + end +end From c1b5574fde3b525a613e49039c47d400cdcbd5ec Mon Sep 17 00:00:00 2001 From: Amar1729 Date: Sun, 24 Sep 2023 08:30:48 -0400 Subject: [PATCH 4/7] numpy: depend on this tap's libcython, restrict to python3.9 --- numpy@1.23.3.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/numpy@1.23.3.rb b/numpy@1.23.3.rb index e36cd6b..317401e 100644 --- a/numpy@1.23.3.rb +++ b/numpy@1.23.3.rb @@ -7,8 +7,8 @@ class NumpyAT1233 < Formula head "https://github.com/numpy/numpy.git", branch: "main" depends_on "gcc" => :build # for gfortran - depends_on "libcython" => :build - depends_on "python@3.10" => [:build, :test] + depends_on "mtg/essentia/libcython@0.29.30" => :build + # depends_on "python@3.10" => [:build, :test] depends_on "python@3.9" => [:build, :test] depends_on "openblas" @@ -37,7 +37,7 @@ def install pythons.each do |python| site_packages = Language::Python.site_packages(python) - ENV.prepend_path "PYTHONPATH", Formula["libcython"].opt_libexec/site_packages + ENV.prepend_path "PYTHONPATH", Formula["mtg/essentia/libcython@0.29.30"].opt_libexec/site_packages system python, "setup.py", "build", "--fcompiler=#{Formula["gcc"].opt_bin}/gfortran", "--parallel=#{ENV.make_jobs}" From 7cc86201627d79c5118bcb31d25fa27eda83a600 Mon Sep 17 00:00:00 2001 From: Amar1729 Date: Sun, 24 Sep 2023 12:12:22 -0400 Subject: [PATCH 5/7] essentia: make python version explicit, depend on numpy properly --- essentia.rb | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/essentia.rb b/essentia.rb index 6b6d49a..68b7e93 100644 --- a/essentia.rb +++ b/essentia.rb @@ -20,7 +20,7 @@ class Essentia < Formula option "without-python", "Build without Python 3.9 support" depends_on "python@3.9" if build.with? "python" - depends_on "numpy" if build.with? "python" + depends_on "mtg/essentia/numpy@1.23.3" if build.with? "python" resource "six" do url "https://files.pythonhosted.org/packages/21/9f/b251f7f8a76dec1d6651be194dfba8fb8d7781d10ab3987190de8391d08e/six-1.14.0.tar.gz" @@ -44,9 +44,9 @@ def install build_flags += ["--with-tensorflow"] end - system Formula["python@3.9"].opt_bin/"python3", "waf", "configure", *build_flags - system Formula["python@3.9"].opt_bin/"python3", "waf" - system Formula["python@3.9"].opt_bin/"python3", "waf", "install" + system Formula["python@3.9"].opt_bin/"python3.9", "waf", "configure", *build_flags + system Formula["python@3.9"].opt_bin/"python3.9", "waf" + system Formula["python@3.9"].opt_bin/"python3.9", "waf", "install" python_flags = [ "--mode=release", @@ -58,15 +58,18 @@ def install ENV['PKG_CONFIG_PATH'] = "#{prefix}/lib/pkgconfig:" + ENV['PKG_CONFIG_PATH'] if build.with? "python" - system Formula["python@3.9"].opt_bin/"python3", "waf", "configure", *python_flags - system Formula["python@3.9"].opt_bin/"python3", "waf" - system Formula["python@3.9"].opt_bin/"python3", "waf", "install" + site_packages = Language::Python.site_packages(Formula["python@3.9"].opt_libexec/"bin/python") + ENV.prepend_create_path "PYTHONPATH", Formula["mtg/essentia/numpy@1.23.3"].opt_prefix/site_packages + + system Formula["python@3.9"].opt_bin/"python3.9", "waf", "configure", *python_flags + system Formula["python@3.9"].opt_bin/"python3.9", "waf" + system Formula["python@3.9"].opt_bin/"python3.9", "waf", "install" resource("six").stage do - system Formula["python@3.9"].opt_bin/"python3", *Language::Python.setup_install_args(libexec) + system Formula["python@3.9"].opt_bin/"python3.9", *Language::Python.setup_install_args(libexec) end - version = Language::Python.major_minor_version Formula["python@3.9"].opt_bin/"python3" + version = Language::Python.major_minor_version Formula["python@3.9"].opt_bin/"python3.9" site_packages = "lib/python#{version}/site-packages" pth_contents = "import site; site.addsitedir('#{libexec/site_packages}')\n" (prefix/site_packages/"homebrew-essentia.pth").write pth_contents @@ -85,7 +88,7 @@ def install EOS if build.with? "python" - system Formula["python@3.9"].opt_bin/"python3", "-c", "#{py_test}" + system Formula["python@3.9"].opt_bin/"python3.9", "-c", "#{py_test}" end end end From d027e2a82073f7a3e7946715f487b3d9cc5abce0 Mon Sep 17 00:00:00 2001 From: Amar1729 Date: Sun, 24 Sep 2023 12:32:44 -0400 Subject: [PATCH 6/7] numpy: conflicts_with numpy, add caveats --- numpy@1.23.3.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/numpy@1.23.3.rb b/numpy@1.23.3.rb index 317401e..dbbdb15 100644 --- a/numpy@1.23.3.rb +++ b/numpy@1.23.3.rb @@ -12,6 +12,8 @@ class NumpyAT1233 < Formula depends_on "python@3.9" => [:build, :test] depends_on "openblas" + conflicts_with "numpy", because: "both install f2py and other binaries" + fails_with gcc: "5" def pythons @@ -45,6 +47,26 @@ def install end end + def caveats + on_macos do + <<-EOS + This formula technically conflicts with the current Homebrew + version of `numpy`, as they both provide binaries. However, + the only result is that this formula can't be fully linked. + + Since essentia only requires numpy's python bindings, there are + a few solutions (you only need to do one of the following): + + 1. `brew uninstall numpy` (easiest, only if you have no formulae that depend on numpy) + 2. `brew unlink numpy`, then install this formula + 3. If you need to keep `numpy` linked after installing this, you must run the + following to use this version of numpy when calling python3.9: + + export PYTHONPATH="#{opt_prefix/Language::Python.site_packages(Formula["python@3.9"].opt_libexec/"bin/python")}" + EOS + end + end + test do pythons.each do |python| system python, "-c", <<~EOS From c1b6e2de4d0d33adfb02482602abab381c2661df Mon Sep 17 00:00:00 2001 From: Amar1729 Date: Sun, 24 Sep 2023 12:55:41 -0400 Subject: [PATCH 7/7] essentia: bump revision to force user rebuilds (short-term) after fix --- essentia.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/essentia.rb b/essentia.rb index 68b7e93..4c37fa7 100644 --- a/essentia.rb +++ b/essentia.rb @@ -2,6 +2,7 @@ class Essentia < Formula desc "Library for audio analysis and audio-based music information retrieval" homepage "http://essentia.upf.edu" head 'https://github.com/MTG/essentia.git' + revision 1 include Language::Python::Virtualenv