{% set name = "keras" %}
{% set version = "3.4.1" %}

package:
  name: keras
  version: {{ version }}

source:
  url: https://github.com/keras-team/keras/archive/refs/tags/v{{ version }}.tar.gz
  sha256: fc36516fe8eb807480948385bc1ec3b6ebc64fdd963b645ff763d6e30ad72f66
  patches:
    # https://github.com/keras-team/keras/pull/19956
    - patches/19956_pytorch_2.3_compatibility.patch

build:
  number: 0
  script: {{ PYTHON }} -m pip install . --no-deps --ignore-installed --no-build-isolation -v
  skip: true  # [py<39]

requirements:
  build:
    - m2-patch  # [win]
    - patch     # [unix]
  host:
    - python
    - pip
    - wheel
    - setuptools
  run:
    - python
    - absl-py
    - numpy
    - rich
    - namex
    - h5py
    - optree
    - ml_dtypes
    - packaging
  run_constrained:
    # https://github.com/keras-team/keras/blob/v{{ version }}/requirements.txt
    - tensorflow >=2.17.0,<3.0a
    - jax >=0.4.23,<0.5.0a
    # pytorch should have >=2.1.0,<2.3.0 (GitHub issue #19602)
    # a simple >=2.1.0 lower bound is used with a patch.
    - pytorch >=2.1.0
    - torchvision >=0.16.0

test:
  source_files:
    - conftest.py
    - pyproject.toml
    - integration_tests
  requires:
    - pip
    - jax  # [not (win or s390x)]
    - pytorch
    - pytest
  commands:
    - pip check
    # numpy is checked as backend in exports and contest (pytest tests configuration)
    # although not listed in the README among the backends. We add a quick test here.
    #
    # numpy import jax in source code which causes test to fail for win
    - python -c "import os; os.environ['KERAS_BACKEND'] = 'numpy'; import keras;"  # [not (win or s390x)]
    - python -c "import os; os.environ['KERAS_BACKEND'] = 'jax'; import keras;"    # [not (win or s390x)]
    - python -c "import os; os.environ['KERAS_BACKEND'] = 'torch'; import keras;"
    # the imports section is moved down here so that
    # we can set the backend to torch (tensorflow is
    # the default one, but not available at the moment
    # with the right version)
    - set KERAS_BACKEND=torch     # [win]
    - export KERAS_BACKEND=torch  # [not win]
    - python -c "import keras;"
    - python -c "import keras.backend;"
    - python -c "import keras.datasets;"
    - python -c "import keras.layers;"
    - python -c "import keras.utils;"
    - pytest integration_tests/torch_workflow_test.py
    - set KERAS_BACKEND=     # [win]
    - export KERAS_BACKEND=  # [not win]

about:
  home: https://github.com/keras-team/keras
  license: Apache-2.0
  license_family: Apache
  license_file: LICENSE
  summary: Deep Learning for humans
  description: |
    Keras 3 is a multi-backend deep learning framework, with support for JAX, 
    TensorFlow, and PyTorch. Effortlessly build and train models for computer 
    vision, natural language processing, audio processing, timeseries forecasting, 
    recommender systems, etc.
  doc_url: https://keras.io/
  dev_url: https://github.com/keras-team/keras

extra:
  recipe-maintainers:
    - ericdill
    - mariusvniekerk
    - croth1
    - ocefpaf
    - jjhelmus
  skip-lints:
    # The imports section is moved down to the commands
    - missing_imports_or_run_test_py