class Numpy < Formula desc "Package for scientific computing with Python" homepage "http://www.numpy.org" url "https://files.pythonhosted.org/packages/c0/3a/40967d9f5675fbb097ffec170f59c2ba19fc96373e73ad47c2cae9a30aed/numpy-1.13.1.zip" sha256 "c9b0283776085cb2804efff73e9955ca279ba4edafd58d3ead70b61d209c4fbb" bottle do cellar :any_skip_relocation sha256 "963ecb45478f316c9d49f55c8ab992d507d30d269e3e07e34bee173635cdb719" => :sierra sha256 "c2199387028b12a362b932d56034f85622390b157fb38d15a6f55630154dca5b" => :el_capitan sha256 "ec1ab3efd6464564d52997653cc9274e4baf14d56f066b40720fbf5fdfce13cb" => :yosemite end head do url "https://github.com/numpy/numpy.git" resource "Cython" do url "https://files.pythonhosted.org/packages/b7/67/7e2a817f9e9c773ee3995c1e15204f5d01c8da71882016cac10342ef031b/Cython-0.25.2.tar.gz" sha256 "f141d1f9c27a07b5a93f7dc5339472067e2d7140d1c5a9e20112a5665ca60306" end end option "without-python", "Build without python2 support" depends_on :fortran => :build depends_on :python => :recommended if MacOS.version <= :snow_leopard depends_on :python3 => :optional resource "nose" do url "https://files.pythonhosted.org/packages/58/a5/0dc93c3ec33f4e281849523a5a913fa1eea9a3068acfa754d44d88107a44/nose-1.3.7.tar.gz" sha256 "f1bffef9cbc82628f6e7d7b40d7e255aefaa1adb6a1b1d26c69a8b79e6208a98" end def install Language::Python.each_python(build) do |python, version| dest_path = lib/"python#{version}/site-packages" dest_path.mkpath nose_path = libexec/"nose/lib/python#{version}/site-packages" resource("nose").stage do system python, *Language::Python.setup_install_args(libexec/"nose") (dest_path/"homebrew-numpy-nose.pth").write "#{nose_path}\n" end if build.head? ENV.prepend_create_path "PYTHONPATH", buildpath/"tools/lib/python#{version}/site-packages" resource("Cython").stage do system python, *Language::Python.setup_install_args(buildpath/"tools") end end system python, "setup.py", "build", "--fcompiler=gnu95", "--parallel=#{ENV.make_jobs}", "install", "--prefix=#{prefix}", "--single-version-externally-managed", "--record=installed.txt" end end def caveats if build.with?("python") && !Formula["python"].installed? homebrew_site_packages = Language::Python.homebrew_site_packages user_site_packages = Language::Python.user_site_packages "python" <<-EOS.undent If you use system python (that comes - depending on the OS X version - with older versions of numpy, scipy and matplotlib), you may need to ensure that the brewed packages come earlier in Python's sys.path with: mkdir -p #{user_site_packages} echo 'import sys; sys.path.insert(1, "#{homebrew_site_packages}")' >> #{user_site_packages}/homebrew.pth EOS end end test do system "python", "-c", <<-EOS.undent import numpy as np t = np.ones((3,3), int) assert t.sum() == 9 assert np.dot(t, t).sum() == 27 EOS end end