# Maintainer: Bruno Pagani <archange@archlinux.org>
# Maintainer: Jakub Klinkovský <lahwaacz at archlinux dot org>

_name=distributed
pkgname=python-$_name
pkgver=2025.11.0
pkgrel=1
pkgdesc="Distributed task scheduler for Dask"
arch=(any)
url="https://distributed.dask.org/"
license=(BSD-3-Clause)
depends=(
  python
  python-click
  python-cloudpickle
  python-dask
  python-jinja
  python-locket
  python-msgpack
  python-packaging
  python-psutil
  python-sortedcontainers
  python-tblib
  python-toolz
  python-tornado
  python-urllib3
  python-yaml
  python-zict
)
makedepends=(
  python-build
  python-installer
  python-setuptools
  python-setuptools-scm
  python-wheel
)
checkdepends=(
  ipython
  python-pytest
  python-pytest-repeat
  python-pytest-timeout
  python-pytest-xdist
  python-flaky
  python-blosc
  python-cryptography
  python-fsspec
  python-h5py
  python-ipykernel
  python-ipywidgets
  python-jsonschema
  python-lz4
  python-netcdf4
  python-numpy
  python-pandas
  python-paramiko
  python-prometheus_client
  python-pyarrow
  python-requests
  python-scipy
  python-snappy
  python-zstandard
)
source=(https://github.com/dask/distributed/archive/$pkgver/$pkgname-$pkgver.tar.gz)
b2sums=('0316e7671bc5257528444fc04302ebec9b58b7ea65fcde0fa9f6065b16bf92221dd1ce2e348dad1cfb34e6cb837e6382e786908b050fc309c11b608b4d21e87e')

build() {
  cd $_name-$pkgver
  SETUPTOOLS_SCM_PRETEND_VERSION=$pkgver \
  python -m build --wheel --no-isolation
}

check() {
  local pytest_options=(
    -vv
    --override-ini="addopts="
    -W ignore::DeprecationWarning
    # distribute tests across multiple CPUs
    -n auto
    --dist loadscope
    -m "not avoid_ci and not gpu and not extra_packages"
    --deselect distributed/cli/tests/test_dask_scheduler.py
    --deselect distributed/cli/tests/test_dask_spec.py
    --deselect distributed/cli/tests/test_dask_worker.py
    --deselect distributed/cli/tests/test_tls_cli.py
    --deselect distributed/comm/tests/test_comms.py::test_tls_comm_closed_implicit[tornado]
    --deselect distributed/deploy/tests/test_local.py::test_defaults_5
    --deselect distributed/deploy/tests/test_old_ssh.py  # crashes the test suite
    --deselect distributed/deploy/tests/test_subprocess.py
    --deselect distributed/tests/test_client.py::test_computation_object_code_dask_compute
    --deselect distributed/tests/test_init.py::test_git_revision
    --deselect distributed/tests/test_queues.py::test_queue_in_task
    --deselect distributed/tests/test_steal.py::test_steal_twice
    --deselect distributed/tests/test_variable.py::test_variable_in_task
    --deselect distributed/tests/test_worker_memory.py::test_fail_to_pickle_execute_1
    --deselect distributed/tests/test_active_memory_manager.py::test_RetireWorker_with_actor[True]  # TimeoutError
    # TypeError: _FlakyPlugin._make_test_flaky() got an unexpected keyword argument 'reruns'
    --deselect distributed/comm/tests/test_ws.py
    --deselect distributed/deploy/tests/test_slow_adaptive.py::test_scale_up_down
    --deselect distributed/diagnostics/tests/test_progress.py::test_many_Progress
    --deselect distributed/diagnostics/tests/test_progress.py::test_AllProgress
    --deselect distributed/diagnostics/tests/test_progress.py::test_AllProgress_lost_key
    --deselect distributed/tests/test_client.py::test_profile
    --deselect distributed/tests/test_worker.py::test_statistical_profiling
    # TimeoutError: Test timeout (30) hit after 30.000276130624115s
    --deselect distributed/tests/test_scheduler.py::test_resubmit_nondeterministic_task_different_deps
    # FutureWarning: get_ipv6 is deprecated and will be removed in a future release. Please use get_ip instead.
    --deselect distributed/comm/tests/test_comms.py::test_default_client_server_ipv6[tornado]
    --deselect distributed/comm/tests/test_comms.py::test_tcp_client_server_ipv6[tornado]
    --deselect distributed/deploy/tests/test_local.py::test_only_local_access
    --deselect distributed/deploy/tests/test_local.py::test_remote_access
    --deselect distributed/deploy/tests/test_local.py::test_local_tls[True]
    --deselect distributed/deploy/tests/test_local.py::test_local_tls[False]
    # AssertionError: Regex pattern did not match.
    --deselect distributed/tests/test_queues.py::test_set_cancelled_future
    --deselect distributed/tests/test_scheduler.py::test_restart_not_all_workers_return
  )

  cd $_name-$pkgver
  python -m venv --system-site-packages test-env
  test-env/bin/python -m installer dist/*.whl
  test-env/bin/python -m pytest "${pytest_options[@]}" distributed
}

package() {
  cd $_name-$pkgver
  python -m installer --destdir="$pkgdir" dist/*.whl
  install -vDm 644 LICENSE.txt -t "$pkgdir"/usr/share/licenses/$pkgname/
}
