Skip to content

Commit

Permalink
Added support for Python v3.13
Browse files Browse the repository at this point in the history
Python v3.13 raises the minimum macOS version to 10.13.  Ensure that this
minimum is used for wheel names for projects where all modules use the
limited ABI, no matter what the minimum requirement of the version of
Python being used to build the wheel is.

Resolves #22
  • Loading branch information
philthompson10 committed Jun 13, 2024
1 parent 51f3e60 commit 830d8be
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 21 deletions.
14 changes: 3 additions & 11 deletions sipbuild/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import sys

from .abstract_builder import AbstractBuilder
from .buildable import BuildableFromSources
from .distinfo import write_metadata
from .exceptions import UserException
from .installable import Installable
Expand Down Expand Up @@ -121,18 +120,11 @@ def build_wheel(self, wheel_directory):
# Build the wheel contents.
self._generate_bindings()

# If all buildables use the limited API then the wheel does.
all_use_limited_api = True
for buildable in project.buildables:
if isinstance(buildable, BuildableFromSources):
if not buildable.uses_limited_api:
all_use_limited_api = False
break

# Create the wheel tag.
# Create the wheel tag. If all buildables use the limited API then the
# wheel does.
wheel_tag = []

if all_use_limited_api:
if project.all_modules_use_limited_abi:
# When the ABI tag is 'abi3' the interpreter tag is interpreted as
# a minimum Python version. This doesn't seem to be defined in a
# PEP but is implemented in current pips.
Expand Down
53 changes: 43 additions & 10 deletions sipbuild/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,20 @@
from .abstract_builder import AbstractBuilder
from .abstract_project import AbstractProject
from .bindings import Bindings
from .buildable import BuildableFromSources
from .configurable import Configurable, Option
from .exceptions import deprecated, UserException
from .module import resolve_abi_version
from .py_versions import OLDEST_SUPPORTED_MINOR
from .pyproject import PyProjectException, PyProjectOptionException


# The macOS minimum version of the latest supported version of Python. v10.13
# is the minimum version required by Python v3.13.
MACOS_MIN_OS_MAJOR = 10
MACOS_MIN_OS_MINOR = 13


class Project(AbstractProject, Configurable):
""" Encapsulate a project containing one or more sets of bindings. """

Expand Down Expand Up @@ -156,6 +163,17 @@ def __init__(self, **kwargs):

self.initialise_options(kwargs)

@property
def all_modules_use_limited_abi(self):
""" True if all modules in the project use the limited ABI. """

for buildable in self.buildables:
if isinstance(buildable, BuildableFromSources):
if not buildable.uses_limited_api:
return False

return True

def apply_nonuser_defaults(self, tool):
""" Set default values for non-user options that haven't been set yet.
"""
Expand Down Expand Up @@ -308,20 +326,36 @@ def get_platform_tag(self):

platform_tag = sysconfig.get_platform()

if self.py_platform == 'darwin' and self.minimum_macos_version:
if self.py_platform == 'darwin':
# We expect a three part tag so leave anything else unchanged.
parts = platform_tag.split('-')
if len(parts) == 3:
min_major = int(self.minimum_macos_version[0])
min_minor = int(self.minimum_macos_version[1])

# For arm64 binaries enforce a valid minimum macOS version.
min_major, min_minor = parts[1].split('.')
min_major = int(min_major)
min_minor = int(min_minor)

# Use the user supplied value if it is later than the platform
# value.
if self.minimum_macos_version:
user_min_major = int(self.minimum_macos_version[0])
user_min_minor = int(self.minimum_macos_version[1])

if (min_major, min_minor) < (user_min_major, user_min_minor):
min_major = user_min_major
min_minor = user_min_minor

# Enforce a minimum macOS version for limited ABI projects.
if self.all_modules_use_limited_abi and (min_major, min_minor) < (MACOS_MIN_OS_MAJOR, MACOS_MIN_OS_MINOR):
min_major = MACOS_MIN_OS_MAJOR
min_minor = MACOS_MIN_OS_MINOR

# Enforce a minimum macOS version for arm64 binaries.
if parts[2] == 'arm64' and min_major < 11:
min_major = 11
min_minor = 0

parts[1] = '{}.{}'.format(min_major, min_minor)

# Reassemble the tag.
parts[1] = f'{min_major}.{min_minor}'
platform_tag = '-'.join(parts)

elif self.py_platform == 'linux' and self.manylinux:
Expand All @@ -334,7 +368,7 @@ def get_platform_tag(self):
major, minor = 2, 5

parts[0] = 'manylinux'
parts.insert(1, '{}.{}'.format(major, minor))
parts.insert(1, f'{major}.{minor}')

platform_tag = '-'.join(parts)

Expand Down Expand Up @@ -362,8 +396,7 @@ def get_requires_dists(self):

next_abi_major = int(self.abi_version.split('.')[0]) + 1

return ['{} (>={}, <{})'.format(sip_project_name, self.abi_version,
next_abi_major)]
return [f'{sip_project_name} (>={self.abi_version}, <{next_abi_major})']

def get_sip_distinfo_command_line(self, sip_distinfo, inventory,
generator=None, wheel_tag=None, generator_version=None):
Expand Down

0 comments on commit 830d8be

Please sign in to comment.