- Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathbindings_configuration.py
73 lines (54 loc) · 2.43 KB
/
bindings_configuration.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# SPDX-License-Identifier: BSD-2-Clause
# Copyright (c) 2025 Phil Thompson <phil@riverbankcomputing.com>
importos
from ..exceptionsimportUserFileException, UserParseException
from ..tomlimporttoml_load
defget_bindings_configuration(spec, sip_file, sip_include_dirs):
""" Get the configuration of a set of bindings. """
# We make no assumption about the name of the .sip file but we assume that
# the directory it is in is the name of the bindings.
bindings_name=os.path.basename(os.path.dirname(sip_file))
# See if there is a .toml file.
forsip_dirinsip_include_dirs:
toml_file=os.path.join(sip_dir, bindings_name,
bindings_name+'.toml')
ifos.path.isfile(toml_file):
break
else:
return [], []
# Read the configuration.
try:
cfg=toml_load(toml_file)
exceptExceptionase:
raiseUserParseException(toml_file, detail=str(e))
# Check the major ABI versions are the same.
cfg_abi_version=cfg.get('sip-abi-version')
ifcfg_abi_versionisNoneornotisinstance(cfg_abi_version, str):
raiseUserFileException(toml_file,
"'sip-abi-version' must be specified as a string")
cfg_abi_major=int(cfg_abi_version.split('.')[0])
ifspec.target_abiisNone:
# Infer the target ABI major version if we don't yet know it.
spec.target_abi= (cfg_abi_major, None)
else:
major_version=spec.target_abi[0]
ifcfg_abi_major!=major_version:
raiseUserFileException(toml_file,
f"'{bindings_name}' was built against ABI v{cfg_abi_major} "
"but this module is being built against ABI v{major_version}")
# Return the tags and disabled features.
return (_get_string_list(toml_file, cfg, 'module-tags'),
_get_string_list(toml_file, cfg, 'module-disabled-features'))
def_get_string_list(toml_file, cfg, name):
""" Get an option from the configuration and check it is a list of strings.
"""
option_list=cfg.get(name)
ifoption_listisNone:
option_list=list()
elifnotisinstance(option_list, list):
raiseUserFileException(toml_file, "'{0}' must be a list".format(name))
foroptioninoption_list:
ifnotisinstance(option, str):
raiseUserFileException(toml_file,
"elements of '{0}' must be strings".format(name))
returnoption_list