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

Remove globals in policy module #466

Merged
merged 3 commits into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
30 changes: 14 additions & 16 deletions src/auditwheel/main_repair.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,15 @@

from auditwheel.patcher import Patchelf

from .policy import (
POLICY_PRIORITY_HIGHEST,
get_policy_by_name,
get_policy_name,
get_priority_by_name,
load_policies,
)
from .policy import WheelPolicies
from .tools import EnvironmentDefault

logger = logging.getLogger(__name__)


def configure_parser(sub_parsers):
policies = load_policies()
wheel_policy = WheelPolicies()
policies = wheel_policy.policies
policy_names = [p["name"] for p in policies]
policy_names += [alias for p in policies for alias in p["aliases"]]
epilog = """PLATFORMS:
Expand All @@ -32,7 +27,7 @@ def configure_parser(sub_parsers):
if len(p["aliases"]) > 0:
epilog += f" (aliased by {', '.join(p['aliases'])})"
epilog += "\n"
highest_policy = get_policy_name(POLICY_PRIORITY_HIGHEST)
highest_policy = wheel_policy.get_policy_name(wheel_policy.priority_highest)
help = """Vendor in external shared library dependencies of a wheel.
If multiple wheels are specified, an error processing one
wheel will abort processing of subsequent wheels.
Expand Down Expand Up @@ -114,6 +109,8 @@ def execute(args, p):
from .repair import repair_wheel
from .wheel_abi import NonPlatformWheel, analyze_wheel_abi

wheel_policy = WheelPolicies()

for wheel_file in args.WHEEL_FILE:
if not isfile(wheel_file):
p.error("cannot access %s. No such file" % wheel_file)
Expand All @@ -124,23 +121,23 @@ def execute(args, p):
os.makedirs(args.WHEEL_DIR)

try:
wheel_abi = analyze_wheel_abi(wheel_file)
wheel_abi = analyze_wheel_abi(wheel_policy, wheel_file)
except NonPlatformWheel:
logger.info(NonPlatformWheel.LOG_MESSAGE)
return 1

policy = get_policy_by_name(args.PLAT)
policy = wheel_policy.get_policy_by_name(args.PLAT)
reqd_tag = policy["priority"]

if reqd_tag > get_priority_by_name(wheel_abi.sym_tag):
if reqd_tag > wheel_policy.get_priority_by_name(wheel_abi.sym_tag):
msg = (
'cannot repair "%s" to "%s" ABI because of the presence '
"of too-recent versioned symbols. You'll need to compile "
"the wheel on an older toolchain." % (wheel_file, args.PLAT)
)
p.error(msg)

if reqd_tag > get_priority_by_name(wheel_abi.ucs_tag):
if reqd_tag > wheel_policy.get_priority_by_name(wheel_abi.ucs_tag):
msg = (
'cannot repair "%s" to "%s" ABI because it was compiled '
"against a UCS2 build of Python. You'll need to compile "
Expand All @@ -149,7 +146,7 @@ def execute(args, p):
)
p.error(msg)

if reqd_tag > get_priority_by_name(wheel_abi.blacklist_tag):
if reqd_tag > wheel_policy.get_priority_by_name(wheel_abi.blacklist_tag):
msg = (
'cannot repair "%s" to "%s" ABI because it depends on '
"black-listed symbols." % (wheel_file, args.PLAT)
Expand All @@ -158,7 +155,7 @@ def execute(args, p):

abis = [policy["name"]] + policy["aliases"]
if not args.ONLY_PLAT:
if reqd_tag < get_priority_by_name(wheel_abi.overall_tag):
if reqd_tag < wheel_policy.get_priority_by_name(wheel_abi.overall_tag):
logger.info(
(
"Wheel is eligible for a higher priority tag. "
Expand All @@ -168,11 +165,12 @@ def execute(args, p):
args.PLAT,
wheel_abi.overall_tag,
)
higher_policy = get_policy_by_name(wheel_abi.overall_tag)
higher_policy = wheel_policy.get_policy_by_name(wheel_abi.overall_tag)
abis = [higher_policy["name"]] + higher_policy["aliases"] + abis

patcher = Patchelf()
out_wheel = repair_wheel(
wheel_policy,
wheel_file,
abis=abis,
lib_sdir=args.LIB_SDIR,
Expand Down
30 changes: 16 additions & 14 deletions src/auditwheel/main_show.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import logging

from auditwheel.policy import WheelPolicies

logger = logging.getLogger(__name__)


Expand All @@ -23,22 +25,17 @@ def execute(args, p):
import json
from os.path import basename, isfile

from .policy import (
POLICY_PRIORITY_HIGHEST,
POLICY_PRIORITY_LOWEST,
get_policy_name,
get_priority_by_name,
load_policies,
)
from .wheel_abi import NonPlatformWheel, analyze_wheel_abi

wheel_policy = WheelPolicies()

fn = basename(args.WHEEL_FILE)

if not isfile(args.WHEEL_FILE):
p.error("cannot access %s. No such file" % args.WHEEL_FILE)

try:
winfo = analyze_wheel_abi(args.WHEEL_FILE)
winfo = analyze_wheel_abi(wheel_policy, args.WHEEL_FILE)
except NonPlatformWheel:
logger.info(NonPlatformWheel.LOG_MESSAGE)
return 1
Expand All @@ -52,7 +49,10 @@ def execute(args, p):
% (fn, winfo.overall_tag)
)

if get_priority_by_name(winfo.pyfpe_tag) < POLICY_PRIORITY_HIGHEST:
if (
wheel_policy.get_priority_by_name(winfo.pyfpe_tag)
< wheel_policy.priority_highest
):
printp(
"This wheel uses the PyFPE_jbuf function, which is not compatible with the"
" manylinux1 tag. (see https://www.python.org/dev/peps/pep-0513/"
Expand All @@ -61,7 +61,7 @@ def execute(args, p):
if args.verbose < 1:
return

if get_priority_by_name(winfo.ucs_tag) < POLICY_PRIORITY_HIGHEST:
if wheel_policy.get_priority_by_name(winfo.ucs_tag) < wheel_policy.priority_highest:
printp(
"This wheel is compiled against a narrow unicode (UCS2) "
"version of Python, which is not compatible with the "
Expand All @@ -81,7 +81,7 @@ def execute(args, p):
"system-provided shared libraries: %s" % ", ".join(libs_with_versions)
)

if get_priority_by_name(winfo.sym_tag) < POLICY_PRIORITY_HIGHEST:
if wheel_policy.get_priority_by_name(winfo.sym_tag) < wheel_policy.priority_highest:
printp(
(
'This constrains the platform tag to "%s". '
Expand All @@ -95,15 +95,17 @@ def execute(args, p):
if args.verbose < 1:
return

libs = winfo.external_refs[get_policy_name(POLICY_PRIORITY_LOWEST)]["libs"]
libs = winfo.external_refs[
wheel_policy.get_policy_name(wheel_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(dict(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):
for p in sorted(wheel_policy.policies, key=lambda p: p["priority"]):
if p["priority"] > wheel_policy.get_priority_by_name(winfo.overall_tag):
libs = winfo.external_refs[p["name"]]["libs"]
if len(libs):
printp(
Expand Down
Loading