{% set version = "1.21.5" %}

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

source:
  url: https://github.com/numpy/numpy/releases/download/v{{ version }}/numpy-{{ version }}.tar.gz
  sha256: 1a7ee0ffb35dc7489aebe5185a483f4c43b0d2cf784c3c9940f975a7dde56506
  patches:
    - patches/0001-Obtain-and-prefer-custom-gfortran-from-env-variable.patch
    - patches/0002-intel_mkl-version.patch              # [blas_impl == "mkl"]
    - patches/0003-intel_init_mkl.patch                 # [blas_impl == "mkl"]
    - patches/0004-disable-autorun-for-cmd-test.patch   # [win]
    - patches/0005-array_coercion_fix.patch             # [blas_impl == "mkl" and win]
    - patches/0006-popcnt_fix.patch                     # [blas_impl == "mkl" and win]

build:
  number: 1
  # numpy 1.20.0 no longer supports Python 3.6: https://numpy.org/doc/stable/release/1.20.0-notes.html
  # "The Python versions supported for this release are 3.7-3.9, support for Python 3.6 has been dropped"
  skip: True  # [(blas_impl == 'openblas' and win) or py2k or py<37]
  force_use_keys:
    - python

requirements:
  build:
    - patch     # [not win]
    - m2-patch  # [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  # [win]
      missing_dso_whitelist:  # [s390x]
        - $RPATH/ld64.so.1    # [s390x]
    requirements:
      build:
        - {{ compiler('c') }}
        - {{ compiler('cxx') }}
        - armpl  # [aarch64]
      host:
        - python
        - pip
        - cython >=0.29.21
        - setuptools <60.0.0
        - mkl-devel  {{ mkl }}  # [blas_impl == "mkl"]
        - openblas-devel {{ openblas }}  # [blas_impl == "openblas"]
      run:
        - python
    # 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' %}
    test:
      commands:
        - test -e $SP_DIR/numpy/distutils/site.cfg     # [unix]
        - IF NOT EXIST %SP_DIR%\numpy\distutils\site.cfg exit 1  # [win]

  # 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]
    requirements:
      build:
        # for runtime alignment
        - {{ compiler('c') }}
        - {{ compiler('cxx') }}
        - armpl  # [aarch64]
      host:
        - python
        - setuptools <60.0.0
        # 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)]
        # - mkl_umath  # [blas_impl == 'mkl']
    {% endif %}
    {% set tests_to_skip = "_not_a_real_test" %}
    # Seems to fail with current version of blas for large numbers
    # https://github.com/conda-forge/numpy-feedstock/pull/179#issuecomment-569591828
    {% set tests_to_skip = tests_to_skip + " or test_sincos_float32" %}  # [linux64]
    # Flawed test when using MKL
    # https://github.com/numpy/numpy/issues/16769
    {% set tests_to_skip = tests_to_skip + " or test_overrides" %}  # [blas_impl == 'mkl']
    # Only the complex256 system is failing, but I don't know how to skip it on its own
    # https://github.com/numpy/numpy/issues/15243
    {% set tests_to_skip = tests_to_skip + " or test_loss_of_precision" %}  # [ppc64le or aarch64 or s390x]
    # see: https://github.com/numpy/numpy/issues/20637
    # failure to raise FloatingPointError on osx for reciprocal
    {% set tests_to_skip = tests_to_skip + " or test_unary_PyUFunc_O_O_method_full[reciprocal]" %}  # [osx]
    # Arrays are not equal?:
    # E            x: array(2.236068, dtype=float32)
    # E            y: array(2.236068, dtype=float32)
    {% set tests_to_skip = tests_to_skip + " or test_scalar_coercion_same_as_cast_and_assignment[float32]" %} # [ppc64le]
    {% set tests_to_skip = tests_to_skip + " or test_memory_store" %} # [ppc64le]
    # any test that uses `sys.executable` has a chance to fail...
    # this seems to be the related cause: https://github.com/conda/conda/issues/8305
    # essentially older kernel versions + overlayfs = chance for corruption?
    {% set tests_to_skip = tests_to_skip + " or test_sdot_bug_8577" %}          # [ppc64le or s390x]
    {% set tests_to_skip = tests_to_skip + " or test_import_lazy_import" %}     # [ppc64le or s390x]
    {% set tests_to_skip = tests_to_skip + " or test_full_reimport" %}          # [ppc64le or s390x]
    {% set tests_to_skip = tests_to_skip + " or test_pep338" %}                 # [ppc64le or s390x]
    {% set tests_to_skip = tests_to_skip + " or test_no_typing_extensions" %}   # [ppc64le or s390x]

    test:
      requires:
        - pip     # force installation or `test_api_importable` will fail
        - setuptools <60.0.0
        - pytest
        - hypothesis
        - {{ compiler('c') }}  # [not osx]
        - {{ compiler('cxx') }}  # [not osx]
        - {{ compiler('fortran') }}  # [not osx]
        - nomkl  # [x86 and blas_impl != 'mkl']
      commands:
        - f2py -h
        - python -c "import numpy; numpy.show_config()"
        - export OPENBLAS_NUM_THREADS=1  # [unix]
        - set OPENBLAS_NUM_THREADS=1  # [win]
        - pytest -vvv --pyargs numpy -k "not ({{ tests_to_skip }})" --durations=0
      imports:
        - numpy
        - numpy.linalg.lapack_lite

about:
  home: https://numpy.org/
  license: BSD-3-Clause
  license_file: LICENSE.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://docs.scipy.org/doc/numpy/reference/
  dev_url: https://github.com/numpy/numpy
  dev_source_url: https://github.com/numpy/numpy/tree/master/doc

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