{% set version = "3.10.14" %}
{% set build_number = 1 %}
{% set ver2 = '.'.join(version.split('.')[0:2]) %}
{% set ver2nd = ''.join(version.split('.')[0:2]) %}
{% set ver3nd = ''.join(version.split('.')[0:3]) %}

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

build:
  number: {{ build_number }}

source:
  - git_url: https://github.com/python/cpython.git
    git_tag: v{{ version }}
    patches:
      - patches/0001-Win32-Change-FD_SETSIZE-from-512-to-2048.patch
      - patches/0002-Win32-distutils-Add-support-to-cygwinccompiler-for-V.patch
      - patches/0003-Support-cross-compiling-byte-code.patch
      # https://github.com/python/cpython/pull/28501
      - patches/0004-bpo-45258-search-for-isysroot-in-addition-to-sysroot.patch
      # https://github.com/pypa/distutils/pull/54
      - patches/0005-runtime_library_dir_option-Use-1st-word-of-CC-as-com.patch
      - patches/0006-Win32-Do-not-download-externals.patch
      - patches/0007-Fix-find_library-so-that-it-looks-in-sys.prefix-lib-.patch
      # https://github.com/python/cpython/pull/28397
      - patches/0008-bpo-22699-Allow-compiling-on-debian-ubuntu-with-a-di.patch
      # Patch doesn't apply, but is Debian-specific anyway.
      # - patches/0008-bpo-22699-Allow-compiling-on-debian-ubuntu-with-a-di.patch
      - patches/0009-Disable-registry-lookup-unless-CONDA_PY_ALLOW_REG_PA.patch
      - patches/0010-Unvendor-openssl.patch
      - patches/0011-Unvendor-sqlite3.patch
      # https://github.com/pypa/distutils/pull/53
      - patches/0012-Use-ranlib-from-env-if-env-variable-is-set.patch
      - patches/0013-Add-CondaEcosystemModifyDllSearchPath.patch
      - patches/0014-Add-d1trimfile-SRC_DIR-to-make-pdbs-more-relocatable.patch
      - patches/0015-Doing-d1trimfile.patch
      # https://github.com/python/cpython/pull/23523
      - patches/0016-cross-compile-darwin.patch
      - patches/0017-Fix-TZPATH-on-windows.patch
      # https://github.com/python/cpython/pull/24324
      - patches/0018-Make-dyld-search-work-with-SYSTEM_VERSION_COMPAT-1.patch
      # https://github.com/pypa/distutils/pull/53
      - patches/0019-Fix-LDSHARED-when-CC-is-overriden-on-Linux-too.patch
      - patches/0020-Unvendor-bzip2.patch
      - patches/0021-Unvendor-libffi.patch
      - patches/0022-Unvendor-tcltk.patch
      - patches/0023-unvendor-xz.patch
      - patches/0024-unvendor-zlib.patch
      - patches/0025-Do-not-pass-g-to-GCC-when-not-Py_DEBUG.patch
      #https://github.com/python/cpython/pull/111116
      - patches/CVE-2023-27043.patch

       # Intel patches
      - patches/intel_version_cprt.patch
      - patches/intel_distutil_build.patch
      #- patches/intel_skip_hanging_test.patch                                        # [osx]
      - patches/intel_build_py_with_pie.patch                                        # [linux]
      - patches/intel_proxy_fix.patch            # [win]

