{% set name = "nbconvert" %}
{% set version = "7.16.6" %}

# from nbconvert/utils/pandoc.py
{% set min_pandoc = "2.9.2" %}
{% set max_pandoc = "4.0.0" %}

{% set build = 0 %}

# skipping test_post_processor and test_convert_full_qualified_name as they expect tests to be a module
{% set pytest_args = "-k \"not (test_post_processor or test_convert_full_qualified_name)\"" %}  # [not win]
# skipping test_convert_explicitly_relative_paths because it tries to access '/home/user/src' on Windows
# skipping test_basic_execution or test_mixed_markdown_execution on win because of RuntimeWarning: Proactor event loop does not implement add_reader family of methods required for zmq.
{% set pytest_args = "-k \"not (test_preprocess_cell or test_populate_language_info or test_executenb or test_post_processor or test_convert_full_qualified_name or test_convert_explicitly_relative_paths or test_basic_execution or test_mixed_markdown_execution)\"" %}  # [win]

# handle undefined PYTHON in `noarch: generic` outputs
{% if PYTHON is not defined %}{% set PYTHON = "$PYTHON" %}{% endif %}

package:
  name: {{ name|lower }}-meta
  version: {{ version }}

source:
  url: https://pypi.io/packages/source/{{ name[0] }}/{{ name }}/{{ name }}-{{ version }}.tar.gz
  sha256: 576a7e37c6480da7b8465eefa66c17844243816ce1ccc372633c6b71c3c0f582

build:
  number: {{ build }}
  # An indirect jupyterlab dependency through ipywidgets -> jupyterlab_widgets
  # isn't available on s390x
  skip: True  #[py<38 or s390x]

requirements:
  host:
    - python
    - pip
  run:
    - python

