62 lines
2 KiB
Ruby
62 lines
2 KiB
Ruby
class PreCommit < Formula
|
|
include Language::Python::Virtualenv
|
|
|
|
desc "Framework for managing multi-language pre-commit hooks"
|
|
homepage "http://pre-commit.com/"
|
|
url "https://github.com/pre-commit/pre-commit/archive/v1.4.1.tar.gz"
|
|
sha256 "cc908bc0ca5f77cdb6d05d090f9b09a18514de8c82dfea3b8edffda06871f0e6"
|
|
revision 2
|
|
|
|
bottle do
|
|
cellar :any
|
|
sha256 "6ce01b3582cdac192722fc52a9135d47d2aa3d9ad7a5f19dc0db3f4962d7d54a" => :high_sierra
|
|
sha256 "3dd6b7f41975da40839c6e8f5523033c40a57970d12f4a7c662ccb832e7b6c29" => :sierra
|
|
sha256 "98b2d42774e8f63150e04f073ea3bcc53c1d3d00d5a43f858fb076c254c8715a" => :el_capitan
|
|
end
|
|
|
|
depends_on :python3
|
|
|
|
def install
|
|
venv = virtualenv_create(libexec, "python3")
|
|
system libexec/"bin/pip", "install", "-v", "--no-binary", ":all:",
|
|
"--ignore-installed", buildpath
|
|
system libexec/"bin/pip", "uninstall", "-y", "pre-commit"
|
|
venv.pip_install_and_link buildpath
|
|
end
|
|
|
|
# Avoid relative paths
|
|
def post_install
|
|
lib_python_path = Pathname.glob(libexec/"lib/python*").first
|
|
lib_python_path.each_child do |f|
|
|
next unless f.symlink?
|
|
realpath = f.realpath
|
|
rm f
|
|
ln_s realpath, f
|
|
end
|
|
inreplace lib_python_path/"orig-prefix.txt",
|
|
Formula["python3"].opt_prefix, Formula["python3"].prefix.realpath
|
|
end
|
|
|
|
test do
|
|
testpath.cd do
|
|
system "git", "init"
|
|
(testpath/".pre-commit-config.yaml").write <<~EOS
|
|
- repo: https://github.com/pre-commit/pre-commit-hooks
|
|
sha: v0.9.1
|
|
hooks:
|
|
- id: trailing-whitespace
|
|
EOS
|
|
system bin/"pre-commit", "install"
|
|
(testpath/"f").write "hi\n"
|
|
system "git", "add", "f"
|
|
|
|
ENV["GIT_AUTHOR_NAME"] = "test user"
|
|
ENV["GIT_AUTHOR_EMAIL"] = "test@example.com"
|
|
ENV["GIT_COMMITTER_NAME"] = "test user"
|
|
ENV["GIT_COMMITTER_EMAIL"] = "test@example.com"
|
|
git_exe = which("git")
|
|
ENV["PATH"] = "/usr/bin:/bin"
|
|
system git_exe, "commit", "-m", "test"
|
|
end
|
|
end
|
|
end
|