homebrew-core/Formula/sip.rb

92 lines
3.2 KiB
Ruby

class Sip < Formula
include Language::Python::Virtualenv
desc "Tool to create Python bindings for C and C++ libraries"
homepage "https://www.riverbankcomputing.com/software/sip/intro"
url "https://files.pythonhosted.org/packages/f8/b2/fcd5e964eefce0737512fb4ea263308769c671c3b1b9b1e380a5008ffef0/sip-6.1.1.tar.gz"
sha256 "52d25af2fcd764c4e15cc9cd1350bdb0e63f52dfa2aa3c5e7679af7fde9f7e20"
license any_of: ["GPL-2.0-only", "GPL-3.0-only"]
head "https://www.riverbankcomputing.com/hg/sip", using: :hg
bottle do
sha256 cellar: :any_skip_relocation, arm64_big_sur: "6520df3269907002172ccb7991771fcb5fb6d00148f82914b0e6761352aa2ae1"
sha256 cellar: :any_skip_relocation, big_sur: "3edb9829de62236f7846d7080ca433849e88c2b3efc00030464e33a55a378dc0"
sha256 cellar: :any_skip_relocation, catalina: "7167e8060df4b6144b2852bf3893854d6ee0c9c2f4ba6101ff7f60e718f57b98"
sha256 cellar: :any_skip_relocation, mojave: "b1cde0dc289c7cb45614808eeb567bfaa820360eeee87b76cbde3adb2d8b7f76"
sha256 cellar: :any_skip_relocation, x86_64_linux: "d68d3d0da661e632122a6aeca9483947b056838f216f95b9902d05693f3a7137"
end
depends_on "python@3.9"
resource "packaging" do
url "https://files.pythonhosted.org/packages/86/3c/bcd09ec5df7123abcf695009221a52f90438d877a2f1499453c6938f5728/packaging-20.9.tar.gz"
sha256 "5b327ac1320dc863dca72f4514ecc086f31186744b84a230374cc1fd776feae5"
end
resource "pyparsing" do
url "https://files.pythonhosted.org/packages/c1/47/dfc9c342c9842bbe0036c7f763d2d6686bcf5eb1808ba3e170afdb282210/pyparsing-2.4.7.tar.gz"
sha256 "c203ec8783bf771a155b207279b9bccb8dea02d8f0c9e5f8ead507bc3246ecc1"
end
resource "toml" do
url "https://files.pythonhosted.org/packages/be/ba/1f744cdc819428fc6b5084ec34d9b30660f6f9daaf70eead706e3203ec3c/toml-0.10.2.tar.gz"
sha256 "b3bda1d108d5dd99f4a20d24d9c348e91c4db7ab1b749200bded2f839ccbe68f"
end
def install
python = Formula["python@3.9"]
venv = virtualenv_create(libexec, python.bin/"python3")
resources.each do |r|
venv.pip_install r
end
system python.bin/"python3", *Language::Python.setup_install_args(prefix)
site_packages = Language::Python.site_packages(python)
pth_contents = "import site; site.addsitedir('#{libexec/site_packages}')\n"
(prefix/site_packages/"homebrew-sip.pth").write pth_contents
end
test do
(testpath/"pyproject.toml").write <<~EOS
# Specify sip v6 as the build system for the package.
[build-system]
requires = ["sip >=6, <7"]
build-backend = "sipbuild.api"
# Specify the PEP 566 metadata for the project.
[tool.sip.metadata]
name = "fib"
EOS
(testpath/"fib.sip").write <<~EOS
// Define the SIP wrapper to the (theoretical) fib library.
%Module(name=fib, language="C")
int fib_n(int n);
%MethodCode
if (a0 <= 0)
{
sipRes = 0;
}
else
{
int a = 0, b = 1, c, i;
for (i = 2; i <= a0; i++)
{
c = a + b;
a = b;
b = c;
}
sipRes = b;
}
%End
EOS
system "sip-install", "--target-dir", "."
end
end