Skip to content

Commit

Permalink
feat: macos free-threading
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
  • Loading branch information
henryiii committed Jun 7, 2024
1 parent e41cb0f commit fc2cfe0
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 7 deletions.
21 changes: 16 additions & 5 deletions cibuildwheel/macos.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
detect_ci_provider,
download,
find_compatible_wheel,
free_thread_enable_313,
get_build_verbosity_extra_flags,
get_pip_version,
install_certifi_script,
Expand Down Expand Up @@ -115,7 +116,7 @@ def get_python_configurations(
return python_configurations


def install_cpython(tmp: Path, version: str, url: str) -> Path:
def install_cpython(tmp: Path, version: str, url: str, free_threading: bool) -> Path:
installation_path = Path(f"/Library/Frameworks/Python.framework/Versions/{version}")
with FileLock(CIBW_CACHE_PATH / f"cpython{version}.lock"):
installed_system_packages = call("pkgutil", "--pkgs", capture_stdout=True).splitlines()
Expand All @@ -137,13 +138,19 @@ def install_cpython(tmp: Path, version: str, url: str) -> Path:
# download the pkg
download(url, pkg_path)
# install
call("sudo", "installer", "-pkg", pkg_path, "-target", "/")
args = []
if version.startswith("3.13"):
# Python 3.13 is the first version to have a free-threading option
args += ["-applyChoiceChangesXML", str(free_thread_enable_313.resolve())]
call("sudo", "installer", "-pkg", pkg_path, *args, "-target", "/")
pkg_path.unlink()
env = os.environ.copy()
env["PIP_DISABLE_PIP_VERSION_CHECK"] = "1"
call(installation_path / "bin" / "python3", install_certifi_script, env=env)
call(installation_path / "bin/python3", install_certifi_script, env=env)
if version.startswith("3.13"):
call(installation_path / "bin/python3.13t", install_certifi_script, env=env)

return installation_path / "bin" / "python3"
return installation_path / "bin" / (f"python{version}t" if free_threading else "python3")


def install_pypy(tmp: Path, url: str) -> Path:
Expand Down Expand Up @@ -172,7 +179,11 @@ def setup_python(
implementation_id = python_configuration.identifier.split("-")[0]
log.step(f"Installing Python {implementation_id}...")
if implementation_id.startswith("cp"):
base_python = install_cpython(tmp, python_configuration.version, python_configuration.url)
free_threading = "t-macos" in python_configuration.identifier
base_python = install_cpython(
tmp, python_configuration.version, python_configuration.url, free_threading
)

elif implementation_id.startswith("pp"):
base_python = install_pypy(tmp, python_configuration.url)
else:
Expand Down
3 changes: 3 additions & 0 deletions cibuildwheel/resources/build-platforms.toml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ python_configurations = [
{ identifier = "cp313-macosx_x86_64", version = "3.13", url = "https://www.python.org/ftp/python/3.13.0/python-3.13.0b2-macos11.pkg" },
{ identifier = "cp313-macosx_arm64", version = "3.13", url = "https://www.python.org/ftp/python/3.13.0/python-3.13.0b2-macos11.pkg" },
{ identifier = "cp313-macosx_universal2", version = "3.13", url = "https://www.python.org/ftp/python/3.13.0/python-3.13.0b2-macos11.pkg" },
{ identifier = "cp313t-macosx_x86_64", version = "3.13", url = "https://www.python.org/ftp/python/3.13.0/python-3.13.0b2-macos11.pkg" },
{ identifier = "cp313t-macosx_arm64", version = "3.13", url = "https://www.python.org/ftp/python/3.13.0/python-3.13.0b2-macos11.pkg" },
{ identifier = "cp313t-macosx_universal2", version = "3.13", url = "https://www.python.org/ftp/python/3.13.0/python-3.13.0b2-macos11.pkg" },
{ identifier = "pp37-macosx_x86_64", version = "3.7", url = "https://downloads.python.org/pypy/pypy3.7-v7.3.9-osx64.tar.bz2" },
{ identifier = "pp38-macosx_x86_64", version = "3.8", url = "https://downloads.python.org/pypy/pypy3.8-v7.3.11-macos_x86_64.tar.bz2" },
{ identifier = "pp38-macosx_arm64", version = "3.8", url = "https://downloads.python.org/pypy/pypy3.8-v7.3.11-macos_arm64.tar.bz2" },
Expand Down
14 changes: 14 additions & 0 deletions cibuildwheel/resources/free-threaded-enable-313.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
<dict>
<key>attributeSetting</key>
<integer>1</integer>
<key>choiceAttribute</key>
<string>selected</string>
<key>choiceIdentifier</key>
<string>org.python.Python.PythonTFramework-3.13</string>
</dict>
</array>
</plist>
2 changes: 2 additions & 0 deletions cibuildwheel/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@

install_certifi_script: Final[Path] = resources_dir / "install_certifi.py"

free_thread_enable_313: Final[Path] = resources_dir / "free-threaded-enable-313.xml"

test_fail_cwd_file: Final[Path] = resources_dir / "testing_temp_dir_file.py"


Expand Down
3 changes: 1 addition & 2 deletions test/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,8 @@ def expected_wheels(
"cp311-cp311",
"cp312-cp312",
"cp313-cp313",
"cp313-cp313t",
]
if platform != "macos":
python_abi_tags.append("cp313-cp313t")

if machine_arch in ["x86_64", "AMD64", "x86", "aarch64"]:
python_abi_tags += [
Expand Down

0 comments on commit fc2cfe0

Please sign in to comment.