outputs:
  - name: python
    script: build_base.sh  # [unix]
    script: build_base.bat  # [win]
    build:
      number: {{ build_number }}
      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]
      ignore_run_exports_from:   # [unix]
        # C++ only installed so CXX is defined for distutils/sysconfig.
        - {{ compiler('cxx') }}  # [unix]
      # Disabled until verified to work correctly
      detect_binary_files_with_prefix: true
      skip: true  # [win and int(float(vc)) < 14]
      skip_compile_pyc:
        - '*.py'            # [build_platform != target_platform]
      string: h{{ PKG_HASH }}_{{ PKG_BUILDNUM }}
      missing_dso_whitelist:   # [win or linux64]
        - '**/MSVCR71.dll'  # [win]
        - '**/MSVCR80.dll'  # [win]
        # I have no idea why this is not in C:\Windows\System32\downlevel
        - '**/api-ms-win-core-path-l1-1-0.dll'  # [win]
    requirements:
      build:
        - {{ compiler('c') }}
        - {{ compiler('cxx') }}
        - {{ cdt('xorg-x11-proto-devel') }}  # [linux]
        - {{ cdt('libx11-devel') }}  # [linux]
        - patch  # [not win]
        - m2-patch  # [win]
        - m2-gcc-libs  # [win]
        - make  # [not win]
        - libtool  # [unix]
        - pkg-config  # [not win]
        # configure script looks for llvm-ar for lto
        - llvm-tools  # [osx]
        - ld_impl_{{ target_platform }}  # [linux]
        - binutils_impl_{{ target_platform }}  # [linux]
      host:
        - bzip2
        - sqlite
        - xz
        - zlib
        # SAT-6615
        - zlib >=1.2.13,<1.3 
        - openssl
        - readline  # [not win]
        - tk
        - ncurses  # [unix]
        - libffi
        - ld_impl_{{ target_platform }} >=2.36.1  # [linux]
        - libnsl  # [linux]
        - libuuid  # [linux]
        - libxcrypt # [linux]
      run:
        - tzdata
    test:
      requires:
        - ripgrep
        - cmake
        - ninja
        - {{ compiler('c') }}
        # Tried to use enable_language(C) to avoid needing this. It does not work.
        - {{ compiler('cxx') }}
      files:
        - tests/distutils/*
        - tests/cmake/*
        - tests/cython/*
        - tests/prefix-replacement/*
        - run_test.py
      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]
        # tzdata/zoneinfo test that will need the tzdata package to pass
        - python -c "from zoneinfo import ZoneInfo; from datetime import datetime; dt = datetime(2020, 10, 31, 12, tzinfo=ZoneInfo('America/Los_Angeles')); print(dt.tzname())"
        - python -m venv test-venv
        - test-venv\\Scripts\\python.exe -c "import ctypes"  # [win]
        - test-venv/bin/python -c "import ctypes"            # [unix]
        - 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 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
        - python run_test.py
        - test ! -f default.profraw   # [osx]
        # Test workaround for https://github.com/conda/conda/issues/10969
        - test -d "$PREFIX/lib/python3.1/site-packages"  # [unix]
        - python3.1 --version  # [unix]
        # Test for segfault on osx-64 with libffi=3.4, see https://bugs.python.org/issue44556
        - python -c "from ctypes import CFUNCTYPE; CFUNCTYPE(None)(id)"
        # crypt module will be removed in 3.13 => this failing is a reminder to remove the libxcrypt dependency
        - python -c "import crypt"  # [unix]


  - name: libpython-static
    script: build_static.sh  # [unix]
    script: build_static.bat  # [win]
    build:
      number: {{ build_number }}
      activate_in_script: true
      string: h{{ PKG_HASH }}_{{ PKG_BUILDNUM }}
    requirements:
      build:
        - {{ compiler('c') }}
        - {{ compiler('cxx') }}
      host:
        - {{ pin_subpackage('python', exact=True) }}
      run:
        - {{ pin_subpackage('python', exact=True) }}
    test:
      files:
        - tests/prefix-replacement/*
      requires:
        - {{ compiler('c') }}
      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]
        - pushd tests/prefix-replacement    # [unix]
        - bash build-and-test.sh      # [unix]
        - popd    # [unix]

about:
  home: https://www.python.org/
  license: Python-2.0
  license_file: LICENSE
  summary: General purpose programming language
  description: |
    <strong>LEGAL NOTICE: Use of this software package is subject to the
    software license agreement (as set forth above, in the license section of
    the installed Conda package and/or the README file) and all notices,
    disclaimers or license terms for third party or open source software
    included in or with the software.</strong> 
    <br/><br/>
    EULA: <a href="https://docs.python.org/3/license.html" target="_blank">Python-2.0</a>
    <br/><br/>
  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/
