{% set version = "1.13.1" %}

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

source:
  - url: https://github.com/scipy/scipy/releases/download/v{{ version }}/scipy-{{ version }}.tar.gz
    sha256: 095a87a0312b08dfd6a6155cbbd310a8c51800fc931b8c0b84003014b874ed3c
    patches:                                                     # [s390x]
      - patches/0002-arff-nodata-test-remove-endian-check.patch  # [s390x]

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
    - git     # [osx and x86_64]
  host:
    - python
    - cython >=3.0.8,<3.1.0
    - pybind11 >=2.12.0,<2.13.0
    - pybind11-abi
    - pythran >=0.14.0,<0.16.0
    - meson-python >=0.15.0,<0.18.0
    - python-build
    # see: https://github.com/scipy/scipy/blob/v1.13.1/pyproject.toml#L28-L34
    - numpy 1.23 # [py<311]
    - numpy {{ numpy }} # [py>=311]
    - pip
    - mkl-devel  {{ mkl }}  # [blas_impl == 'mkl']
    - openblas-devel {{ openblas }}  # [blas_impl == 'openblas']
  run:
    - python
    # see explanation of numpy bounds here
    # https://github.com/scipy/scipy/blob/v1.13.1/pyproject.toml#L28-L34
    # https://github.com/scipy/scipy/blob/v1.13.1/pyproject.toml#L55
    # code compiled against numpy 1 is incompatible with numpy 2 ABI
    # code compiled against numpy 2 can work with numpy 1
    - {{ pin_compatible('numpy', upper_bound='1.29') }}

{% 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] or test_x0_equals_Mb[nonsymposdef-bicgstab]" %} # [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' and linux]

# 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
{% set tests_to_skip = tests_to_skip + " or test_tgsyl" %}  # [osx and x86_64 and blas_impl == 'openblas'] See: https://github.com/scipy/scipy/pull/18571, could potentially be fixed with openblas 0.3.23

# skip failing win-64 tests - fortran related regression, from switching to meson
# see https://github.com/scipy/scipy/issues/17075
{% set tests_to_skip = tests_to_skip + " or TestODR" %}  # [win]
{% set tests_to_skip = tests_to_skip + " or test_hermitian_modes" %}  # [win]
{% set tests_to_skip = tests_to_skip + " or test_complex_nonsymmetric_modes" %}  # [win]
{% set tests_to_skip = tests_to_skip + " or test_standard_nonsymmetric_starting_vector" %}  # [win]
{% set tests_to_skip = tests_to_skip + " or test_general_nonsymmetric_starting_vector" %}  # [win]

# skip failing win-64 tests - propack/arpack issues
# see https://github.com/scipy/scipy/issues/15108
{% set tests_to_skip = tests_to_skip + " or test_svd_linop or test_svdp or test_examples" %}  # [win]                                                                                                      

# skip failing mkl tests
# see https://github.com/scipy/scipy/issues/20470
{% set tests_to_skip = tests_to_skip + " or test_nnls_inner_loop_case1" %} # [blas_impl == 'mkl']

# flaky test observerd on multiple platforms
# see https://github.com/scipy/scipy/issues/18880
{% set tests_to_skip = tests_to_skip + " or test_expm_multiply_dtype[True-float32-float32]" %}

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           (until gmpy2 2.2 is released)
    - threadpoolctl
    - pooch
    - hypothesis >=6.30
    - array-api-strict
    # see comment above
    - intel-openmp {{ mkl }}  # [blas_impl == 'mkl']
    # output of numpy.show_config()
    - pyyaml
  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 + ")', '-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_fail = "extra_argv=['-k', '(" + tests_to_skip + ")', '-n', '3', '--timeout=1800', '--durations=50']" %}
    - python -c "import scipy, sys; scipy.test({{ param_fail }}, {{ extra_fail }}); sys.exit(0)"

about:
  home: https://scipy.org/
  license_family: BSD
  license: BSD-3-Clause AND MIT AND BSD-3-Clause-Attribution AND BSD-2-Clause AND BSL-1.0
  license_file:
    - LICENSE.txt
    - LICENSES_bundled.txt
    - scipy/ndimage/LICENSE.txt
    - scipy/optimize/tnc/LICENSE
    - scipy/optimize/_direct/COPYING
    - scipy/io/_fast_matrix_market/LICENSE.txt
    - scipy/io/_fast_matrix_market/fast_matrix_market/dependencies/fast_float/LICENSE-MIT
    - scipy/io/_fast_matrix_market/fast_matrix_market/dependencies/ryu/LICENSE-Boost
    - scipy/_lib/boost_math/LICENSE
    - scipy/_lib/_uarray/LICENSE
    - scipy/_lib/array_api_compat/LICENSE
    - scipy/_lib/pocketfft/LICENSE.md
    - scipy/_lib/unuran/license.txt
    - scipy/_lib/highs/LICENSE
    - scipy/_lib/highs/extern/pdqsort/license.txt
    - scipy/_lib/highs/extern/filereaderlp/LICENSE
    - scipy/fft/_pocketfft/LICENSE.md
    - scipy/sparse/linalg/_eigen/arpack/ARPACK/COPYING
    - scipy/sparse/linalg/_propack/PROPACK/license.txt
    - scipy/sparse/linalg/_dsolve/SuperLU/License.txt
    - scipy/spatial/qhull_src/COPYING.txt
    - scipy/stats/biasedurn/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

