Skip to content

Commit ef579ac

Browse files
Do not duplicate configure args.
1 parent fab3dad commit ef579ac

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

Tools/freeze/test/freeze.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,26 @@ def find_opt(args, name):
4747
return -1
4848

4949

50+
def ensure_opt(args, name, value):
51+
opt = f'--{name}'
52+
pos = find_opt(args, name)
53+
if value is None:
54+
if pos < 0:
55+
args.append(opt)
56+
else:
57+
args[pos] = opt
58+
elif pos < 0:
59+
args.extend([opt, value])
60+
else:
61+
arg = args[pos]
62+
if arg == opt:
63+
if pos == len(args) - 1:
64+
raise NotImplementedError((args, opt))
65+
args[pos + 1] = value
66+
else:
67+
args[pos] = f'{opt}={value}'
68+
69+
5070
def git_copy_repo(newroot, remote=None, *, verbose=True):
5171
if not GIT:
5272
raise UnsupportedError('git')
@@ -156,17 +176,17 @@ def configure_python(builddir=None, prefix=None, cachefile=None, args=None, *,
156176

157177
cmd = [configure]
158178
if inherit:
159-
oldargs = get_configure_args(builddir)
179+
oldargs = get_configure_args(builddir, fail=False)
160180
if oldargs:
161181
cmd.extend(oldargs)
162182
if cachefile:
163183
if args and find_opt(args, 'cache-file') >= 0:
164184
raise ValueError('unexpected --cache-file')
165-
cmd.extend(['--cache-file', os.path.abspath(cachefile)])
185+
ensure_opt(cmd, 'cache-file', os.path.abspath(cachefile))
166186
if prefix:
167187
if args and find_opt(args, 'prefix') >= 0:
168188
raise ValueError('unexpected --prefix')
169-
cmd.extend(['--prefix', os.path.abspath(prefix)])
189+
ensure_opt(cmd, 'prefix', os.path.abspath(prefix))
170190
if args:
171191
cmd.extend(args)
172192

0 commit comments

Comments
 (0)