forked from derekbrokeit/homebrew-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnumpy.rb
More file actions
110 lines (95 loc) · 3.86 KB
/
Copy pathnumpy.rb
File metadata and controls
110 lines (95 loc) · 3.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
class Numpy < Formula
desc "Package for scientific computing with Python"
homepage "http://www.numpy.org"
url "https://files.pythonhosted.org/packages/e0/4c/515d7c4ac424ff38cc919f7099bf293dd064ba9a600e1e3835b3edefdb18/numpy-1.11.1.tar.gz"
sha256 "dc4082c43979cc856a2bf352a8297ea109ccb3244d783ae067eb2ee5b0d577cd"
head "https://github.com/numpy/numpy.git"
bottle do
cellar :any_skip_relocation
sha256 "714347847f02820ee7c921589180b7ce39f608f9215e9e3cb4de12934ad2dd66" => :el_capitan
sha256 "1b09b4fefd131daf662cc79c3fa0247dc84385f2d8949a5967fc05325f2505d7" => :yosemite
sha256 "36425c6621f82a9090ef84b165ec33df88d4d92f5b8cdbaa05143c31be756933" => :mavericks
end
option "without-python", "Build without python2 support"
depends_on :python => :recommended if MacOS.version <= :snow_leopard
depends_on :python3 => :optional
depends_on :fortran => :build
option "without-check", "Don't run tests during installation"
option "with-openblas", "Use openBLAS instead of Apple's Accelerate Framework"
depends_on "homebrew/science/openblas" => (OS.mac? ? :optional : :recommended)
resource "nose" do
url "https://pypi.python.org/packages/source/n/nose/nose-1.3.7.tar.gz"
sha256 "f1bffef9cbc82628f6e7d7b40d7e255aefaa1adb6a1b1d26c69a8b79e6208a98"
end
def install
# https://github.com/numpy/numpy/issues/4203
# https://github.com/Homebrew/homebrew-python/issues/209
ENV.append "LDFLAGS", "-shared" if OS.linux?
if build.with? "openblas"
openblas_dir = Formula["openblas"].opt_prefix
# Setting ATLAS to None is important to prevent numpy from always
# linking against Accelerate.framework.
ENV["ATLAS"] = "None"
ENV["BLAS"] = ENV["LAPACK"] = "#{openblas_dir}/lib/libopenblas.dylib"
config = <<-EOS.undent
[openblas]
libraries = openblas
library_dirs = #{openblas_dir}/lib
include_dirs = #{openblas_dir}/include
EOS
(buildpath/"site.cfg").write config
end
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
system python, "setup.py",
"build", "--fcompiler=gnu95", "--parallel=#{ENV.make_jobs}",
"install", "--prefix=#{prefix}",
"--single-version-externally-managed", "--record=installed.txt"
if build.with? "check"
cd HOMEBREW_TEMP do
with_environment({
"PYTHONPATH" => "#{dest_path}:#{nose_path}",
"PATH" => "#{bin}:#{ENV["PATH"]}"}) do
system python, "-c", "import numpy; assert numpy.test().wasSuccessful()"
end
end
end
end
end
def with_environment(h)
old = Hash[h.keys.map { |k| [k, ENV[k]] }]
ENV.update h
begin
yield
ensure
ENV.update old
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