Skip to content

Commit 3c0a415

Browse files
authored
Merge pull request #466 from lkollar/policy-refactor
Remove globals in policy module
2 parents 522e590 + 8c18c7c commit 3c0a415

12 files changed

+319
-317
lines changed

Diff for: src/auditwheel/main_repair.py

+14-16
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,15 @@
66

77
from auditwheel.patcher import Patchelf
88

9-
from .policy import (
10-
POLICY_PRIORITY_HIGHEST,
11-
get_policy_by_name,
12-
get_policy_name,
13-
get_priority_by_name,
14-
load_policies,
15-
)
9+
from .policy import WheelPolicies
1610
from .tools import EnvironmentDefault
1711

1812
logger = logging.getLogger(__name__)
1913

2014

2115
def configure_parser(sub_parsers):
22-
policies = load_policies()
16+
wheel_policy = WheelPolicies()
17+
policies = wheel_policy.policies
2318
policy_names = [p["name"] for p in policies]
2419
policy_names += [alias for p in policies for alias in p["aliases"]]
2520
epilog = """PLATFORMS:
@@ -32,7 +27,7 @@ def configure_parser(sub_parsers):
3227
if len(p["aliases"]) > 0:
3328
epilog += f" (aliased by {', '.join(p['aliases'])})"
3429
epilog += "\n"
35-
highest_policy = get_policy_name(POLICY_PRIORITY_HIGHEST)
30+
highest_policy = wheel_policy.get_policy_name(wheel_policy.priority_highest)
3631
help = """Vendor in external shared library dependencies of a wheel.
3732
If multiple wheels are specified, an error processing one
3833
wheel will abort processing of subsequent wheels.
@@ -114,6 +109,8 @@ def execute(args, p):
114109
from .repair import repair_wheel
115110
from .wheel_abi import NonPlatformWheel, analyze_wheel_abi
116111

112+
wheel_policy = WheelPolicies()
113+
117114
for wheel_file in args.WHEEL_FILE:
118115
if not isfile(wheel_file):
119116
p.error("cannot access %s. No such file" % wheel_file)
@@ -124,23 +121,23 @@ def execute(args, p):
124121
os.makedirs(args.WHEEL_DIR)
125122

126123
try:
127-
wheel_abi = analyze_wheel_abi(wheel_file)
124+
wheel_abi = analyze_wheel_abi(wheel_policy, wheel_file)
128125
except NonPlatformWheel:
129126
logger.info(NonPlatformWheel.LOG_MESSAGE)
130127
return 1
131128

132-
policy = get_policy_by_name(args.PLAT)
129+
policy = wheel_policy.get_policy_by_name(args.PLAT)
133130
reqd_tag = policy["priority"]
134131

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

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

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

159156
abis = [policy["name"]] + policy["aliases"]
160157
if not args.ONLY_PLAT:
161-
if reqd_tag < get_priority_by_name(wheel_abi.overall_tag):
158+
if reqd_tag < wheel_policy.get_priority_by_name(wheel_abi.overall_tag):
162159
logger.info(
163160
(
164161
"Wheel is eligible for a higher priority tag. "
@@ -168,11 +165,12 @@ def execute(args, p):
168165
args.PLAT,
169166
wheel_abi.overall_tag,
170167
)
171-
higher_policy = get_policy_by_name(wheel_abi.overall_tag)
168+
higher_policy = wheel_policy.get_policy_by_name(wheel_abi.overall_tag)
172169
abis = [higher_policy["name"]] + higher_policy["aliases"] + abis
173170

174171
patcher = Patchelf()
175172
out_wheel = repair_wheel(
173+
wheel_policy,
176174
wheel_file,
177175
abis=abis,
178176
lib_sdir=args.LIB_SDIR,

Diff for: src/auditwheel/main_show.py

+16-14
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import logging
44

5+
from auditwheel.policy import WheelPolicies
6+
57
logger = logging.getLogger(__name__)
68

79

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

26-
from .policy import (
27-
POLICY_PRIORITY_HIGHEST,
28-
POLICY_PRIORITY_LOWEST,
29-
get_policy_name,
30-
get_priority_by_name,
31-
load_policies,
32-
)
3328
from .wheel_abi import NonPlatformWheel, analyze_wheel_abi
3429

30+
wheel_policy = WheelPolicies()
31+
3532
fn = basename(args.WHEEL_FILE)
3633

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

4037
try:
41-
winfo = analyze_wheel_abi(args.WHEEL_FILE)
38+
winfo = analyze_wheel_abi(wheel_policy, args.WHEEL_FILE)
4239
except NonPlatformWheel:
4340
logger.info(NonPlatformWheel.LOG_MESSAGE)
4441
return 1
@@ -52,7 +49,10 @@ def execute(args, p):
5249
% (fn, winfo.overall_tag)
5350
)
5451

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

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

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

98-
libs = winfo.external_refs[get_policy_name(POLICY_PRIORITY_LOWEST)]["libs"]
98+
libs = winfo.external_refs[
99+
wheel_policy.get_policy_name(wheel_policy.priority_lowest)
100+
]["libs"]
99101
if len(libs) == 0:
100102
printp("The wheel requires no external shared libraries! :)")
101103
else:
102104
printp("The following external shared libraries are required " "by the wheel:")
103105
print(json.dumps(dict(sorted(libs.items())), indent=4))
104106

105-
for p in sorted(load_policies(), key=lambda p: p["priority"]):
106-
if p["priority"] > get_priority_by_name(winfo.overall_tag):
107+
for p in sorted(wheel_policy.policies, key=lambda p: p["priority"]):
108+
if p["priority"] > wheel_policy.get_priority_by_name(winfo.overall_tag):
107109
libs = winfo.external_refs[p["name"]]["libs"]
108110
if len(libs):
109111
printp(

0 commit comments

Comments
 (0)