{% set version = "1.11.1" %}

package:
  name: scipy
  version: {{ version }}

source:
  - url: https://github.com/scipy/scipy/archive/refs/tags/v{{ version }}.tar.gz
    sha256: 2605c91a4d00ea77838ecb6db2fcf4e71199f402ff0fd8e80d4ae80bfe0ac80e
    patches:                                                     # [s390x]
      - patches/0002-arff-nodata-test-remove-endian-check.patch  # [s390x]
  # https://github.com/scipy/scipy/tree/v{{ version }}/scipy/_lib
  - url: https://github.com/boostorg/math/archive/298a243ccd3639b6eaa59bcdab7ab9d5f008fb36.tar.gz
    sha256: 119d92c145f0d5a56b0faae3d68088de77ad1fcce803fde1ea9ca6692ae9f1f8
    folder: scipy/_lib/boost_math
  - url: https://github.com/scipy/HiGHS/archive/4a122958a82e67e725d08153e099efe4dad099a2.tar.gz
    sha256: 8ce0e816d8c7517c95e0e404648eef3aaee0d5b919226b46f592c87a4eca24f4
    folder: scipy/_lib/highs
  - url: https://github.com/scipy/unuran/archive/81a1fd118b326880e00cc7d8989fb063782a6bdd.tar.gz
    sha256: f08642f4e54f59c03cb828fa10b13e8b6921cde8a62d41dfd71d797b6e29564b
    folder: scipy/_lib/unuran
  # https://github.com/scipy/scipy/tree/v{{ version }}/scipy/sparse/linalg/_propack
  - url: https://github.com/scipy/PROPACK/archive/96f6800451372dd003e627bbfd732937ac0c685e.tar.gz
    sha256: a90cd12cf35dabc119442a868573c602893d255b27bb0d8e912552537a39d1c9
    folder: scipy/sparse/linalg/_propack/PROPACK

build:
  number: 0
  skip: true  # [py<39]
  missing_dso_whitelist:  # [linux and s390x]
    - $RPATH/ld64.so.1    # [linux and s390x] 
  ignore_run_exports:
    - numpy

requirements:
  build:
    - {{ compiler('c') }}
    - {{ compiler('cxx') }}
    # pythran code needs clang-cl on windows
    - clang   # [win]
    - lld     # [win]
    - {{ compiler('fortran') }}
    - patch   # [s390x]
    - pkg-config
  host:
    - python
    - cython >=0.29.35,<3.0
    - pybind11 >=2.10.4,<2.11.0
    - pythran >=0.12.0,<0.14.0
    - meson-python >=0.12.1,<0.14.0 # [unix]
    - python-build                  # [unix]
    - setuptools <60                # [win]
    - wheel <0.41.0
    - numpy {{ numpy }}
    - pip
    - mkl-devel  {{ mkl }}  # [blas_impl == 'mkl']
    - openblas-devel {{ openblas }}  # [blas_impl == 'openblas']
  run:
    - python
    # https://github.com/scipy/scipy/blob/v1.11.1/pyproject.toml#L69
    - {{ pin_compatible('numpy', upper_bound='1.28') }}

# Scipy segfault when calling solver PROPACK _svdp at mkl_blas.cdotc (). see: https://github.com/scipy/scipy/issues/15108
# The use of PROPACK is disabled by default on 1.9.0 : see https://github.com/scipy/scipy/pull/16420
# However PROPACK tests themselves are not disabled, so we skip test_propack.py tests.
{% set tests_known_to_crash = "test_svdp or test_examples"%}

{% set tests_to_skip = "_not_a_real_test" %}

# skip a test that fails with MKL + AVX512 (non-AVX512 passes) (See: https://github.com/scipy/scipy/issues/15533)
{% set tests_to_skip = tests_to_skip + " or test_x0_equals_Mb[bicgstab] or test_x0_equals_Mb[bicgstab-nonsymposdef-F]" %} # [blas_impl == 'mkl']

# mark one linalg.solve_discrete_are as knownfail https://github.com/scipy/scipy/issues/16926
{% set tests_to_skip = tests_to_skip + " or test_solve_discrete_are"  %} # [blas_impl == 'openblas']

# skip failing s390x tests
{% set tests_to_skip = tests_to_skip + " or test_jacobi_int" %} # [s390x] timeout after 1800s
{% set tests_to_skip = tests_to_skip + " or test_distance_transform_cdt05" %} # [s390x](See: https://github.com/scipy/scipy/issues/18878)

# skip failing osx-64 tests
# See open issues:
#   - https://github.com/scipy/scipy/issues/17125
{% set tests_to_skip = tests_to_skip + " or test_bad_genei" %}  # [osx and x86_64]

