Skip to content

Commit 70e167d

Browse files
authored
Ensure policies in policy.json are compliant with PEP600 (#287)
This removes 2 non existing symbols from manylinux1 i686 policy and removes ncurses librairies from manylinux1 whitelist.
1 parent 22c8451 commit 70e167d

File tree

3 files changed

+91
-5
lines changed

3 files changed

+91
-5
lines changed

auditwheel/policy/__init__.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import sys
22
import json
33
import platform as _platform_module
4-
from typing import Optional, List
4+
from collections import defaultdict
5+
from typing import Dict, List, Optional, Set
56
from os.path import join, dirname, abspath
67
import logging
78

@@ -23,9 +24,42 @@ def get_arch_name() -> str:
2324
_ARCH_NAME = get_arch_name()
2425

2526

27+
def _validate_pep600_compliance(policies) -> None:
28+
symbol_versions: Dict[str, Dict[str, Set[str]]] = {}
29+
lib_whitelist: Set[str] = set()
30+
for policy in sorted(policies, key=lambda x: x['priority'], reverse=True):
31+
if policy['name'] == 'linux':
32+
continue
33+
if not lib_whitelist.issubset(set(policy['lib_whitelist'])):
34+
diff = lib_whitelist - set(policy["lib_whitelist"])
35+
raise ValueError(
36+
'Invalid "policy.json" file. Missing whitelist libraries in '
37+
f'"{policy["name"]}" compared to previous policies: {diff}'
38+
)
39+
lib_whitelist.update(policy['lib_whitelist'])
40+
for arch in policy['symbol_versions'].keys():
41+
symbol_versions_arch = symbol_versions.get(arch, defaultdict(set))
42+
for prefix in policy['symbol_versions'][arch].keys():
43+
policy_symbol_versions = set(
44+
policy['symbol_versions'][arch][prefix])
45+
if not symbol_versions_arch[prefix].issubset(
46+
policy_symbol_versions):
47+
diff = symbol_versions_arch[prefix] - \
48+
policy_symbol_versions
49+
raise ValueError(
50+
'Invalid "policy.json" file. Symbol versions missing '
51+
f'in "{policy["name"]}_{arch}" for "{prefix}" '
52+
f'compared to previous policies: {diff}'
53+
)
54+
symbol_versions_arch[prefix].update(
55+
policy['symbol_versions'][arch][prefix])
56+
symbol_versions[arch] = symbol_versions_arch
57+
58+
2659
with open(join(dirname(abspath(__file__)), 'policy.json')) as f:
2760
_POLICIES = []
2861
_policies_temp = json.load(f)
62+
_validate_pep600_compliance(_policies_temp)
2963
for _p in _policies_temp:
3064
if _ARCH_NAME in _p['symbol_versions'].keys() or _p['name'] == 'linux':
3165
if _p['name'] != 'linux':

auditwheel/policy/policy.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
"symbol_versions": {
1010
"i686": {
1111
"CXXABI": ["1.3", "1.3.1"],
12-
"GCC": ["3.0", "3.3", "3.3.1", "3.4", "3.4.2", "3.4.4", "4.0.0", "4.2.0"],
13-
"GLIBC": ["2.0", "2.1", "2.1.1", "2.1.2", "2.1.3", "2.2", "2.2.1", "2.2.2", "2.2.3", "2.2.4", "2.2.5", "2.2.6", "2.3", "2.3.2", "2.3.3", "2.3.4", "2.4", "2.5"],
12+
"GCC": ["3.0", "3.3", "3.3.1", "3.4", "3.4.2", "4.0.0", "4.2.0"],
13+
"GLIBC": ["2.0", "2.1", "2.1.1", "2.1.2", "2.1.3", "2.2", "2.2.1", "2.2.2", "2.2.3", "2.2.4", "2.2.6", "2.3", "2.3.2", "2.3.3", "2.3.4", "2.4", "2.5"],
1414
"GLIBCXX": ["3.4", "3.4.1", "3.4.2", "3.4.3", "3.4.4", "3.4.5", "3.4.6", "3.4.7", "3.4.8"]
1515
},
1616
"x86_64": {
@@ -21,7 +21,6 @@
2121
}
2222
},
2323
"lib_whitelist": [
24-
"libpanelw.so.5", "libncursesw.so.5",
2524
"libgcc_s.so.1",
2625
"libstdc++.so.6",
2726
"libm.so.6", "libdl.so.2", "librt.so.1",

tests/unit/test_policy.py

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import pytest
44

55
from auditwheel.policy import get_arch_name, get_policy_name, \
6-
get_priority_by_name, get_replace_platforms
6+
get_priority_by_name, get_replace_platforms, _validate_pep600_compliance
77

88

99
@patch("auditwheel.policy._platform_module.machine")
@@ -43,6 +43,59 @@ def test_replacement_platform(name, expected):
4343
assert get_replace_platforms(name) == expected
4444

4545

46+
def test_pep600_compliance():
47+
_validate_pep600_compliance([{
48+
"name": "manylinux1", "priority": 100, "symbol_versions": {
49+
"i686": {"CXXABI": ["1.3"]},
50+
},
51+
"lib_whitelist": ["libgcc_s.so.1"]
52+
}, {
53+
"name": "manylinux2010", "priority": 90, "symbol_versions": {
54+
"i686": {"CXXABI": ["1.3", "1.3.1"]},
55+
},
56+
"lib_whitelist": ["libgcc_s.so.1", "libstdc++.so.6"],
57+
}])
58+
59+
_validate_pep600_compliance([{
60+
"name": "manylinux1", "priority": 100, "symbol_versions": {
61+
"i686": {"CXXABI": ["1.3"]},
62+
"x86_64": {"CXXABI": ["1.3"]},
63+
},
64+
"lib_whitelist": ["libgcc_s.so.1"]
65+
}, {
66+
"name": "manylinux2010", "priority": 90, "symbol_versions": {
67+
"i686": {"CXXABI": ["1.3", "1.3.1"]},
68+
},
69+
"lib_whitelist": ["libgcc_s.so.1", "libstdc++.so.6"],
70+
}])
71+
72+
with pytest.raises(ValueError, match="manylinux2010_i686.*CXXABI.*1.3.2"):
73+
_validate_pep600_compliance([{
74+
"name": "manylinux1", "priority": 100, "symbol_versions": {
75+
"i686": {"CXXABI": ["1.3", "1.3.2"]},
76+
},
77+
"lib_whitelist": ["libgcc_s.so.1"]
78+
}, {
79+
"name": "manylinux2010", "priority": 90, "symbol_versions": {
80+
"i686": {"CXXABI": ["1.3", "1.3.1"]},
81+
},
82+
"lib_whitelist": ["libgcc_s.so.1", "libstdc++.so.6"],
83+
}])
84+
85+
with pytest.raises(ValueError, match="manylinux2010.*libstdc\+\+\.so\.6"):
86+
_validate_pep600_compliance([{
87+
"name": "manylinux1", "priority": 100, "symbol_versions": {
88+
"i686": {"CXXABI": ["1.3"]},
89+
},
90+
"lib_whitelist": ["libgcc_s.so.1", "libstdc++.so.6"]
91+
}, {
92+
"name": "manylinux2010", "priority": 90, "symbol_versions": {
93+
"i686": {"CXXABI": ["1.3", "1.3.1"]},
94+
},
95+
"lib_whitelist": ["libgcc_s.so.1"],
96+
}])
97+
98+
4699
class TestPolicyAccess:
47100

48101
def test_get_by_priority(self):

0 commit comments

Comments
 (0)