Skip to content

Commit af8d6e7

Browse files
aWZHY0yQH81uOYvHthliebig
authored andcommitted
add python bindings to brew formula
1 parent d3c31d2 commit af8d6e7

File tree

2 files changed

+51
-13
lines changed

2 files changed

+51
-13
lines changed

doc-src/install/package.rst

+13-13
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,9 @@ Setup Python Interfaces
8686

8787
- **Optional**: Build Python libraries.
8888

89-
Unfortunately, currently Python modules are not automatically installed,
90-
they need manual installation.
89+
If you install openEMS with Homebrew, the Python libraries will be automatically installed unless `--without-python@3` is passed.
90+
91+
If you prefer to build them manually, follow the following instructions.
9192

9293
First, install the needed dependencies...
9394

@@ -106,21 +107,23 @@ cloned git code:
106107

107108
.. code-block:: console
108109
109-
cd CSXCAD
110-
cd python
111-
pip3 install . --user
110+
cd CSXCAD/python
111+
BREW=$(brew --prefix)
112+
python3 setup.py build_ext -I$BREW/include -L$BREW/lib -R$BREW/lib
113+
python3 setup.py install
112114
113-
cd ..
115+
cd ../..
114116
115117
2. Build openEMS's Python extension:
116118

117119
.. code-block:: console
118120
119-
cd openEMS
120-
cd python
121-
pip3 install . --user
121+
cd openEMS/python
122+
BREW=$(brew --prefix)
123+
python3 setup.py build_ext -I$BREW/include -L$BREW/lib -R$BREW/lib
124+
python3 setup.py install
122125
123-
cd ..
126+
cd ../..
124127
125128
Check Installation
126129
~~~~~~~~~~~~~~~~~~~
@@ -151,8 +154,5 @@ Updating
151154
152155
brew upgrade --fetch-HEAD openems
153156
154-
If Python modules are used, they need to be reinstalled (in case that
155-
a module has been updated).
156-
157157
.. _openEMS_win: https://github.com/thliebig/openEMS-Project/releases
158158
.. _Homebrew: https://brew.sh

openEMS.rb

+38
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
require "formula"
44

55
class Openems < Formula
6+
include Language::Python::Virtualenv
7+
68
desc "Electromagnetic field solver using the FDTD method"
79
homepage "https://www.openems.de"
810

@@ -19,12 +21,48 @@ class Openems < Formula
1921
depends_on "mpfr"
2022
depends_on "cgal"
2123
depends_on "boost"
24+
depends_on "python@3" => :recommended
25+
26+
if build.with? "python@3"
27+
depends_on "cython"
28+
depends_on "numpy"
29+
depends_on "python-matplotlib"
30+
end
2231

2332
def install
2433
ENV["SDKROOT"] = MacOS.sdk_path
2534
system "cmake", ".", *std_cmake_args
2635
system "make"
2736
# install is handled by ExternalProject_Add
37+
38+
if build.with? "python@3"
39+
# Get python 3 sub-version we are currently using (3.x)
40+
python_version = Formula["python@3"].version.to_s.split(".")[0..1].join(".")
41+
python = "python#{python_version}"
42+
43+
# Install non-bottled dependencies into a virtual environment
44+
venv = virtualenv_create(libexec, "python3")
45+
venv.pip_install "h5py"
46+
47+
# Create .pth file to reference packages in venv
48+
(lib/"#{python}/site-packages/homebrew-openems-dependencies.pth").write <<~EOS
49+
#{libexec}/lib/#{python}/site-packages
50+
EOS
51+
52+
# Use keg-only cython
53+
ENV.prepend_path "PYTHONPATH", "#{Formula["cython"].libexec}/lib/#{python}/site-packages"
54+
55+
# Build and install bindings
56+
cd "CSXCAD/python" do
57+
system Formula["python@3"].opt_bin/"python3", "setup.py", "build_ext", "-I", include, "-L", lib, "-R", lib, "-j", ENV.make_jobs
58+
system Formula["python@3"].opt_bin/"python3", *Language::Python.setup_install_args(prefix)
59+
end
60+
61+
cd "openEMS/python" do
62+
system Formula["python@3"].opt_bin/"python3", "setup.py", "build_ext", "-I", include, "-L", lib, "-R", lib, "-j", ENV.make_jobs
63+
system Formula["python@3"].opt_bin/"python3", *Language::Python.setup_install_args(prefix)
64+
end
65+
end
2866
end
2967

3068
end

0 commit comments

Comments
 (0)