61 lines
1.9 KiB
Ruby
61 lines
1.9 KiB
Ruby
class PreCommit < Formula
|
|
include Language::Python::Virtualenv
|
|
|
|
desc "Framework for managing multi-language pre-commit hooks"
|
|
homepage "https://pre-commit.com/"
|
|
url "https://github.com/pre-commit/pre-commit/archive/v1.21.0.tar.gz"
|
|
sha256 "9cdc791bfad86b3648a5801518bbfb3ad7cb66f74a4681b10d8dd34d4032cb59"
|
|
revision 1
|
|
|
|
bottle do
|
|
cellar :any_skip_relocation
|
|
sha256 "e91d7afb101e474e4a064e61a04fcd428bf620dfeeb41749389f130a4fa83da1" => :catalina
|
|
sha256 "de1c5a3a4f924145edbab2e705280a92ea6491b1e6485af3b299aa1bd5ece1fd" => :mojave
|
|
sha256 "f2976d6b3e6a5443638d32f44de261e9615fdaf780f1270cfe2c11762819a597" => :high_sierra
|
|
end
|
|
|
|
depends_on "python@3.8"
|
|
|
|
def install
|
|
venv = virtualenv_create(libexec, "python3")
|
|
system libexec/"bin/pip", "install", "-v", "--no-binary", ":all:",
|
|
"--ignore-installed", "PyYAML==3.13b1", 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
|
|
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
|