Skip to content

Commit 52dae56

Browse files
authored
Merge pull request #493 from dpinol/dp/fix-args
support for "threads" and "min-optlevel" julia options
2 parents e5b06f1 + 45d1ec3 commit 52dae56

File tree

3 files changed

+55
-9
lines changed

3 files changed

+55
-9
lines changed

src/julia/options.py

+43-2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,35 @@ def _domain(self): # used in test
4141
return str
4242

4343

44+
class IntEtc(OptionDescriptor):
45+
def __init__(self, name, *, etc={}):
46+
self.name = name
47+
self.default = etc
48+
49+
def __set__(self, instance, value):
50+
if instance is None:
51+
raise AttributeError(self.name)
52+
elif value in {None, *self.default} or isinstance(value, int):
53+
setattr(instance, self.dataname, value)
54+
else:
55+
if self.default:
56+
part = " or " + " ".join(map(str, self.default))
57+
else:
58+
part = ""
59+
raise ValueError(
60+
f"Option {self.name} only accepts integers{part}. Got: {value}"
61+
)
62+
63+
def _domain(self):
64+
return {int, *self.default}
65+
66+
def cli_argument_spec(self):
67+
return dict(
68+
super(IntEtc, self).cli_argument_spec(),
69+
choices=list(self.default) + ["1", "2", "3", "..."],
70+
)
71+
72+
4473
class Choices(OptionDescriptor):
4574
def __init__(self, name, choicemap, default=None):
4675
self.name = name
@@ -110,6 +139,12 @@ def yes_no_etc(*etc):
110139
111140
warn_overwrite: {True, False, 'yes', 'no'}
112141
Enable or disable method overwrite warnings.
142+
143+
min_optlevel: {0, 1, 2, 3}
144+
Lower bound on the optimization level.
145+
146+
threads: {int, 'auto'}
147+
How many threads to use.
113148
"""
114149

115150

@@ -134,9 +169,11 @@ class JuliaOptions(object):
134169
compile = Choices("compile", yes_no_etc("all", "min"))
135170
depwarn = Choices("depwarn", yes_no_etc("error"))
136171
warn_overwrite = Choices("warn_overwrite", yes_no_etc())
172+
min_optlevel = Choices("min_optlevel", dict(zip(range(4), map(str, range(4)))))
137173
optimize = Choices("optimize", dict(zip(range(4), map(str, range(4)))))
138174
inline = Choices("inline", yes_no_etc())
139175
check_bounds = Choices("check_bounds", yes_no_etc())
176+
threads = IntEtc("threads", etc={"auto"})
140177

141178
def __init__(self, **kwargs):
142179
unsupported = []
@@ -168,8 +205,12 @@ def specified(self):
168205
def as_args(self):
169206
args = []
170207
for (desc, value) in self.specified():
171-
args.append(desc.cli_argument_name())
172-
args.append(value)
208+
if value is None:
209+
...
210+
elif len(desc.cli_argument_name()) == 1:
211+
args.append(desc.cli_argument_name() + str(value))
212+
else:
213+
args.append(desc.cli_argument_name() + "=" + str(value))
173214
return args
174215

175216
@classmethod

src/julia/tests/test_compatible_exe.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def discover_other_pythons():
2323
[sys.executable, "--version"], universal_newlines=True, stderr=subprocess.STDOUT
2424
)
2525

26-
candidate_names = ["python", "python2", "python2.7", "python3"] + [
26+
candidate_names = ["python", "python3"] + [
2727
"python3.{}".format(i) for i in range(20)
2828
]
2929
found = {}

src/julia/tests/test_juliaoptions.py

+11-6
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,17 @@
77
@pytest.mark.parametrize("kwargs, args", [
88
({}, []),
99
(dict(compiled_modules=None), []),
10-
(dict(compiled_modules=False), ["--compiled-modules", "no"]),
11-
(dict(compiled_modules="no"), ["--compiled-modules", "no"]),
12-
(dict(depwarn="error"), ["--depwarn", "error"]),
13-
(dict(sysimage="PATH"), ["--sysimage", "PATH"]),
14-
(dict(bindir="PATH"), ["--home", "PATH"]),
15-
(dict(optimize=3), ["--optimize", "3"]),
10+
(dict(compiled_modules=False), ["--compiled-modules=no"]),
11+
(dict(compiled_modules="no"), ["--compiled-modules=no"]),
12+
(dict(depwarn="error"), ["--depwarn=error"]),
13+
(dict(sysimage="PATH"), ["--sysimage=PATH"]),
14+
(dict(bindir="PATH"), ["--home=PATH"]),
15+
(dict(optimize=3), ["--optimize=3"]),
16+
(dict(threads=4), ["--threads=4"]),
17+
(dict(min_optlevel=2), ["--min-optlevel=2"]),
18+
(dict(threads="auto", optimize=3), ["--optimize=3", '--threads=auto']),
19+
(dict(optimize=3, threads="auto"), ["--optimize=3", '--threads=auto']), # passed order doesn't matter
20+
(dict(compiled_modules=None, depwarn="yes"), ["--depwarn=yes"]),
1621
])
1722
# fmt: on
1823
def test_as_args(kwargs, args):

0 commit comments

Comments
 (0)