diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index cfd9f5c..9e9a824 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -89,7 +89,7 @@ jobs: strategy: fail-fast: false matrix: - target: ['macOS', 'iOS', 'tvOS', 'watchOS'] + platform: ['macOS', 'iOS', 'tvOS', 'watchOS'] steps: - uses: actions/checkout@v4.1.7 @@ -104,29 +104,29 @@ jobs: # It's an edge case, but when a new alpha is released, we need to use it ASAP. check-latest: true - - name: Build ${{ matrix.target }} + - name: Build ${{ matrix.platform }} run: | - # Do the build for the requested target. - make ${{ matrix.target }} BUILD_NUMBER=${{ needs.config.outputs.BUILD_NUMBER }} + # Do the build for the requested platform. + make ${{ matrix.platform }} BUILD_NUMBER=${{ needs.config.outputs.BUILD_NUMBER }} - name: Upload build artefacts uses: actions/upload-artifact@v4.6.2 with: - name: Python-${{ needs.config.outputs.PYTHON_VER }}-${{ matrix.target }}-support.${{ needs.config.outputs.BUILD_NUMBER }}.tar.gz - path: dist/Python-${{ needs.config.outputs.PYTHON_VER }}-${{ matrix.target }}-support.${{ needs.config.outputs.BUILD_NUMBER }}.tar.gz + name: Python-${{ needs.config.outputs.PYTHON_VER }}-${{ matrix.platform }}-support.${{ needs.config.outputs.BUILD_NUMBER }}.tar.gz + path: dist/Python-${{ needs.config.outputs.PYTHON_VER }}-${{ matrix.platform }}-support.${{ needs.config.outputs.BUILD_NUMBER }}.tar.gz briefcase-testbed: - name: Briefcase testbed (${{ matrix.target }}) + name: Briefcase testbed (${{ matrix.platform }}) runs-on: macOS-latest needs: [ config, build ] strategy: fail-fast: false matrix: - target: ["macOS", "iOS"] + platform: ["macOS", "iOS"] include: - briefcase-run-args: - - target: iOS + - platform: iOS briefcase-run-args: ' -d "iPhone SE (3rd generation)"' steps: @@ -135,7 +135,7 @@ jobs: - name: Get build artifact uses: actions/download-artifact@v4.3.0 with: - pattern: Python-${{ needs.config.outputs.PYTHON_VER }}-${{ matrix.target }}-support.${{ needs.config.outputs.BUILD_NUMBER }}.tar.gz + pattern: Python-${{ needs.config.outputs.PYTHON_VER }}-${{ matrix.platform }}-support.${{ needs.config.outputs.BUILD_NUMBER }}.tar.gz path: dist merge-multiple: true @@ -162,16 +162,16 @@ jobs: - name: Run support testbed check timeout-minutes: 10 working-directory: Python-support-testbed - run: briefcase run ${{ matrix.target }} Xcode --test ${{ matrix.briefcase-run-args }} -C support_package=\'../dist/Python-${{ needs.config.outputs.PYTHON_VER }}-${{ matrix.target }}-support.${{ needs.config.outputs.BUILD_NUMBER }}.tar.gz\' + run: briefcase run ${{ matrix.platform }} Xcode --test ${{ matrix.briefcase-run-args }} -C support_package=\'../dist/Python-${{ needs.config.outputs.PYTHON_VER }}-${{ matrix.platform }}-support.${{ needs.config.outputs.BUILD_NUMBER }}.tar.gz\' cpython-testbed: - name: CPython testbed (${{ matrix.target }}) + name: CPython testbed (${{ matrix.platform }}) runs-on: macOS-latest needs: [ config, build ] strategy: fail-fast: false matrix: - target: ["iOS"] + platform: ["iOS"] steps: - uses: actions/checkout@v4.1.7 @@ -179,7 +179,7 @@ jobs: - name: Get build artifact uses: actions/download-artifact@v4.3.0 with: - pattern: Python-${{ needs.config.outputs.PYTHON_VER }}-${{ matrix.target }}-support.${{ needs.config.outputs.BUILD_NUMBER }}.tar.gz + pattern: Python-${{ needs.config.outputs.PYTHON_VER }}-${{ matrix.platform }}-support.${{ needs.config.outputs.BUILD_NUMBER }}.tar.gz path: dist merge-multiple: true @@ -195,13 +195,13 @@ jobs: - name: Unpack support package run: | - mkdir support - cd support - tar zxvf ../dist/Python-${{ needs.config.outputs.PYTHON_VER }}-${{ matrix.target }}-support.${{ needs.config.outputs.BUILD_NUMBER }}.tar.gz + mkdir -p support/${{ needs.config.outputs.PYTHON_VER }}/${{ matrix.platform }} + cd support/${{ needs.config.outputs.PYTHON_VER }}/${{ matrix.platform }} + tar zxvf ../../../dist/Python-${{ needs.config.outputs.PYTHON_VER }}-${{ matrix.platform }}-support.${{ needs.config.outputs.BUILD_NUMBER }}.tar.gz - name: Run CPython testbed timeout-minutes: 10 - working-directory: support + working-directory: support/${{ needs.config.outputs.PYTHON_VER }}/${{ matrix.platform }} run: | # Run a representative subset of CPython core tests: # - test_builtin as a test of core language tools @@ -210,3 +210,66 @@ jobs: # - test_bz2 as a simple test of third party libraries # - test_ctypes as a test of FFI python -m testbed run -- test --single-process --rerun -W test_builtin test_grammar test_os test_bz2 test_ctypes + + crossenv-test: + name: Cross-platform env test (${{ matrix.multiarch }}) + runs-on: macOS-latest + needs: [ config, build ] + strategy: + fail-fast: false + matrix: + include: + - platform: iOS + slice: ios-arm64_x86_64-simulator + multiarch: arm64-iphonesimulator + - platform: iOS + slice: ios-arm64_x86_64-simulator + multiarch: x86_64-iphonesimulator + - platform: iOS + slice: ios-arm64 + multiarch: arm64-iphoneos + + steps: + - uses: actions/checkout@v4.1.7 + + - name: Get build artifact + uses: actions/download-artifact@v4.3.0 + with: + pattern: Python-${{ needs.config.outputs.PYTHON_VER }}-${{ matrix.platform }}-support.${{ needs.config.outputs.BUILD_NUMBER }}.tar.gz + path: dist + merge-multiple: true + + - name: Set up Python + uses: actions/setup-python@v5.6.0 + with: + # Appending -dev ensures that we can always build the dev release. + # It's a no-op for versions that have been published. + python-version: ${{ needs.config.outputs.PYTHON_VER }}-dev + # Ensure that we *always* use the latest build, not a cached version. + # It's an edge case, but when a new alpha is released, we need to use it ASAP. + check-latest: true + + - name: Unpack support package + run: | + mkdir -p support/${{ needs.config.outputs.PYTHON_VER }}/${{ matrix.platform }} + cd support/${{ needs.config.outputs.PYTHON_VER }}/${{ matrix.platform }} + tar zxvf ../../../dist/Python-${{ needs.config.outputs.PYTHON_VER }}-${{ matrix.platform }}-support.${{ needs.config.outputs.BUILD_NUMBER }}.tar.gz + + - name: Run cross-platform environment test + env: + PYTHON_CROSS_PLATFORM: ${{ matrix.platform }} + PYTHON_CROSS_SLICE: ${{ matrix.slice }} + PYTHON_CROSS_MULTIARCH: ${{ matrix.multiarch }} + run: | + # Create and activate a native virtual environment + python${{ needs.config.outputs.PYTHON_VER }} -m venv cross-venv + source cross-venv/bin/activate + + # Install pytest + python -m pip install pytest + + # Convert venv into cross-venv + python support/${{ needs.config.outputs.PYTHON_VER }}/${{ matrix.platform }}/Python.xcframework/${{ matrix.slice }}/platform-config/${{ matrix.multiarch }}/make_cross_venv.py cross-venv + + # Run the test suite + python -m pytest tests diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index fd78eee..6767d2e 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -47,7 +47,7 @@ jobs: merge-multiple: true - name: Create Release - uses: ncipollo/release-action@v1.16.0 + uses: ncipollo/release-action@v1.18.0 with: name: ${{ needs.ci.outputs.PYTHON_VER }}-${{ needs.config.outputs.BUILD_NUMBER }} tag: ${{ needs.ci.outputs.PYTHON_VER }}-${{ needs.config.outputs.BUILD_NUMBER }} diff --git a/.gitignore b/.gitignore index f805393..a87e3e2 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,5 @@ tests/testbed/iOS *.log *.gz *.DS_Store +cross-venv/ +temp diff --git a/Makefile b/Makefile index 3f67336..c0b6121 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,6 @@ # - iOS - build everything for iOS # - tvOS - build everything for tvOS # - watchOS - build everything for watchOS -# - visionOS - build everything for visionOS # Current directory PROJECT_DIR=$(shell pwd) @@ -34,7 +33,7 @@ OPENSSL_VERSION=3.0.16-2 XZ_VERSION=5.6.4-2 # Supported OS -OS_LIST=macOS iOS tvOS watchOS visionOS +OS_LIST=macOS iOS tvOS watchOS CURL_FLAGS=--disable --fail --location --create-dirs --progress-bar @@ -89,7 +88,7 @@ update-patch: # comparing between the current state of the 3.X branch against the v3.X.Y # tag associated with the release being built. This allows you to # maintain a branch that contains custom patches against the default Python. - # The patch archived in this respository is based on github.com/freakboy3742/cpython + # The patch archived in this repository is based on github.com/freakboy3742/cpython # Requires patchutils (installable via `brew install patchutils`); this # also means we need to re-introduce homebrew to the path for the filterdiff # call @@ -333,7 +332,7 @@ $$(PYTHON_LIB-$(target)): $$(PYTHON_SRCDIR-$(target))/python.exe $$(PYTHON_PLATFORM_SITECUSTOMIZE-$(target)): - @echo ">>> Create cross-plaform config for $(target)" + @echo ">>> Create cross-platform config for $(target)" mkdir -p $$(PYTHON_PLATFORM_CONFIG-$(target)) # Create the cross-platform site definition echo "import _cross_$$(ARCH-$(target))_$$(SDK-$(target)); import _cross_venv;" \ diff --git a/README.md b/README.md new file mode 100644 index 0000000..8a3963b --- /dev/null +++ b/README.md @@ -0,0 +1,163 @@ +# Python Apple Support + +This is a meta-package for building a version of Python that can be +embedded into a macOS, iOS, tvOS, or watchOS project. + +**This branch builds a packaged version of Python 3.13**. Other Python +versions are available by cloning other branches of the main repository: + +- [Python 3.9](https://github.com/beeware/Python-Apple-support/tree/3.9) +- [Python + 3.10](https://github.com/beeware/Python-Apple-support/tree/3.10) +- [Python + 3.11](https://github.com/beeware/Python-Apple-support/tree/3.11) +- [Python + 3.12](https://github.com/beeware/Python-Apple-support/tree/3.12) +- [Python + 3.14](https://github.com/beeware/Python-Apple-support/tree/3.14) + +It works by downloading, patching, and building a fat binary of Python +and selected pre-requisites, and packaging them as frameworks that can +be incorporated into an Xcode project. The binary modules in the Python +standard library are distributed as binaries that can be dynamically +loaded at runtime. + +The macOS package is a re-bundling of the official macOS binary, +modified so that it is relocatable, with the IDLE, Tkinter and turtle +packages removed, and the App Store compliance patch applied. + +The iOS, tvOS, and watchOS packages compiled by this project +use the official [PEP 730](https://peps.python.org/pep-0730/) code that +is part of Python 3.13 to provide iOS support; the relevant patches have +been backported to 3.9-3.12. Additional patches have been applied to add +tvOS, and watchOS support. + +The binaries support x86_64 and arm64 for macOS; arm64 for iOS and +appleTV devices; and arm64_32 for watchOS devices. +It also supports device simulators on both x86_64 and M1 +hardware. This should enable the code to run on: + +- macOS 11 (Big Sur) or later, on: + - MacBook (including MacBooks using Apple Silicon) + - iMac (including iMacs using Apple Silicon) + - Mac Mini (including Apple Silicon Mac minis) + - Mac Studio (all models) + - Mac Pro (all models) + +- iOS 13.0 or later, on: + - iPhone (6s or later) + - iPad (5th gen or later) + - iPad Air (all models) + - iPad Mini (2 or later) + - iPad Pro (all models) + - iPod Touch (7th gen or later) + +- tvOS 12.0 or later, on: + - Apple TV (4th gen or later) + +- watchOS 4.0 or later, on: + - Apple Watch (4th gen or later) + +## Quickstart + +The easist way to use these packages is by creating a project with +[Briefcase](https://github.com/beeware/briefcase). Briefcase will +download pre-compiled versions of these support packages, and add them +to an Xcode project (or pre-build stub application, in the case of +macOS). + +Pre-built versions of the frameworks can be downloaded from the [Github +releases page](https://github.com/beeware/Python-Apple-support/releases) +and added to your project. + +Alternatively, to build the frameworks on your own, download/clone this +repository, and then in the root directory, and run: + +- `make` (or `make all`) to build everything. +- `make macOS` to build everything for macOS. +- `make iOS` to build everything for iOS. +- `make tvOS` to build everything for tvOS. +- `make watchOS` to build everything for watchOS. + +This should: + +1. Download the original source packages +2. Patch them as required for compatibility with the selected OS +3. Build the packages as Xcode-compatible XCFrameworks. + +The resulting support packages will be packaged as `.tar.gz` files in +the `dist` folder. + +Each support package contains: + +- `VERSIONS`, a text file describing the specific versions of code used + to build the support package; +- `Python.xcframework`, a multi-architecture build of the Python runtime + library. + +On iOS/tvOS/watchOS, the `Python.xcframework` contains a slice +for each supported ABI (device and simulator). The folder containing the +slice can also be used as a `PYTHONHOME`, as it contains a `bin`, +`include` and `lib` directory. + +The `bin` folder does not contain Python executables (as they can't be +invoked). However, it *does* contain shell aliases for the compilers +that are needed to build packages. This is required because Xcode uses +the `xcrun` alias to dynamically generate the name of binaries, but a +lot of C tooling expects that `CC` will not contain spaces. + +Each slice of an iOS/tvOS/watchOS XCframework also contains a +`platform-config` folder with a subfolder for each supported +architecture in that slice. These subfolders can be used to make a macOS +Python environment behave as if it were on an iOS/tvOS/watchOS +device. This works in one of two ways: + +1. **A sitecustomize.py script**. If the `platform-config` subfolder is + on your `PYTHONPATH` when a Python interpreter is started, a site + customization will be applied that patches methods in `sys`, + `sysconfig` and `platform` that are used to identify the system. +2. **A make_cross_venv.py script**. If you call `make_cross_venv.py`, + providing the location of a virtual environment, the script will add + some files to the `site-packages` folder of that environment that + will automatically apply the same set of patches as the + `sitecustomize.py` script whenever the environment is activated, + without any need to modify `PYTHONPATH`. If you use `build` to + create an isolated PEP 517 environment to build a wheel, these + patches will also be applied to the isolated build environment that + is created. + +iOS distributions also contain a copy of the iOS +`testbed` project - an Xcode project that can be used to run +test suites of Python code. See the [CPython documentation on testing +packages](https://docs.python.org/3/using/ios.html#testing-a-python-package) +for details on how to use this testbed. + +For a detailed instructions on using the support package in your own +project, see the [usage guide](./USAGE.md) + +## Building binary wheels + +This project packages the Python standard library, but does not address +building binary wheels. Binary wheels for macOS can be obtained from +PyPI. [Mobile Forge](https://github.com/beeware/mobile-forge) is a +project that provides the tooling to build build binary wheels for iOS +(and potentially for tvOS, and watchOS, although that hasn't +been tested). + +## Historical support + +The following versions were supported in the past, but are no longer +maintained: + +- [Python 2.7](https://github.com/beeware/Python-Apple-support/tree/2.7) + (EOL January 2020) +- [Python 3.4](https://github.com/beeware/Python-Apple-support/tree/3.4) + (EOL March 2019) +- [Python 3.5](https://github.com/beeware/Python-Apple-support/tree/3.5) + (EOL February 2021) +- [Python 3.6](https://github.com/beeware/Python-Apple-support/tree/3.6) + (EOL December 2021) +- [Python 3.7](https://github.com/beeware/Python-Apple-support/tree/3.7) + (EOL September 2022) +- [Python 3.8](https://github.com/beeware/Python-Apple-support/tree/3.8) + (EOL October 2024) diff --git a/README.rst b/README.rst deleted file mode 100644 index d75ef0e..0000000 --- a/README.rst +++ /dev/null @@ -1,150 +0,0 @@ -Python Apple Support -==================== - -This is a meta-package for building a version of Python that can be embedded -into a macOS, iOS, tvOS, watchOS project. - -**This branch builds a packaged version of Python 3.13**. -Other Python versions are available by cloning other branches of the main -repository: - -* `Python 3.9 `__ -* `Python 3.10 `__ -* `Python 3.11 `__ -* `Python 3.12 `__ -* `Python 3.14 `__ - -It works by downloading, patching, and building a fat binary of Python and -selected pre-requisites, and packaging them as frameworks that can be -incorporated into an Xcode project. The binary modules in the Python standard -library are distributed as binaries that can be dynamically loaded at runtime. - -The macOS package is a re-bundling of the official macOS binary, modified so that -it is relocatable, with the IDLE, Tkinter and turtle packages removed, and the -App Store compliance patch applied. - -The iOS, tvOS, and watchOS packages compiled by this project use the -official `PEP 730 `__ code that is part of -Python 3.13 to provide iOS support; the relevant patches have been backported -to 3.9-3.12. Additional patches have been applied to add tvOS, and watchOS -support. - -The binaries support x86_64 and arm64 for macOS; arm64 for iOS and appleTV -devices; and arm64_32 for watchOS devices. It also -supports device simulators on both x86_64 and M1 hardware. This should enable the -code to run on: - -* macOS 11 (Big Sur) or later, on: - * MacBook (including MacBooks using Apple Silicon) - * iMac (including iMacs using Apple Silicon) - * Mac Mini (including Apple Silicon Mac minis) - * Mac Studio (all models) - * Mac Pro (all models) -* iOS 13.0 or later, on: - * iPhone (6s or later) - * iPad (5th gen or later) - * iPad Air (all models) - * iPad Mini (2 or later) - * iPad Pro (all models) - * iPod Touch (7th gen or later) -* tvOS 12.0 or later, on: - * Apple TV (4th gen or later) -* watchOS 4.0 or later, on: - * Apple Watch (4th gen or later) - -Quickstart ----------- - -The easist way to use these packages is by creating a project with `Briefcase -`__. Briefcase will download pre-compiled -versions of these support packages, and add them to an Xcode project (or -pre-build stub application, in the case of macOS). - -Pre-built versions of the frameworks can be downloaded from the `Github releases page -`__ and added to your project. - -Alternatively, to build the frameworks on your own, download/clone this -repository, and then in the root directory, and run: - -* ``make`` (or ``make all``) to build everything. -* ``make macOS`` to build everything for macOS. -* ``make iOS`` to build everything for iOS. -* ``make tvOS`` to build everything for tvOS. -* ``make watchOS`` to build everything for watchOS. - -This should: - -1. Download the original source packages -2. Patch them as required for compatibility with the selected OS -3. Build the packages as Xcode-compatible XCFrameworks. - -The resulting support packages will be packaged as ``.tar.gz`` files -in the ``dist`` folder. - -Each support package contains: - -* ``VERSIONS``, a text file describing the specific versions of code used to build the - support package; -* ``Python.xcframework``, a multi-architecture build of the Python runtime library. - -On iOS/tvOS/watchOS, the ``Python.xcframework`` contains a -slice for each supported ABI (device and simulator). The folder containing the -slice can also be used as a ``PYTHONHOME``, as it contains a ``bin``, ``include`` -and ``lib`` directory. - -The ``bin`` folder does not contain Python executables (as they can't be -invoked). However, it *does* contain shell aliases for the compilers that are -needed to build packages. This is required because Xcode uses the ``xcrun`` -alias to dynamically generate the name of binaries, but a lot of C tooling -expects that ``CC`` will not contain spaces. - -Each slice of an iOS/tvOS/watchOS XCframework also contains a -``platform-config`` folder with a subfolder for each supported architecture in -that slice. These subfolders can be used to make a macOS Python environment -behave as if it were on an iOS/tvOS/watchOS device. This works in one of two -ways: - -1. **A sitecustomize.py script**. If the ``platform-config`` subfolder is on - your ``PYTHONPATH`` when a Python interpreter is started, a site - customization will be applied that patches methods in ``sys``, ``sysconfig`` - and ``platform`` that are used to identify the system. - -2. **A make_cross_venv.py script**. If you call ``make_cross_venv.py``, - providing the location of a virtual environment, the script will add some - files to the ``site-packages`` folder of that environment that will - automatically apply the same set of patches as the ``sitecustomize.py`` - script whenever the environment is activated, without any need to modify - ``PYTHONPATH``. If you use ``build`` to create an isolated PEP 517 - environment to build a wheel, these patches will also be applied to the - isolated build environment that is created. - -iOS distributions also contain a copy of the iOS ``testbed`` project - an Xcode -project that can be used to run test suites of Python code. See the `CPython -documentation on testing packages -`__ for -details on how to use this testbed. - -For a detailed instructions on using the support package in your own project, -see the `usage guide <./USAGE.md>`__ - -Building binary wheels ----------------------- - -This project packages the Python standard library, but does not address building -binary wheels. Binary wheels for macOS can be obtained from PyPI. `Mobile Forge -`__ is a project that provides the -tooling to build build binary wheels for iOS (and potentially for tvOS and watchOS -although that hasn't been tested). - -Historical support ------------------- - -The following versions were supported in the past, but are no longer -maintained: - -* `Python 2.7 `__ (EOL January 2020) -* `Python 3.4 `__ (EOL March 2019) -* `Python 3.5 `__ (EOL February 2021) -* `Python 3.6 `__ (EOL December 2021) -* `Python 3.7 `__ (EOL September 2022) -* `Python 3.8 `__ (EOL October 2024) diff --git a/USAGE.md b/USAGE.md index 985efc4..114ded2 100644 --- a/USAGE.md +++ b/USAGE.md @@ -22,7 +22,7 @@ guides: * [macOS](https://docs.python.org/3/using/mac.html) * [iOS](https://docs.python.org/3/using/ios.html#adding-python-to-an-ios-project) -For tvOS, and watchOS, you should be able to broadly follow the instructions +For tvOS and watchOS, you should be able to broadly follow the instructions in the iOS guide, changing some platform names in the first script. The testbed projects generated on iOS may be used as rough references as well. diff --git a/tests/test_cross_env.py b/tests/test_cross_env.py new file mode 100644 index 0000000..34e8c5e --- /dev/null +++ b/tests/test_cross_env.py @@ -0,0 +1,93 @@ +import os +import platform +import sys +import sysconfig +from pathlib import Path + +import pytest + +# To run these tests, the following three environment variables must be set, +# reflecting the cross-platform environment that is in effect.' +PYTHON_CROSS_PLATFORM = os.getenv("PYTHON_CROSS_PLATFORM", "unknown") +PYTHON_CROSS_SLICE = os.getenv("PYTHON_CROSS_SLICE", "unknown") +PYTHON_CROSS_MULTIARCH = os.getenv("PYTHON_CROSS_MULTIARCH", "unknown") + +# Determine some file system anchor points for the tests +# Assumes that the tests are run in a virtual environment named +# `cross-venv`, +VENV_PREFIX = Path(__file__).parent.parent / "cross-venv" +default_support_base = f"support/{sys.version_info.major}.{sys.version_info.minor}/{PYTHON_CROSS_PLATFORM}" +SUPPORT_PREFIX = ( + Path(__file__).parent.parent + / os.getenv("PYTHON_SUPPORT_BASE", default_support_base) + / "Python.xcframework" + / PYTHON_CROSS_SLICE +) + + +########################################################################### +# sys +########################################################################### + +def test_sys_platform(): + assert sys.platform == PYTHON_CROSS_PLATFORM.lower() + + +def test_sys_cross_compiling(): + assert sys.cross_compiling + + +def test_sys_multiarch(): + assert sys.implementation._multiarch == PYTHON_CROSS_MULTIARCH + + +def test_sys_base_prefix(): + assert Path(sys.base_prefix) == SUPPORT_PREFIX + + +def test_sys_base_exec_prefix(): + assert Path(sys.base_exec_prefix) == SUPPORT_PREFIX + + +########################################################################### +# platform +########################################################################### + +def test_platform_system(): + assert platform.system() == PYTHON_CROSS_PLATFORM + + +########################################################################### +# sysconfig +########################################################################### + +def test_sysconfig_get_platform(): + parts = sysconfig.get_platform().split("-", 2) + assert parts[0] == PYTHON_CROSS_PLATFORM.lower() + assert parts[2] == PYTHON_CROSS_MULTIARCH + + +def test_sysconfig_get_sysconfigdata_name(): + parts = sysconfig._get_sysconfigdata_name().split("_", 4) + assert parts[3] == PYTHON_CROSS_PLATFORM.lower() + assert parts[4] == PYTHON_CROSS_MULTIARCH + + +@pytest.mark.parametrize( + "name, prefix", + [ + # Paths that should be relative to the support folder + ("stdlib", SUPPORT_PREFIX), + ("include", SUPPORT_PREFIX), + ("platinclude", SUPPORT_PREFIX), + ("stdlib", SUPPORT_PREFIX), + # paths that should be relative to the venv + ("platstdlib", VENV_PREFIX), + ("purelib", VENV_PREFIX), + ("platlib", VENV_PREFIX), + ("scripts", VENV_PREFIX), + ("data", VENV_PREFIX), + ] +) +def test_sysconfig_get_paths(name, prefix): + assert sysconfig.get_paths()[name].startswith(str(prefix))