{% set version = "3.8.8" %}
{% set linkage_nature = os.environ.get('PY_INTERP_LINKAGE_NATURE', '') %}
{% set debug = os.environ.get('PY_INTERP_DEBUG', '') %}
{% if linkage_nature != '' %}
  {% set linkage_nature = "_" ~ linkage_nature %}
{% endif %}
{% if debug != '' %}
  {% set debug = "_d" ~ debug %}
{% endif %}

package:
  name: python-split
  version: {{ version }}

source:
  - url: https://www.python.org/ftp/python/{{ version }}/Python-{{ version }}.tar.xz
    # md5 from: https://www.python.org/downloads/release/python-388/
    md5: 23e6b769857233c1ac07b6be7442eff4
    patches:
      - patches/0001-Fix-off-by-one-error-in-_winapi_WaitForMultipleObjec.patch
{% if 'conda-forge' not in channel_targets %}
      - patches/0002-Add-Anaconda-Distribution-version-logic.patch
{% endif %}
      - patches/0003-Darwin-Add-arch-x86_64-to-UnicCCompiler-ld_args.patch
      - patches/0004-Win32-Change-FD_SETSIZE-from-512-to-2048.patch
      - patches/0005-Win32-distutils-Add-support-to-cygwinccompiler-for-V.patch
      - patches/0006-Do-not-pass-g-to-GCC-when-not-Py_DEBUG.patch
      - patches/0007-Support-cross-compiling-byte-code.patch
      - patches/0008-Win32-Fixes-for-Windows-GCC-interop-needed-by-RPy2-a.patch
      - patches/0009-Darwin-Look-in-sysroot-usr-lib-include-if-sysroot-is.patch
      - patches/0010-runtime_library_dir_option-Use-1st-word-of-CC-as-com.patch
      - patches/0011-Win32-Do-not-download-externals.patch
      - patches/0012-Add-support-for-_CONDA_PYTHON_SYSCONFIGDATA_NAME-if-.patch
      - patches/0013-Fix-find_library-so-that-it-looks-in-sys.prefix-lib-.patch
      - patches/0014-Disable-new-dtags-in-unixccompiler.py.patch
      - patches/0015-Fix-cross-compilation-on-Debian-based-distros.patch
      - patches/0016-Disable-registry-lookup-unless-CONDA_PY_ALLOW_REG_PA.patch
      - patches/0017-Unvendor-openssl.patch
      - patches/0018-Unvendor-sqlite3.patch
      # https://bugs.python.org/issue35644
      - patches/0019-venv-Revert-a-change-from-https-github.com-python-cp.patch
      - patches/0020-Win-Add-back-the-DLLSuffix-used-to-find-the-openssl-.patch
      - patches/0021-Use-ranlib-from-env-if-env-variable-is-set.patch
      # Python 3.8 is pretty broken without this.
      - patches/0022-Add-CondaEcosystemModifyDllSearchPath.patch
      - patches/0023-Revert-part-of-https-bugs.python.org-issue33895-http.patch
      - patches/0024-cross-compile-darwin.patch.patch
      - patches/0025-BPO-41101-Support-arm64-in-Mac-Tools-pythonw.patch
      - patches/0026-fix-_decimal-for-arm64-Mac-OS.patch
      - patches/0027-Added-by-blurb_it.patch
      - patches/0028-ctypes-check-_dyld_shared_cache_contains_path-in-fin.patch
      - patches/0029-fix-test_macholib-for-Mac-OS-11.patch
      - patches/0030-Xcode-12-Beta-4-declares-_dyld_shared_cache_contains.patch
      - patches/0031-gh21564.patch.patch  # [osx and arm64]

  # TODO :: Depend on our own packages for these:
  - url: https://github.com/python/cpython-source-deps/archive/xz-5.2.2.zip          # [win]
    folder: externals/xz-5.2.2                                                       # [win]
    sha256: 02b6d6f1e0369940e7e1f0d324992e069d09f5f3d32d86e2d22cd8b82ac3fb3f         # [win]
  # Not used as of 3.7b3 (tcltk from cpython-bin- is), but kept for archival and license reasons.
  - url: https://github.com/python/cpython-source-deps/archive/tcl-core-8.6.9.0.zip  # [win]
    folder: externals/tcl-core-8.6.9.0                                               # [win]
    sha256: ea9e724536ec13b476ebbd47948303b92fdd90a33aa94f30fcc2f5c3a899f69e         # [win]
  # Not used as of 3.7b3 (tcltk from cpython-bin- is), but kept for archival and license reasons.
  - url: https://github.com/python/cpython-source-deps/archive/tk-8.6.9.0.zip        # [win]
    folder: externals/tk-8.6.9.0                                                     # [win]
    sha256: f3112b6bbc3bd163c877030187e73ce9a113ce03eff559ec5b9df697e3a08fad         # [win]
  - url: https://github.com/python/cpython-bin-deps/archive/tcltk-8.6.9.0.zip        # [win]
    folder: externals/tcltk-8.6.9.0                                                  # [win]
    sha256: 37cd629a75d2a34974a3d771ccab5c9e3caf3d138cea81040f9cdba1aded1cf2         # [win]
  - url: https://github.com/python/cpython-source-deps/archive/tix-8.4.3.6.zip       # [win]
    folder: externals/tix-8.4.3.6                                                    # [win]
    sha256: e558e3dc5e67ac0942f8fceafce00ca46b177da9ebeaf38ec7fafd9b9913ac56         # [win]
  - url: https://github.com/python/cpython-source-deps/archive/bzip2-1.0.6.zip       # [win]
    folder: externals/bzip2-1.0.6                                                    # [win]
    sha256: c42fd1432a2667b964a74bc423bb7485059c4a6d5dc92946d59dbf9a6bdb988d         # [win]
  - url: https://github.com/python/cpython-source-deps/archive/zlib-1.2.11.zip       # [win]
    folder: externals/zlib-1.2.11                                                    # [win]
    sha256: debb1952945fa6c25817a40abe90641b572c83171f244937b70b9fe156f5a63a         # [win]
  - url: https://github.com/python/cpython-bin-deps/archive/nasm-2.11.06.zip         # [win]
    folder: externals/nasm-2.11.06                                                   # [win]
    sha256: de3c87b26a80e789986d8e6950c6304175d3829afe9c6c7211eb7257266ab0ac         # [win]
  - url: https://github.com/python/cpython-bin-deps/archive/libffi.zip               # [win]
    folder: externals/libffi                                                         # [win]
    sha256: 4872e72e188a5aa1124db0c3b163a4163e84ead359a514d86dd7c6fa2d2ff02a         # [win]

