Skip to content

Commit

Permalink
Default ABI version
Browse files Browse the repository at this point in the history
The default minor ABI version to use is now the latest minor version for a
particular major version (rather than `0` as it was previously).

Resolves #63
  • Loading branch information
philthompson10 committed Dec 28, 2024
1 parent a0d45a9 commit 997a5f0
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 35 deletions.
7 changes: 4 additions & 3 deletions docs/pyproject_toml.rst
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,10 @@ list options may contain environment markers as defined in `PEP 508
<https://www.python.org/dev/peps/pep-0508/>`__.

**abi-version**
The minimum version number of the ABI of the :mod:`sip` module being used.
If only the major version number is specified then the minor version
defaults to 0. By the default the latest major version is used.
The version number of the ABI of the :mod:`sip` module to generate code
for. By the default the latest major version is used. If the minor
version is not specified then the latest minor version of the major version
is used.

**api-dir**
The value is the name of a the directory in which a QScintilla :file:`.api`
Expand Down
2 changes: 1 addition & 1 deletion sipbuild/bindings_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def get_bindings_configuration(abi_major, sip_file, sip_include_dirs):
except Exception as e:
raise UserParseException(toml_file, detail=str(e))

# Check the ABI version is compatible.
# Check the major ABI versions are the same.
cfg_abi_version = cfg.get('sip-abi-version')
if cfg_abi_version is None or not isinstance(cfg_abi_version, str):
raise UserFileException(toml_file,
Expand Down
54 changes: 26 additions & 28 deletions sipbuild/module/abi_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,46 +52,44 @@ def get_sip_module_version(abi_major_version):
return f'{abi_major_version}.{abi_minor_version}.{patch_version}'


def resolve_abi_version(abi_version, module=True):
""" Return a valid ABI version or the latest if none was given. """
def resolve_abi_version(abi_version):
""" Return a valid ABI version defaulting to the latest. """

# Get the major and minimum minor version of what we need.
# Assume we are using the default minor version.
minor_version = -1

# Make sure we have a valid major version.
if abi_version:
parts = abi_version.split('.')
abi_major_version = parts[0]
major_version = parts[0]

if not os.path.isdir(get_module_source_dir(abi_major_version)):
if not os.path.isdir(get_module_source_dir(major_version)):
raise UserException(
f"'{abi_version}' is not a supported ABI version")

if len(parts) == 1:
minimum_minor_version = 0
else:
if len(parts) != 1:
try:
minimum_minor_version = int(parts[1])
minor_version = int(parts[1])
except ValueError:
minimum_minor_version = None
pass

if len(parts) > 2 or minimum_minor_version is None:
if len(parts) > 2 or minor_version < 0:
raise UserException(
f"'{abi_version}' is not a valid ABI version")
else:
abi_major_version = sorted(os.listdir(_module_source_dir), key=int)[-1]
# v13.0 is deprecated so explicitly exclude it to avoid a later
# deprecation warning.
minimum_minor_version = 1 if abi_major_version == '13' else 0

# Get the minor version of what we actually have.
module_version = get_sip_module_version(abi_major_version)
_, abi_minor_version, _ = module_version.split('.')

# Check we meet the minimum requirement.
if int(abi_minor_version) < minimum_minor_version:
# Default to the latest major version.
major_version = sorted(os.listdir(_module_source_dir), key=int)[-1]

# Get the latest minor version of the major version.
latest_version = get_sip_module_version(major_version)
_, latest_minor_version, _ = latest_version.split('.')
latest_minor_version = int(latest_minor_version)

# Get or validate the minor version to use.
if minor_version < 0:
minor_version = latest_minor_version
elif minor_version > latest_minor_version:
raise UserException(f"'{abi_version}' is not a supported ABI version")

if module:
# Return the module's version.
return f'{abi_major_version}.{abi_minor_version}'

# Return the required version.
return f'{abi_major_version}.{minimum_minor_version}'
# Return the version.
return f'{major_version}.{minor_version}'
5 changes: 2 additions & 3 deletions sipbuild/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -685,9 +685,8 @@ def verify_configuration(self, tool):
"Python v{}.{} is not supported".format(
self.py_major_version, self.py_minor_version))

# Get the supported ABI version. (The actual version may have a later
# minor version.)
self.abi_version = resolve_abi_version(self.abi_version, module=False)
# Get the ABI version to use.
self.abi_version = resolve_abi_version(self.abi_version)

# These ABI versions are deprecated because we have deprecated any
# arguments to 'throw()' which these versions rely on.
Expand Down

0 comments on commit 997a5f0

Please sign in to comment.