Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_policy():
policy = load_policies()
policy_schema = _load_policy_schema()
validate(policy, policy_schema)
def configure_parser(sub_parsers):
policy_names = [p['name'] for p in load_policies()]
highest_policy = get_policy_name(POLICY_PRIORITY_HIGHEST)
help = "Vendor in external shared library dependencies of a wheel."
p = sub_parsers.add_parser('repair', help=help, description=help)
p.add_argument('WHEEL_FILE', help='Path to wheel file.')
p.add_argument('-f',
'--force',
help='Override symbol version ABI check',
action='store_true')
p.add_argument(
'--plat',
dest='PLAT',
help='Desired target platform. (default: "%s")' % highest_policy,
choices=policy_names,
default=highest_policy)
p.add_argument('-L',
'--lib-sdir',
def lddtree_external_references(lddtree: Dict, wheel_path: str):
# XXX: Document the lddtree structure, or put it in something
# more stable than a big nested dict
policies = load_policies()
def filter_libs(libs, whitelist):
for lib in libs:
if 'ld-linux' in lib or lib in ['ld64.so.2', 'ld64.so.1']:
# always exclude ELF dynamic linker/loader
# 'ld64.so.2' on s390x
# 'ld64.so.1' on ppc64le
# 'ld-linux*' on other platforms
continue
if LIBPYTHON_RE.match(lib):
# always exclude libpythonXY
continue
if lib in whitelist:
# exclude any libs in the whitelist
continue
yield lib
for name in (set(required_vers) & set(policy_sym_vers)):
if not required_vers[name].issubset(policy_sym_vers[name]):
for symbol in required_vers[name] - policy_sym_vers[name]:
log.debug('Package requires %s, incompatible with '
'policy %s which requires %s', symbol,
policy_name, policy_sym_vers[name])
policy_satisfied = False
return policy_satisfied
required_vers = {} # type: Dict[str, Set[str]]
for symbols in versioned_symbols.values():
for symbol in symbols:
sym_name, _, _ = symbol.partition("_")
required_vers.setdefault(sym_name, set()).add(symbol)
matching_policies = [] # type: List[int]
for p in load_policies():
policy_sym_vers = {
sym_name: {sym_name + '_' + version for version in versions}
for sym_name, versions in p['symbol_versions'].items()
}
if policy_is_satisfied(p['name'], policy_sym_vers):
matching_policies.append(p['priority'])
if len(matching_policies) == 0:
# the base policy (generic linux) should always match
raise RuntimeError('Internal error')
return max(matching_policies)
def analyze_wheel_abi(wheel_fn: str):
external_refs = {
p['name']: {'libs': {},
'priority': p['priority']}
for p in load_policies()
}
(elftree_by_fn, external_refs_by_fn, versioned_symbols, has_ucs2,
uses_PyFPE_jbuf) = get_wheel_elfdata(wheel_fn)
for fn in elftree_by_fn.keys():
update(external_refs, external_refs_by_fn[fn])
log.debug('external reference info')
log.debug(json.dumps(external_refs, indent=4))
external_libs = get_external_libs(external_refs)
external_versioned_symbols = get_versioned_symbols(external_libs)
symbol_policies = get_symbol_policies(versioned_symbols,
external_versioned_symbols,
external_refs)
def configure_parser(sub_parsers):
policy_names = [p['name'] for p in load_policies()]
highest_policy = get_policy_name(POLICY_PRIORITY_HIGHEST)
help = "Vendor in external shared library dependencies of a wheel."
p = sub_parsers.add_parser('repair', help=help, description=help)
p.add_argument('WHEEL_FILE', help='Path to wheel file.')
p.add_argument(
'--plat',
action=EnvironmentDefault,
env='AUDITWHEEL_PLAT',
dest='PLAT',
help='Desired target platform. (default: "%s")' % highest_policy,
choices=policy_names,
default=highest_policy)
p.add_argument('-L',
'--lib-sdir',
dest='LIB_SDIR',
help=('Subdirectory in packages to store copied libraries.'
'In order to achieve a more compatible tag, you would '
'need to recompile a new wheel from source on a system '
'with earlier versions of these libraries, such as '
'a recent manylinux image.') % winfo.sym_tag)
if args.verbose < 1:
return
libs = winfo.external_refs[get_policy_name(POLICY_PRIORITY_LOWEST)]['libs']
if len(libs) == 0:
printp('The wheel requires no external shared libraries! :)')
else:
printp(('The following external shared libraries are required '
'by the wheel:'))
print(json.dumps(OrderedDict(sorted(libs.items())), indent=4))
for p in sorted(load_policies(), key=lambda p: p['priority']):
if p['priority'] > get_priority_by_name(winfo.overall_tag):
printp(('In order to achieve the tag platform tag "%s" '
'the following shared library dependencies '
'will need to be eliminated:') % p['name'])
printp(', '.join(
sorted(winfo.external_refs[p['name']]['libs'].keys())))