build:
  number: 0
  script_env:
    - PY_INTERP_LINKAGE_NATURE
    - PY_INTERP_DEBUG

outputs:
  - name: python
    build:
      activate_in_script: True
      # Windows has issues updating python if conda is using files itself.
      # Copy rather than link.
      no_link:
        - DLLs/_ctypes.pyd  # [win]
      # We delete the shared libraries.
      ignore_run_exports:   # [unix]
        - bzip2             # [unix]
      # Disabled until new conda-build release
      detect_binary_files_with_prefix: True
      # detect_binary_files_with_prefix: False
      # binary_has_prefix_files:
      #   - lib/libpython3.8.*.1.0
      #   - bin/python3.8  # [linux]
      #   - lib/libpython3.8.a  # [linux]
      #   - lib/libpython3.8.nolto.a  # [linux]
      #   - lib/libpython3.so  # [linux]
      #   - lib/python3.8/lib-dynload/_hashlib.cpython-38-x86_64-linux-gnu.so  # [linux]
      #   - lib/libpython3.dylib  # [osx]
      # match python.org compiler standard
      skip: True            # [win and int(float(vc)) < 14]
      skip_compile_pyc:
        - '*.py'            # [osx and arm64]
      # Would like to be able to append to the calculated build string here, ping @msarahan, is this possible?
      string: h{{ PKG_HASH }}_{{ PKG_BUILDNUM }}{{ linkage_nature }}{{ debug }}_cpython
      run_exports:
        noarch:
          - python
        weak:
          - python_abi 3.8.* *_cp38
    # Not until: https://github.com/mingwandroid/conda-build/commit/c68a7d100866df7a3e9c0e3177fc7ef0ff76def9
    # {% if 'conda-forge' not in channel_targets %}
    #      - CONDA_FORGE=yes
    # {% else %}
    #      - CONDA_FORGE=no
    # {% endif %}
    script: build_base.sh  # [unix]
    script: build_base.bat  # [win]
    requirements:
      build:
        - {{ compiler('c') }}
        - {{ compiler('cxx') }}
        - {{ cdt('xorg-x11-proto-devel') }}  # [linux]
        - {{ cdt('libx11-devel') }}  # [linux]
        - {{ cdt('libuuid-devel') }}  # [linux and not (ppc64le or aarch64)]
        - make  # [not win]
        - pkg-config  # [not win]
        # configure script looks for llvm-ar for lto
        - llvm-tools  # [osx]
        - patch  # [not win]
        - m2-patch  # [win]
        - posix  # [win]
        - ld_impl_{{ target_platform }} >=2.34  # [linux]
        - binutils_impl_{{ target_platform }} >=2.34  # [linux]
        - libtool  # [unix]
      host:
        - bzip2  # [not win]
        - sqlite
        - xz  # [not win]
        - zlib  # [not win]
        - openssl
        - readline  # [not win]
        - tk  # [not win]
        - ncurses  # [linux]
        - libffi  # [not win]
        - ld_impl_{{ target_platform }} >=2.34  # [linux]
      run:
        - ld_impl_{{ target_platform }} >=2.34  # [linux]
      run_constrained:
        - python_abi 3.8.* *_cp38
    test:
      requires:
        - ripgrep
        - cmake
        - ninja
        - cython
        - setuptools
        - {{ compiler('c') }}
        # Tried to use enable_language(C) to avoid needing this. It does not work.
        - {{ compiler('cxx') }}
      files:
        - tests/distutils/*
        - tests/distutils.cext/*
        - tests/cmake/*
        - tests/cython/*
        - tests/prefix-replacement/*
      commands:
        - echo on  # [win]
        - set  # [win]
        - python -V
        - python3 -V            # [not win]
        - 2to3 -h
        - pydoc -h
        - python3-config --help  # [not win]
        - set "PIP_NO_BUILD_ISOLATION=False"  # [win]
        - set "PIP_NO_DEPENDENCIES=True"  # [win]
        - set "PIP_IGNORE_INSTALLED=True"  # [win]
        - set "PIP_NO_INDEX=True"  # [win]
        - set "PIP_CACHE_DIR=%CONDA_PREFIX%/pip_cache"  # [win]
        - set "TEMP=%CONDA_PREFIX%/tmp"  # [win]
        - mkdir "%TEMP%"  # [win]
        - python -Im ensurepip --upgrade --default-pip  # [win]
        - python -m venv test-venv
        - python -c "import sysconfig; print(sysconfig.get_config_var('CC'))"  # [not win]
        -  _CONDA_PYTHON_SYSCONFIGDATA_NAME=_sysconfigdata_x86_64_conda_cos6_linux_gnu python -c "import sysconfig; print(sysconfig.get_config_var('CC'))"  # [linux64]
        # check for unreplaced @ symbols in sysconfig files
        - for f in ${CONDA_PREFIX}/lib/python*/_sysconfig*.py; do echo "Checking $f:"; if [[ `rg @ $f` ]]; then echo "FAILED ON $f"; cat $f; exit 1; fi; done  # [linux64 or osx]
        - test ! -f ${PREFIX}/lib/libpython${PKG_VERSION%.*}.a  # [unix]
        - test ! -f ${PREFIX}/lib/libpython${PKG_VERSION%.*}.nolto.a  # [unix]
        # https://github.com/conda-forge/python-feedstock/issues/384
        - if exist %PREFIX%\\Scripts\\pydoc exit 1  # [win]
        - if exist %PREFIX%\\Scripts\\idle exit 1  # [win]
        - if exist %PREFIX%\\Scripts\\2to3 exit 1  # [win]
        - if not exist %PREFIX%\\Scripts\\pydoc-script.py exit 1  # [win]
        - if not exist %PREFIX%\\Scripts\\idle-script.py exit 1  # [win]
        - if not exist %PREFIX%\\Scripts\\2to3-script.py exit 1  # [win]
        - if not exist %PREFIX%\\Scripts\\idle.exe exit 1  # [win]
        - if not exist %PREFIX%\\Scripts\\2to3.exe exit 1  # [win]
        - if not exist %PREFIX%\\Scripts\\pydoc.exe exit 1  # [win]
        - pushd tests
        -   pushd distutils
        -     python setup.py install -v -v
        -     python -c "import foobar"
        -   popd
        -   pushd distutils.cext
        -     python setup.py install -v -v
        -     python -c "import greet; greet.greet('Python user')" | rg "Hello Python"
        -   popd
        -   pushd prefix-replacement  # [unix]
        -     bash build-and-test.sh  # [unix]
        -   popd  # [unix]
        -   pushd cmake
        -     cmake -GNinja -DPY_VER={{ version }}
              # --trace --debug-output --debug-trycompile .
        -   popd
        - popd
        - test ! -f default.profraw   # [osx]

  - name: libpython-static
    build:
      activate_in_script: True
      # Would like to be able to append to the calculated build string here, ping @msarahan, is this possible?
      string: h{{ PKG_HASH }}_{{ PKG_BUILDNUM }}{{ linkage_nature }}{{ debug }}_cpython
    script: build_static.sh  # [unix]
    script: build_static.bat  # [win]
    requirements:
      build:
        - {{ compiler('c') }}
        - {{ compiler('cxx') }}
        - posix  # [win]
      host:
        - {{ pin_subpackage('python', exact=True) }}
      run:
        - {{ pin_subpackage('python', exact=True) }}
    test:
      commands:
        - test -f ${PREFIX}/lib/libpython${PKG_VERSION%.*}.a  # [unix]
        - test -f ${PREFIX}/lib/libpython${PKG_VERSION%.*}.nolto.a  # [unix]
        - test -f ${PREFIX}/lib/python${PKG_VERSION%.*}/config-${PKG_VERSION%.*}-darwin/libpython${PKG_VERSION%.*}.a  # [osx]

about:
  home: https://www.python.org/
  license: Python-2.0
  license_file: LICENSE
  summary: General purpose programming language
  description: |
    Python is a widely used high-level, general-purpose, interpreted, dynamic
    programming language. Its design philosophy emphasizes code
    readability, and its syntax allows programmers to express concepts in
    fewer lines of code than would be possible in languages such as C++ or
    Java. The language provides constructs intended to enable clear programs
    on both a small and large scale.
  doc_url: https://www.python.org/doc/versions/
  doc_source_url: https://github.com/python/pythondotorg/blob/master/docs/source/index.rst
  dev_url: https://docs.python.org/devguide/

extra:
  feedstock-name: python
  recipe-maintainers:
    - isuruf
    - jakirkham
    - jjhelmus
    - mingwandroid
    - msarahan
    - pelson
    - ocefpaf
    - scopatz
