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.18.2.tar.gz" sha256 "7b017afb989c6f2e2f4072ae84a9aeace02f9db2e3f826bf5e1852adf59c1d13" bottle do cellar :any_skip_relocation sha256 "00a00b5256f7bd060072646f3af662deb2279326118ba8e35ea21966cf140e88" => :mojave sha256 "6380d092f11836cd73ed22c51dd70bb5996ce902d0d2939f2b4f77705553805b" => :high_sierra sha256 "e0478101f4b51a80e95b8b4ed78fee007b9e11b14a53b71873e7dce53a9b457e" => :sierra end depends_on "python" 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 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