{% set version = "2.1.3" %}
# numpy will by default use the ABI feature level for the first numpy version
# that added support for the oldest currently-supported CPython version; see
# https://github.com/numpy/numpy/blob/v2.1.1/numpy/_core/include/numpy/numpyconfig.h#L125
{% set default_abi_level = "1.21" %}

package:
  name: numpy_and_numpy_base
  version: {{ version }}

source:
  - url: https://github.com/numpy/numpy/releases/download/v{{ version }}/numpy-{{ version }}.tar.gz
    sha256: aa08e04e08aaf974d4458def539dece0d28146d866a39da5639596f4921fd761
    patches:                                                # [blas_impl == "mkl" or s390x]
      - patches/0003-intel_init_mkl.patch                   # [blas_impl == "mkl"]
      - patches/0004-Partially-revert-function-blocklisting-for-glibc-lt-2.18.patch # [s390x]

build:
  number: 0
  # numpy 2.1.3 no longer supports Python 3.9: https://numpy.org/devdocs/release/2.1.3-notes.html
  skip: True  # [(blas_impl == 'openblas' and win)]
  skip: True  # [py<310 or py>=314]
  force_use_keys:
    - python

requirements:
  build:
    - patch     # [(blas_impl == "mkl" or s390x) and not win]
    - m2-patch  # [(blas_impl == "mkl") and win]

outputs:
  # this one has all the actual contents
  - name: numpy-base
    script: install_base.sh   # [unix]
    script: install_base.bat  # [win]
    build:
      entry_points:
        - f2py = numpy.f2py.f2py2e:main
        - numpy-config = numpy._configtool:main
      missing_dso_whitelist:  # [s390x]
        - $RPATH/ld64.so.1    # [s390x]
    requirements:
      build:
        - {{ compiler('c') }}
        - {{ compiler('cxx') }}
        - armpl  # [aarch64]
        - ninja-base
        - pkg-config
      host:
        - python
        - pip
        - cython >=3.0.6
        - meson-python >=0.15.0
        - python-build
        # blas
        - mkl-devel  {{ mkl }}  # [blas_impl == "mkl"]
        - openblas-devel {{ openblas }}  # [blas_impl == "openblas"]
      run:
        - python
      run_constrained:
        # restrict setuptools: see https://github.com/numpy/numpy/issues/27405
        # TODO remove when numpy stop using distutils.msvccompiler from setuptools. 
        - setuptools <74

  # When building out the initial package set for a new Python version / MKL version the
  # recommendation is to build numpy-base but not numpy, then build
  # mkl_fft and mkl_random, and then numpy.
  # If only_build_numpy_base: "yes build numpy-base only; otherwise build all the outputs.
  {% if only_build_numpy_base != 'yes' %}
  # numpy is a metapackage that may include mkl_fft and mkl_random both of
  # which require numpy-base to build
  - name: numpy
    build:
      missing_dso_whitelist:  # [s390x]
        - $RPATH/ld64.so.1    # [s390x]
      run_exports:
        - numpy >={{ default_abi_level }},<3
    requirements:
      build:
        # for runtime alignment
        - {{ compiler('c') }}
        - {{ compiler('cxx') }}
        - armpl  # [aarch64]
      host:
        - python
        # these import blas metapackages to ensure consistency with downstream libs that also use blas
        - mkl-devel  {{ mkl }}  # [blas_impl == 'mkl']
        - openblas-devel {{ openblas }}  # [blas_impl == 'openblas']
      run:
        - python
        - {{ pin_subpackage('numpy-base', exact=True) }}
        # openblas or mkl runtime included with run_exports
        - mkl_fft  # [blas_impl == 'mkl']
        - mkl_random # [blas_impl == 'mkl' and (not win or vc>=14)]
      run_constrained:
        # restrict setuptools: see https://github.com/numpy/numpy/issues/27405
        # TODO remove when numpy stop using distutils.msvccompiler from setuptools. 
        - setuptools <74
    {% endif %}

    {% set tests_to_skip = "_not_a_real_test" %}

    # https://github.com/numpy/numpy/issues/3858 - could be related
    {% set tests_to_skip = tests_to_skip + " or test_big_arrays" %}  # [s390x]
    # https://github.com/numpy/numpy/issues/16046
    {% set tests_to_skip = tests_to_skip + " or test_gcd_overflow" %}  # [s390x]
    # skip simd tests because vxe2 feature is not detected when running from prefect
    {% set tests_to_skip = tests_to_skip + " or test_features" %}  # [s390x]
    # https://github.com/numpy/numpy/issues/27313 - can be removed with clang >=16 update
    {% set tests_to_skip = tests_to_skip + " or (test_unary_spurious_fpexception and (f-cos or f-sin))" %}  # [osx and arm64]


    test:
      requires:
        - pip
        - pytest >=7.4.0
        - pytest-cov >=4.1.0
        - pytest-xdist
        # due to hotfix this is the only hypothesis version that works with numpy 2.0.0 and above
        - hypothesis >=6.111.0
        - pytz >=2023.3.post1
        - {{ compiler('c') }}  # [not osx]
        - {{ compiler('cxx') }}  # [not osx]
        - {{ compiler('fortran') }}  # [not osx]
        - nomkl  # [x86 and blas_impl != 'mkl']
        - typing-extensions >=4.2.0
        - mypy >=1.7.1
        - cffi  # [py<310]
        - charset-normalizer
        - meson
      commands:
        - f2py -h
        - python -c "import numpy; numpy.show_config()"
        - export OPENBLAS_NUM_THREADS=1  # [unix]
        - set OPENBLAS_NUM_THREADS=1  # [win]
        - export CPU_COUNT=4  # [linux and ppc64le]
        - pytest -vv --pyargs numpy -k "not ({{ tests_to_skip }})" --durations=50 --durations-min=1.0
      imports:
        - numpy
        - numpy.core.multiarray
        - numpy.core.numeric
        - numpy.core.umath
        - numpy.linalg.lapack_lite
        - numpy.random.mtrand
        # from numpy/tests/test_public_api.py
        - numpy.ctypeslib
        - numpy.dtypes
        - numpy.exceptions
        - numpy.f2py
        - numpy.fft
        - numpy.lib
        - numpy.lib.array_utils
        - numpy.lib.format
        - numpy.lib.introspect
        - numpy.lib.mixins
        - numpy.lib.npyio
        - numpy.lib.recfunctions # note: still needs cleaning, was forgotten for 2.0
        - numpy.lib.scimath
        - numpy.lib.stride_tricks
        - numpy.linalg
        - numpy.ma
        - numpy.ma.extras
        - numpy.ma.mrecords
        - numpy.polynomial
        - numpy.polynomial.chebyshev
        - numpy.polynomial.hermite
        - numpy.polynomial.hermite_e
        - numpy.polynomial.laguerre
        - numpy.polynomial.legendre
        - numpy.polynomial.polynomial
        - numpy.random
        - numpy.strings
        - numpy.testing
        - numpy.testing.overrides
        - numpy.typing
        - numpy.typing.mypy_plugin
        - numpy.version

about:
  home: https://numpy.org/
  license: BSD-3-Clause
  license_family: BSD
  license_file:
    - LICENSE.txt
    - LICENSES_bundled.txt
  summary: Array processing for numbers, strings, records, and objects.
  description: |
    NumPy is the fundamental package needed for scientific computing with Python.
  doc_url: https://numpy.org/doc/stable/reference/
  dev_url: https://github.com/numpy/numpy

extra:
  recipe-maintainers:
    - jakirkham
    - msarahan
    - pelson
    - rgommers
    - ocefpaf
    - chenghlee
