# Maintainer: Patrick Stewart <patstew@gmail.com>
# Contributor: dragon-archer <dragon-archer@outlook.com>

_realname=jsonschema
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=4.26.0
pkgrel=1
pkgdesc="An implementation of JSON Schema validation for Python (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://python-jsonschema.readthedocs.io/"
msys2_repository_url="https://github.com/python-jsonschema/jsonschema/"
msys2_changelog_url="https://github.com/python-jsonschema/jsonschema/blob/main/CHANGELOG.rst"
msys2_references=(
  'archlinux: python-jsonschema'
  'gentoo: dev-python/jsonschema'
  'purl: pkg:pypi/jsonschema'
)
license=('spdx:MIT')
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-attrs"
         "${MINGW_PACKAGE_PREFIX}-python-jsonschema-specifications"
         "${MINGW_PACKAGE_PREFIX}-python-rpds-py"
         "${MINGW_PACKAGE_PREFIX}-python-referencing")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-hatchling"
             "${MINGW_PACKAGE_PREFIX}-python-hatch-vcs"
             "${MINGW_PACKAGE_PREFIX}-python-hatch-fancy-pypi-readme")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-pytest"
              "${MINGW_PACKAGE_PREFIX}-python-jsonpath-ng")
options=('!strip')
source=("https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname}-${pkgver}.tar.gz")
sha256sums=('0c26707e2efad8aa1bfc5b7ce170f3fccc2e4918ff85989ba9ffa9facb2be326')

build() {
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}" && cd "python-build-${MSYSTEM}"

  "${MINGW_PREFIX}"/bin/python -m build --wheel --skip-dependency-check --no-isolation
}

check() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  # Needs manual install for metadata resolution
  mkdir _install
  "${MINGW_PREFIX}"/bin/python -m installer --prefix= --destdir=_install dist/*.whl

  cd _install/lib/python*/site-packages/

  # 1 failed, 7389 passed, 425 skipped, test_nonexistent_file_with_explicit_base_uri failed for os.sep difference
  PYTHONPATH=. "${MINGW_PREFIX}"/bin/python -m pytest "${srcdir}/python-build-${MSYSTEM}/jsonschema/tests" || \
    warning "Tests failed."
}

package() {
  cd "${srcdir}/python-build-${MSYSTEM}"

  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
    "${MINGW_PREFIX}"/bin/python -m installer --prefix="${MINGW_PREFIX}" \
    --destdir="${pkgdir}" dist/*.whl

  install -Dm644 json/LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
}
