Skip to content

Commit

Permalink
chore: enable experimental free-threaded python 3.13 on unix
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelotduarte committed Jan 1, 2025
1 parent 5e1b439 commit a9bdf21
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 35 deletions.
3 changes: 2 additions & 1 deletion ci/build-wheel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ PY_PLATFORM=$($PYTHON -c "import sysconfig; print(sysconfig.get_platform(), end=
PY_VERSION=$($PYTHON -c "import sysconfig; print(sysconfig.get_python_version(), end='')")
PY_VERSION_FULL=$($PYTHON -c "import sysconfig; print(sysconfig.get_config_var('py_version'), end='')")
PY_VERSION_NODOT=$($PYTHON -c "import sysconfig; print(sysconfig.get_config_var('py_version_nodot'), end='')")
PY_ABI_THREAD=$($PYTHON -c "import sysconfig; print(sysconfig.get_config_var('abi_thread') or '', end='')")

PYTHON_TAG=cp$PY_VERSION_NODOT
PYTHON_TAG=cp$PY_VERSION_NODOT$PY_ABI_THREAD
if [[ $PY_PLATFORM == linux* ]]; then
PLATFORM_TAG=many$(echo $PY_PLATFORM | sed 's/\-/_/')
PLATFORM_TAG_MASK="$(echo $PLATFORM_TAG | sed 's/_/*_/')"
Expand Down
4 changes: 3 additions & 1 deletion cx_Freeze/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from pathlib import Path

__all__ = [
"ABI_THREAD",
"BUILD_EXE_DIR",
"EXE_SUFFIX",
"EXT_SUFFIX",
Expand All @@ -21,8 +22,9 @@

PLATFORM = sysconfig.get_platform()
PYTHON_VERSION = sysconfig.get_python_version()
ABI_THREAD = sysconfig.get_config_var("abi_thread") or ""

BUILD_EXE_DIR = Path(f"build/exe.{PLATFORM}-{PYTHON_VERSION}")
BUILD_EXE_DIR = Path(f"build/exe.{PLATFORM}-{PYTHON_VERSION}{ABI_THREAD}")
EXE_SUFFIX = sysconfig.get_config_var("EXE")
EXT_SUFFIX = sysconfig.get_config_var("EXT_SUFFIX")

Expand Down
14 changes: 10 additions & 4 deletions cx_Freeze/executable.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from typing import TYPE_CHECKING

from cx_Freeze._compat import (
ABI_THREAD,
EXE_SUFFIX,
IS_MACOS,
IS_MINGW,
Expand Down Expand Up @@ -74,12 +75,17 @@ def base(self) -> Path:

@base.setter
def base(self, name: str | Path | None) -> None:
# The default base is the legacy console, except for
# The default base is the legacy console, except for Python 3.13t and
# Python 3.13 on macOS, that supports only the new console
if IS_MACOS and sys.version_info[:2] >= (3, 13):
name = name or "console"
else:
version = sys.version_info[:2]
if (
version <= (3, 13)
and ABI_THREAD == ""
and not (IS_MACOS and version == (3, 13))
):
name = name or "console_legacy"
else:
name = name or "console"
# silently ignore gui and service on non-windows systems
if not (IS_WINDOWS or IS_MINGW) and name in ("gui", "service"):
name = "console"
Expand Down
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ dynamic = ["version"]

[project.optional-dependencies]
dev = [
"bump-my-version==0.29.0",
"bump-my-version==0.29.0 ;python_version < '3.13'",
"cibuildwheel==2.22.0",
"pre-commit==4.0.1", # python_version >= 3.9
]
Expand Down Expand Up @@ -164,9 +164,11 @@ optional_value = "final"
before-build = "uv pip install -r requirements.txt"
build-frontend = "build[uv]"
build-verbosity = 1
enable = ["cpython-freethreading"]
skip = [
"cp3{9,10,13}-musllinux_*",
"cp3{9,10,13}-manylinux_ppc64le",
"cp313t-win*",
]

[tool.cibuildwheel.linux]
Expand Down
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
bump-my-version==0.29.0
bump-my-version==0.29.0 ;python_version < '3.13'
cibuildwheel==2.22.0
pre-commit==4.0.1
57 changes: 34 additions & 23 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ def build_extension(self, ext) -> None:
library_dirs.append(get_config_var("LIBPL"))
if not ENABLE_SHARED or IS_CONDA:
library_dirs.append(get_config_var("LIBDIR"))
libraries.append(f"python{get_python_version()}")
abi_thread = get_config_var("abi_thread") or ""
libraries.append(f"python{get_python_version()}{abi_thread}")
if get_config_var("LIBS"):
extra_args.extend(get_config_var("LIBS").split())
if get_config_var("LIBM"):
Expand Down Expand Up @@ -275,38 +276,48 @@ def get_extensions() -> list[Extension]:
os.environ.get("CI", "") != "true"
or os.environ.get("CIBUILDWHEEL", "0") != "1"
)
abi_thread = get_config_var("abi_thread") or ""
version = sys.version_info[:2]
extensions = [
Extension(
"cx_Freeze.bases.console",
["source/bases/console.c", "source/bases/_common.c"],
optional=optional,
),
Extension(
"cx_Freeze.bases.console_legacy",
["source/legacy/console.c"],
depends=["source/legacy/common.c"],
optional=optional
or (sys.version_info[:2] >= (3, 13) and IS_MACOS),
),
)
]

if IS_MINGW or IS_WINDOWS:
if (
version <= (3, 13)
and abi_thread == ""
and not (IS_MACOS and version == (3, 13))
):
extensions += [
Extension(
"cx_Freeze.bases.Win32GUI",
["source/legacy/Win32GUI.c"],
"cx_Freeze.bases.console_legacy",
["source/legacy/console.c"],
depends=["source/legacy/common.c"],
libraries=["user32"],
optional=optional,
),
Extension(
"cx_Freeze.bases.Win32Service",
["source/legacy/Win32Service.c"],
depends=["source/legacy/common.c"],
extra_link_args=["/DELAYLOAD:cx_Logging"],
libraries=["advapi32"],
optional=optional,
),
)
]
if IS_MINGW or IS_WINDOWS:
if version <= (3, 13) and abi_thread == "":
extensions += [
Extension(
"cx_Freeze.bases.Win32GUI",
["source/legacy/Win32GUI.c"],
depends=["source/legacy/common.c"],
libraries=["user32"],
optional=optional,
),
Extension(
"cx_Freeze.bases.Win32Service",
["source/legacy/Win32Service.c"],
depends=["source/legacy/common.c"],
extra_link_args=["/DELAYLOAD:cx_Logging"],
libraries=["advapi32"],
optional=optional,
),
]
extensions += [
Extension(
"cx_Freeze.bases.gui",
["source/bases/Win32GUI.c", "source/bases/_common.c"],
Expand Down
13 changes: 9 additions & 4 deletions tests/test_executables.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

from cx_Freeze import Executable
from cx_Freeze._compat import (
ABI_THREAD,
BUILD_EXE_DIR,
EXE_SUFFIX,
IS_MACOS,
Expand Down Expand Up @@ -241,14 +242,18 @@ def test_executables(
("icon.ico", "icon.icns", "icon.png", "icon.svg"),
),
]
if IS_MACOS and sys.version_info[:2] >= (3, 13):
if (
sys.version_info[:2] <= (3, 13)
and ABI_THREAD == ""
and not (IS_MACOS and sys.version_info[:2] == (3, 13))
):
TEST_VALID_PARAMETERS += [
("base", None, "console-"),
("base", None, "console_legacy-"),
("base", "console_legacy", "console_legacy-"),
]
else:
TEST_VALID_PARAMETERS += [
("base", None, "console_legacy-"),
("base", "console_legacy", "console_legacy-"),
("base", None, "console-"),
]
if IS_WINDOWS or IS_MINGW:
TEST_VALID_PARAMETERS += [
Expand Down

0 comments on commit a9bdf21

Please sign in to comment.