Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure policies in policy.json are compliant with PEP600 #287

Merged
merged 2 commits into from
Feb 28, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion auditwheel/policy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import sys
import json
import platform as _platform_module
from typing import Optional, List
from collections import defaultdict
from typing import Dict, List, Optional, Set
from os.path import join, dirname, abspath
import logging

Expand All @@ -23,9 +24,30 @@ def get_arch_name() -> str:
_ARCH_NAME = get_arch_name()


def _validate_pep600_compliance(policies) -> None:
symbol_versions: Dict[str, Dict[str, Set[str]]] = {}
lib_whitelist: Set[str] = set()
for policy in sorted(policies, key=lambda x: x['priority'], reverse=True):
if policy['name'] == 'linux':
continue
if not lib_whitelist.issubset(set(policy['lib_whitelist'])):
raise ValueError('Invalid "policy.json" file')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about making the string more explicit on what's wrong with the policy check? That could make it easier to diagnose the issue when editing the JSON.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added more information and tests for that. Is that better now ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thanks!

lib_whitelist.update(policy['lib_whitelist'])
for arch in policy['symbol_versions'].keys():
symbol_versions_arch = symbol_versions.get(arch, defaultdict(set))
for prefix in policy['symbol_versions'][arch].keys():
if not symbol_versions_arch[prefix].issubset(
set(policy['symbol_versions'][arch][prefix])):
raise ValueError('Invalid "policy.json" file')
symbol_versions_arch[prefix].update(
policy['symbol_versions'][arch][prefix])
symbol_versions[arch] = symbol_versions_arch


with open(join(dirname(abspath(__file__)), 'policy.json')) as f:
_POLICIES = []
_policies_temp = json.load(f)
_validate_pep600_compliance(_policies_temp)
for _p in _policies_temp:
if _ARCH_NAME in _p['symbol_versions'].keys() or _p['name'] == 'linux':
if _p['name'] != 'linux':
Expand Down
5 changes: 2 additions & 3 deletions auditwheel/policy/policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"symbol_versions": {
"i686": {
"CXXABI": ["1.3", "1.3.1"],
"GCC": ["3.0", "3.3", "3.3.1", "3.4", "3.4.2", "3.4.4", "4.0.0", "4.2.0"],
"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"],
"GCC": ["3.0", "3.3", "3.3.1", "3.4", "3.4.2", "4.0.0", "4.2.0"],
"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"],
"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"]
},
"x86_64": {
Expand All @@ -21,7 +21,6 @@
}
},
"lib_whitelist": [
"libpanelw.so.5", "libncursesw.so.5",
"libgcc_s.so.1",
"libstdc++.so.6",
"libm.so.6", "libdl.so.2", "librt.so.1",
Expand Down
55 changes: 54 additions & 1 deletion tests/unit/test_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pytest

from auditwheel.policy import get_arch_name, get_policy_name, \
get_priority_by_name, get_replace_platforms
get_priority_by_name, get_replace_platforms, _validate_pep600_compliance


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


def test_pep600_compliance():
_validate_pep600_compliance([{
"name": "manylinux1", "priority": 100, "symbol_versions": {
"i686": {"CXXABI": ["1.3"]},
},
"lib_whitelist": ["libgcc_s.so.1"]
}, {
"name": "manylinux2010", "priority": 90, "symbol_versions": {
"i686": {"CXXABI": ["1.3", "1.3.1"]},
},
"lib_whitelist": ["libgcc_s.so.1", "libstdc++.so.6"],
}])

_validate_pep600_compliance([{
"name": "manylinux1", "priority": 100, "symbol_versions": {
"i686": {"CXXABI": ["1.3"]},
"x86_64": {"CXXABI": ["1.3"]},
},
"lib_whitelist": ["libgcc_s.so.1"]
}, {
"name": "manylinux2010", "priority": 90, "symbol_versions": {
"i686": {"CXXABI": ["1.3", "1.3.1"]},
},
"lib_whitelist": ["libgcc_s.so.1", "libstdc++.so.6"],
}])

with pytest.raises(ValueError):
_validate_pep600_compliance([{
"name": "manylinux1", "priority": 100, "symbol_versions": {
"i686": {"CXXABI": ["1.3", "1.3.2"]},
},
"lib_whitelist": ["libgcc_s.so.1"]
}, {
"name": "manylinux2010", "priority": 90, "symbol_versions": {
"i686": {"CXXABI": ["1.3", "1.3.1"]},
},
"lib_whitelist": ["libgcc_s.so.1", "libstdc++.so.6"],
}])

with pytest.raises(ValueError):
_validate_pep600_compliance([{
"name": "manylinux1", "priority": 100, "symbol_versions": {
"i686": {"CXXABI": ["1.3"]},
},
"lib_whitelist": ["libgcc_s.so.1", "libstdc++.so.6"]
}, {
"name": "manylinux2010", "priority": 90, "symbol_versions": {
"i686": {"CXXABI": ["1.3", "1.3.1"]},
},
"lib_whitelist": ["libgcc_s.so.1"],
}])


class TestPolicyAccess:

def test_get_by_priority(self):
Expand Down