forked from codedreality/homebrew-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scipy.rb
115 lines (99 loc) · 4.31 KB
/
scipy.rb
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
111
112
113
114
115
class Scipy < Formula
desc "Software for mathematics, science, and engineering"
homepage "http://www.scipy.org"
url "https://github.com/scipy/scipy/releases/download/v0.18.1/scipy-0.18.1.tar.xz"
sha256 "406d4e2dec5e46ad9f2ab08620174d064d3b5aab987591d1acd77eda846bd95e"
head "https://github.com/scipy/scipy.git"
bottle do
sha256 "4b434a8f8433bcbac8bc40902048d360dd3f6718002c6e349b589f1163da5cbb" => :sierra
sha256 "53564b2c4601a6d8992cba091a76830e3062871eb552d285f7883ae5b22567f7" => :el_capitan
sha256 "cab73e270ffb38a4ba93a45c5e196561d7ff0de79cc1cd00a49872241a78bb32" => :yosemite
end
option "without-python", "Build without python2 support"
depends_on "swig" => :build
depends_on :python => :recommended if MacOS.version <= :snow_leopard
depends_on :python3 => :optional
depends_on :fortran
option "with-check", "Run tests"
option "with-openblas", "Use openblas instead of Apple's Accelerate framework " \
"(required to build with gcc on OS X)"
depends_on "homebrew/science/openblas" => (OS.mac? ? :optional : :recommended)
numpy_options = []
numpy_options << "with-python3" if build.with? "python3"
numpy_options << "with-openblas" if build.with? "openblas"
depends_on "homebrew/python/numpy" => numpy_options
cxxstdlib_check :skip
# https://github.com/Homebrew/homebrew-python/issues/110
# There are ongoing problems with gcc+accelerate.
fails_with :gcc if OS.mac? && build.without?("openblas")
def install
# https://github.com/numpy/numpy/issues/4203
# https://github.com/Homebrew/homebrew-python/issues/209
# https://github.com/Homebrew/homebrew-python/issues/233
if OS.linux?
ENV.append "FFLAGS", "-fPIC"
ENV.append "LDFLAGS", "-shared"
end
config = <<-EOS.undent
[DEFAULT]
library_dirs = #{HOMEBREW_PREFIX}/lib
include_dirs = #{HOMEBREW_PREFIX}/include
EOS
if build.with? "openblas"
# For maintainers:
# Check which BLAS/LAPACK numpy actually uses via:
# xcrun otool -L $(brew --prefix)/Cellar/scipy/<version>/lib/python2.7/site-packages/scipy/linalg/_flinalg.so
# or the other .so files.
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
end
Pathname("site.cfg").write config
# gfortran is gnu95
Language::Python.each_python(build) do |python, version|
ENV["PYTHONPATH"] = Formula["numpy"].opt_lib/"python#{version}/site-packages"
ENV.prepend_create_path "PYTHONPATH", lib/"python#{version}/site-packages"
system python, "setup.py", "build", "--fcompiler=gnu95"
system python, *Language::Python.setup_install_args(prefix)
if build.with?("check") || build.bottle?
cd ".." do
tmpdir = buildpath/"homebrew-scratch"
tmpdir.mkpath
ENV["TMPDIR"] = tmpdir
system python, "-c", "import scipy; assert scipy.test().wasSuccessful()"
end
end
end
end
# cleanup leftover .pyc files from previous installs which can cause problems
# see https://github.com/Homebrew/homebrew-python/issues/185#issuecomment-67534979
def post_install
Language::Python.each_python(build) do |_python, version|
rm_f Dir["#{HOMEBREW_PREFIX}/lib/python#{version}/site-packages/scipy/**/*.pyc"]
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", "import scipy"
end
end