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.9.0.tar.gz" sha256 "1357414213525e9e91bc2d8ecbf33121a4f75d208232f8ef6d328a28955d6e05" bottle do cellar :any_skip_relocation sha256 "885e366d63d8eb829a7c8031e6b3936c3089183fa21ca2eef527fa5e89ae67c7" => :high_sierra sha256 "724e6d580fcea30b176a9c771abfb33f6080ad7eaff94f072bad94a8bf164e02" => :sierra sha256 "ae7b7b9ef9b1c6460b997e41fb62abf80906ade43aed920b0ec2e28f2983bd47" => :el_capitan end depends_on "python" 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