# Maintainer: Caleb Maclennan <caleb@alerque.com>
# Contributor: Felix Yan <felixonmars@archlinux.org>
# Contributor: Yaron de Leeuw <me@jarondl.net>

_pyname=isort
pkgname=python-$_pyname
pkgver=7.0.0
pkgrel=1
pkgdesc='A Python utility / library to sort Python imports'
arch=(any)
url="https://github.com/PyCQA/$_pyname"
license=(MIT)
_pydeps=(colorama
         setuptools
         tomli)
depends=(python
         "${_pydeps[@]/#/python-}")
makedepends=(python-{build,installer,wheel}
             python-hatch-vcs
             python-hatchling)
_pycheckdeps=(black
              hypothesis
              hypothesis-auto
              hypothesmith
              libcst
              natsort
              pytest
              pytest-mock
              requirementslib)
_archive="$_pyname-$pkgver"
source=("https://files.pythonhosted.org/packages/source/${_pyname::1}/$_pyname/$_archive.tar.gz")
sha256sums=('5513527951aadb3ac4292a41a16cbc50dd1642432f5e8c20057d414bdafb4187')

prepare() {
	cd "$_archive"

	# Devendor toml
	rm -r isort/_vendored
	sed -i 's/from ._vendored //' isort/settings.py

	## Skipping example integration tests
	# for _plugin in example_*; do
	#     pushd $_plugin
	#     dephell deps convert --from pyproject.toml --to setup.py
	#     popd
	# done
}

build() {
	cd "$_archive"
	python -m build -wn
}

# check() {
#     cd "$_archive"
#     ## Skipping example integration tests
#     # python setup.py install --root="$PWD/tmp_install" --optimize=1
#     # for _plugin in example_*; do
#     #     pushd $_plugin
#     #     python setup.py install --root="$srcdir/isort-$pkgver/tmp_install" --optimize=1
#     #     popd
#     # done
#     # PYTHONPATH="$PWD/example_isort_formatting_plugin:$PWD/example_shared_isort_profile:$PWD/tmp_install/usr/lib/python3.11/site-packages" PATH="$PWD/tmp_install/usr/bin:$PATH" \
#     python -m pytest -p no:warnings \
#         --deselect tests/unit/test_deprecated_finders.py::TestRequirementsFinder::test_requirements_dir $(: having pip in ruins other tests ) \
#         --deselect tests/unit/test_deprecated_finders.py::test_requirements_finder $(: having pip in ruins other tests ) \
#         --deselect tests/unit/test_deprecated_finders.py::test_pipfile_finder $(: having pip in ruins other tests ) \
#         --deselect tests/unit/test_isort.py::test_settings_path_skip_issue_909 $(: example integrations ) \
#         --deselect tests/unit/test_isort.py::test_skip_paths_issue_938 $(: example integrations ) \
#         --deselect tests/unit/test_ticketed_features.py::test_isort_supports_shared_profiles_issue_970 $(: example integrations ) \
#         --deselect tests/unit/test_literal.py::test_value_assignment_list $(: unknown) \
#         --deselect tests/unit/test_ticketed_features.py::test_isort_supports_formatting_plugins_issue_1353 $(: unknown) \
#         --deselect tests/unit/test_ticketed_features.py::test_isort_literals_issue_1358 $(: unknown ) \
#         --deselect tests/unit/test_ticketed_features.py::test_sort_configurable_sort_issue_1732 $(: unknown ) \
#         --deselect tests/integration/test_setting_combinations.py $(: unknown ) \
#         --deselect tests/integration/test_projects_using_isort.py::test_typeshed $(: requires network ) \
#         --deselect tests/test_importable.py::test_importable $(: just weird ) \
#         --deselect tests/benchmark/test_api.py $(: no benchmarks thanks )
# }

package() {
	cd "$_archive"
	python -m installer -d "$pkgdir" dist/*.whl
	rm -f "$pkgdir"/usr/lib/python*/site-packages/{LICENSE,CHANGELOG.md}
	install -Dm0644 -t "$pkgdir/usr/share/licenses/$pkgname/" LICENSE
}
