# Maintainer: Andreas 'Segaja' Schleifer <segaja at archlinux dot org>
# Maintainer: Robin Candau <antiz@archlinux.org>

pkgname='pre-commit'
pkgver=4.6.0
pkgrel=1
pkgdesc="A framework for managing and maintaining multi-language pre-commit hooks"
url="https://github.com/pre-commit/pre-commit"
license=('MIT')
arch=('any')
depends=(
  python-cfgv
  python-identify
  python-nodeenv
  python-toml
  python-virtualenv
  python-yaml
)
makedepends=(
  python-build
  python-installer
  python-wheel
)
checkdepends=(
  cabal-install
  git
  ghc
  go
  julia
  luarocks
  nodejs
  npm
  python-pytest
  python-pytest-env
  python-re-assert
  r
  rubygems
  rust
)
provides=(
  python-pre-commit
)
replaces=(
  python-pre-commit
)
source=("https://github.com/pre-commit/pre-commit/archive/v$pkgver/$pkgname-$pkgver.tar.gz")
sha512sums=('50cb895695dd7a8be34217cc1fbcc74273fded1c96888bf31f7128ae47b2836dbe699d596515781b78ba1923c7085719796271b3b7dc5fa8caa6461acc95a7c0')
b2sums=('a1ea166dacc9c7d62a026b04b56c092fdc60a4683ed9bc1d1ea25721440043c6d974af48912d3e9e7871477eacb753992d4fca4ee3d16696de18ae39fbfab932')

build() {
  cd pre-commit-$pkgver
  python -m build --wheel --no-isolation
}

check() {
  cd pre-commit-$pkgver
  export GIT_CONFIG_GLOBAL="$HOME/.gitconfig"
  git init
  git config user.email "pony@arch"
  git config user.name "Lucky Pony"
  git config --global protocol.file.allow always
  export GIT_AUTHOR_NAME="Lucky Pony"
  export GIT_COMMITTER_NAME="Lucky Pony"
  export GIT_AUTHOR_EMAIL="pony@arch"
  export GIT_COMMITTER_EMAIL="pony@arch"
  export VIRTUALENV_NO_DOWNLOAD=1
  export PRE_COMMIT_NO_CONCURRENCY=1

  # Empty venv so that `importlib` picks up the local "pre-commit" package
  python -m venv --system-site-packages venv
  source "$PWD/venv/bin/activate"
  python setup.py develop

  # Deselect conda because we don't have it!
  # Deselect coursier because we don't have it!
  # Deselect dart because it doesn't support 3.x.x!
  # Deselect swift because we don't have it!
  # test_install_ruby_with_version,test_run_a_ruby_hook: https://github.com/pre-commit/pre-commit/issues/1368
  python -m pytest --deselect tests/languages/conda_test.py \
                   --deselect tests/languages/coursier_test.py \
                   --deselect tests/languages/dart_test.py \
                   --deselect tests/languages/docker_image_test.py \
                   --deselect tests/languages/docker_test.py \
                   --deselect tests/languages/dotnet_test.py \
                   --deselect tests/languages/haskell_test.py::test_run_dep \
                   --deselect tests/languages/haskell_test.py::test_run_example_executable \
                   --deselect tests/languages/swift_test.py \
                   --deselect tests/languages/ruby_test.py::test_install_ruby_with_version \
                   --deselect tests/languages/ruby_test.py::test_ruby_hook_language_version \
                   --deselect tests/languages/ruby_test.py::test_ruby_with_bundle_disable_shared_gems \
                   --deselect tests/languages/rust_test.py::test_language_version_with_rustup \
                   --deselect tests/languages/lua_test.py::test_lua_additional_dependencies
  deactivate
}

package() {
  cd pre-commit-$pkgver
  python setup.py install --root="$pkgdir" --optimize=1

  install -Dm644 LICENSE -t "$pkgdir"/usr/share/licenses/$pkgname/
}