# skip failing osx-arm64 tests
{% set tests_to_skip = tests_to_skip + " or test_roots" %}  # [osx and arm64]

test:
  imports:
    - scipy
    # reference for public API is effectively
    # https://github.com/scipy/scipy/blob/master/scipy/_lib/tests/test_public_api.py
    - scipy.cluster
    - scipy.cluster.hierarchy
    - scipy.cluster.vq
    - scipy.constants
    - scipy.datasets
    - scipy.fft
    - scipy.fftpack
    - scipy.integrate
    - scipy.interpolate
    - scipy.io
    - scipy.io.arff
    - scipy.io.matlab
    - scipy.io.wavfile
    - scipy.linalg
    - scipy.linalg.blas
    - scipy.linalg.cython_blas
    - scipy.linalg.cython_lapack
    - scipy.linalg.interpolative
    - scipy.linalg.lapack
    - scipy.misc
    - scipy.ndimage
    - scipy.odr
    - scipy.optimize
    - scipy.signal
    - scipy.signal.windows
    - scipy.sparse
    - scipy.sparse.csgraph
    - scipy.sparse.linalg
    - scipy.spatial
    - scipy.spatial.distance
    - scipy.spatial.transform
    - scipy.special
    - scipy.stats
    - scipy.stats.contingency
    - scipy.stats.distributions
    - scipy.stats.mstats
    - scipy.stats.qmc
    - scipy.stats.sampling
  requires:
    - pytest
    - pytest-timeout
    - pytest-xdist
    - asv
    - mpmath
    - gmpy2
    - threadpoolctl
    - pooch
    # see comment above
    - intel-openmp {{ mkl }}  # [blas_impl == 'mkl']
  commands:
    # Use OpenBLAS with 1 thread only as it seems to be using too many
    # on the CIs apparently.
    - export OPENBLAS_NUM_THREADS=1 # [ppc64le and blas_impl == 'openblas']

    # Attempt to fix some file number limits when testing on osx.
    - ulimit -n 64000 # [osx]

    # show configuration - required for bug reports to scipy
    - python -c "import sys, scipy, numpy; print(scipy.__version__, numpy.__version__, sys.version_info)"

    # show SIMD features (some failures occur depending on presence/absence of e.g. AVX512)
    - python -c "import numpy; numpy.show_config()"

    # the tests ppc64le and aarch64 are currently run through emulation in QEMU;
    # since this takes much longer, do not run the most heavy-weight tests, i.e. use
    # label='fast'; same for PyPy due to huge runtime; otherwise set label='full'
    {% set label = "'fast'" if (arm64 or aarch64 or ppc64le) else "'full'" %}
    # for signature of scipy.test see below (note default: label='fast'):
    # https://github.com/scipy/scipy/blob/v1.7.0/scipy/_lib/_testutils.py#L27

    # run tests except tests_to_skip
    {% set param = "verbose=1, label=" + label + ", tests=None" %} # set verbose to 2 for additional logs
    {% set extra = "extra_argv=['-k', 'not (" + tests_to_skip + " or " + tests_known_to_crash + ")', '-n', '3', '--timeout=1800', '--durations=50']" %}
    - python -c "import scipy, sys; sys.exit(not scipy.test({{ param }}, {{ extra }}))"

    # run tests_to_skip tests, but ignore results (to keep a record of failures)
    {% set param_fail = "verbose=2, label=" + label + ", tests=None" %}
    {% set extra_crash = "extra_argv=['-k', '(" + tests_known_to_crash + ")', '-n', '3', '--timeout=1800', '--durations=50']" %}
    {% set extra_fail = "extra_argv=['-k', '(" + tests_to_skip + ")', '-n', '3', '--timeout=1800', '--durations=50']" %}
    - python -c "import scipy, sys; scipy.test({{ param_fail }}, {{ extra_crash }}); sys.exit(0)" # [not s390x]
    - python -c "import scipy, sys; scipy.test({{ param_fail }}, {{ extra_fail }}); sys.exit(0)"  # [not s390x]

about:
  home: https://scipy.org/
  license: BSD-3-Clause
  license_family: BSD
  license_file: LICENSE.txt
  summary: Scientific Library for Python
  description: |
    SciPy is a Python-based ecosystem of open-source software for mathematics,
    science, and engineering.
  doc_url: https://docs.scipy.org/doc/scipy/
  dev_url: https://github.com/scipy/scipy

extra:
  recipe-maintainers:
    - jakirkham
    - msarahan
    - rgommers
    - ocefpaf
    - h-vetinari