outputs:
  - name: nbconvert
    requirements:
      host:
        - python
      run:
        - python
        - {{ pin_subpackage("nbconvert-core", exact=True) }}
        - {{ pin_subpackage("nbconvert-pandoc", exact=True) }}
    test:
      requires:
        - pip
      commands:
        - pip check
        - jupyter nbconvert --version
        - jupyter dejavu --version
        - jupyter nbconvert --help
        - jupyter dejavu --help

  - name: nbconvert-core
    build:
      script: {{ PYTHON }} -m pip install . --no-deps --no-build-isolation --ignore-installed --no-cache-dir -vv
      entry_points:
        - jupyter-nbconvert = nbconvert.nbconvertapp:main
        - jupyter-dejavu = nbconvert.nbconvertapp:dejavu_main
    requirements:
      host:
        - python
        - pip
        - hatchling >=1.5
      run:
        - python
        - beautifulsoup4
        - bleach !=5.0.0
        - defusedxml
        - importlib-metadata >=3.6  # [py<310]
        - jinja2 >=3.0
        - jupyter_core >=4.7
        - jupyterlab_pygments
        - markupsafe >=2.0
        - mistune >=2.0.3,<4
        - nbclient >=0.5.0
        - nbformat >=5.7
        - packaging
        - pandocfilters >=1.4.1
        - pygments >=2.4.1
        - traitlets >=5.1
        - tinycss2  # from bleach(css), pinnings follow run_constrained in bleach
      run_constrained:
        - tornado >=6.1
        # other packages carry the full `run` dependency
        - pandoc >={{ min_pandoc }},<{{ max_pandoc }}
        # avoid mixing nbconvert-core and pre-split nbconvert
        # can't mix noarch:generic and noarch:python with exact=True
        - nbconvert ={{ version }}=*_{{ build }}

    test:
      imports:
        - nbconvert
        - nbconvert.exporters
        - nbconvert.filters
        - nbconvert.postprocessors
        - nbconvert.preprocessors
        - nbconvert.resources
        - nbconvert.utils
        - nbconvert.writers
      source_files:
        - tests
      requires:
        - pip
        - ipykernel
        - ipywidgets >=7.5
        - flaky
      commands:
        - pip check
        - jupyter nbconvert --version
        - jupyter dejavu --version
        - jupyter nbconvert --help
        - jupyter dejavu --help
        - jupyter nbconvert tests/files/notebook1.ipynb --to html
    about:
      home: https://jupyter.org
      license: BSD-3-Clause
      license_file: LICENSE
      description: nbconvert with extra packages for browser-based PDF generation
      doc_url: https://nbconvert.readthedocs.org/
      dev_url: https://github.com/jupyter/nbconvert

  # Skipping nbconvert-qtpdf because it requires missing 'xelatex' on linux and 'PasteBoard' on osx;
  # without them a Segmentation fault happens on unix.
  - name: nbconvert-qtpdf
    build:
      skip: True
    requirements:
      host:
        - python
      run:
        - python
        - {{ pin_subpackage("nbconvert-core", exact=True) }}
        - pyqtwebengine >=5.5
    test:
      requires:
        - pip
        - ipython
      script_env:
        - DISPLAY=localhost:1.0  # [linux]
      commands:
        - pip check
        - jupyter nbconvert --version
        - jupyter dejavu --version
        - jupyter nbconvert --help
        - jupyter dejavu --help
        # Segmantation fault on osx:
        # PasteBoard: Error creating pasteboard: m.apple.pasteboard.clipboard [-4960]
        #- jupyter nbconvert tests/files/notebook2.ipynb --debug --allow-errors --to qtpdf  # [not linux]
        # xelatex is required on linux imlicitely, see https://github.com/jupyter/nbconvert/blob/v7.16.4/nbconvert/exporters/pdf.py#L62-L64 
        # - xvfb-run -a jupyter nbconvert tests/files/notebook2.ipynb --debug --allow-errors --to qtpdf  # [linux]

    about:
      home: https://jupyter.org
      license: BSD-3-Clause
      license_file: LICENSE
      description: nbconvert with extra packages for browser-based PDF generation
      doc_url: https://nbconvert.readthedocs.org/
      dev_url: https://github.com/jupyter/nbconvert

  - name: nbconvert-pandoc
    requirements:
      host:
        - python
      run:
        - python
        - {{ pin_subpackage("nbconvert-core", exact=True) }}
        # the pin is handled by the `run_constrained` in nbconvert-core
        - pandoc
    test:
      files:
        - check_pandoc.py
      requires:
        - pip
      commands:
        - pip check
        - jupyter nbconvert --version
        - jupyter dejavu --version
        - jupyter nbconvert --help
        - jupyter dejavu --help
        - python check_pandoc.py ">={{ min_pandoc }}" "<{{ max_pandoc }}"
    about:
      home: https://jupyter.org
      license: BSD-3-Clause
      license_file: LICENSE
      description: nbconvert with extra packages for pandoc-based outputs
      doc_url: https://nbconvert.readthedocs.org/
      dev_url: https://github.com/jupyter/nbconvert

  # Skipping because playwright-python is not available on the defaults channel
  - name: nbconvert-webpdf
    build:
      skip: True
    requirements:
      host:
        - python
      run:
        - python
        - {{ pin_subpackage("nbconvert-core", exact=True) }}
        - playwright-python
    test:
      source_files:
        - tests/files/notebook1.ipynb
      requires:
        - pip
      script_env:
        - DISPLAY=localhost:1.0  # [linux]
      commands:
        - pip check
        - jupyter nbconvert --version
        - jupyter dejavu --version
        - jupyter nbconvert --help
        - jupyter dejavu --help
        - playwright install chromium
        - jupyter nbconvert tests/files/notebook1.ipynb --to webpdf
    about:
      description: nbconvert with extra packages for browser-based PDF generation

  - name: nbconvert-all
    requirements:
      host:
        - python
      run:
        - python
        - {{ pin_subpackage("nbconvert-core", exact=True) }}
        #- {{ pin_subpackage("nbconvert-qtpdf", exact=True) }}
        #- {{ pin_subpackage("nbconvert-webpdf", exact=True) }}
        - {{ pin_subpackage("nbconvert", exact=True) }}
    test:
      source_files:
        - tests
        - pyproject.toml
      requires:
        - coverage
        - flaky
        - ipykernel
        - ipywidgets >=7.9.0
        - pip
        - pytest >=7
        - pytest-dependency
      commands:
        - pip check
        - jupyter nbconvert --version
        - jupyter dejavu --version
        - jupyter nbconvert --help
        - jupyter dejavu --help
        - pytest -vv {{ pytest_args }}                                                          # [not linux]
        - xvfb-run -a coverage run --branch --source=nbconvert -m pytest -vv {{ pytest_args }}  # [linux]
        - coverage report --show-missing --skip-covered     # [linux]
    about:
      home: https://jupyter.org
      license: BSD-3-Clause
      license_file: LICENSE
      description: nbconvert with all optional packages
      doc_url: https://nbconvert.readthedocs.org/
      dev_url: https://github.com/jupyter/nbconvert

about:
  home: https://nbconvert.readthedocs.io
  license: BSD-3-Clause
  license_file: LICENSE
  license_family: BSD
  summary: Converting Jupyter Notebooks
  description: |
    The nbconvert tool, jupyter nbconvert, converts notebooks to various other
    formats via Jinja templates. The nbconvert tool allows you to convert an
    .ipynb notebook file into various static formats.
  doc_url: https://nbconvert.readthedocs.io
  dev_url: https://github.com/jupyter/nbconvert

extra:
  recipe-maintainers:
    - jakirkham
    - mpacer
    - minrk
    - pelson
    - takluyver
    - mseal
    - blink1073
    - ocefpaf
