From 997a5f001b16332947ca4062ea7d0b908ce9fb40 Mon Sep 17 00:00:00 2001 From: Phil Thompson Date: Sat, 28 Dec 2024 15:16:38 +0000 Subject: [PATCH] Default ABI version 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 --- docs/pyproject_toml.rst | 7 ++-- sipbuild/bindings_configuration.py | 2 +- sipbuild/module/abi_version.py | 54 ++++++++++++++---------------- sipbuild/project.py | 5 ++- 4 files changed, 33 insertions(+), 35 deletions(-) diff --git a/docs/pyproject_toml.rst b/docs/pyproject_toml.rst index f5921410..f162c7f9 100644 --- a/docs/pyproject_toml.rst +++ b/docs/pyproject_toml.rst @@ -96,9 +96,10 @@ list options may contain environment markers as defined in `PEP 508 `__. **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` diff --git a/sipbuild/bindings_configuration.py b/sipbuild/bindings_configuration.py index b1d10d57..8242e3a7 100644 --- a/sipbuild/bindings_configuration.py +++ b/sipbuild/bindings_configuration.py @@ -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, diff --git a/sipbuild/module/abi_version.py b/sipbuild/module/abi_version.py index e7f55931..757cb4fe 100644 --- a/sipbuild/module/abi_version.py +++ b/sipbuild/module/abi_version.py @@ -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}' diff --git a/sipbuild/project.py b/sipbuild/project.py index aeec73dc..f49d1b92 100644 --- a/sipbuild/project.py +++ b/sipbuild/project.py @@ -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.