Skip to content

Commit b5f395d

Browse files
authored
Merge pull request #42 from aCLImatise/avoid-repeats
Avoid repeats
2 parents 017bfe0 + c6da951 commit b5f395d

File tree

11 files changed

+73
-20
lines changed

11 files changed

+73
-20
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ repos:
1414
- "dataclasses"
1515

1616
- repo: https://github.com/psf/black
17-
rev: stable
17+
rev: 20.8b1
1818
hooks:
1919
- id: black
2020

acclimatise/__init__.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,11 @@ def explore_command(
196196
if command.depth < max_depth:
197197
# By default we use the best parent help-flag
198198
child_flags = flags if try_subcommand_flags else [command.generated_using]
199-
for positional in command.positional:
199+
200+
# Try each *unique* positional
201+
for positional in {positional.name for positional in command.positional}:
200202
subcommand = explore_command(
201-
cmd=cmd + [positional.name],
203+
cmd=cmd + [positional],
202204
flags=child_flags,
203205
parent=command,
204206
max_depth=max_depth,
@@ -207,7 +209,6 @@ def explore_command(
207209
)
208210
if subcommand is not None:
209211
command.subcommands.append(subcommand)
210-
211212
# If we had any subcommands then we probably don't have any positionals, or at least don't care about them
212213
command.positional = []
213214

acclimatise/cli.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,9 @@ def explore(
108108
for format in formats:
109109
converter_cls = WrapperGenerator.choose_converter(format)
110110
converter = converter_cls(
111-
generate_names=generate_names, ignore_positionals=not pos, case=case,
111+
generate_names=generate_names,
112+
ignore_positionals=not pos,
113+
case=case,
112114
)
113115
list(converter.generate_tree(command, out_dir))
114116

@@ -133,7 +135,9 @@ def pipe(cmd, pos, generate_names, case, format):
133135

134136
converter_cls = WrapperGenerator.choose_converter(format)
135137
converter = converter_cls(
136-
generate_names=generate_names, ignore_positionals=not pos, case=case,
138+
generate_names=generate_names,
139+
ignore_positionals=not pos,
140+
case=case,
137141
)
138142
output = converter.save_to_string(command)
139143
print(output)

acclimatise/converter/wdl.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ def flag_to_command_input(
3838
if isinstance(named_flag.arg.args, model.EmptyFlagArg):
3939
args.update(dict(true=named_flag.arg.longest_synonym, false=""))
4040
else:
41-
args.update(dict(prefix=named_flag.arg.longest_synonym,))
41+
args.update(
42+
dict(
43+
prefix=named_flag.arg.longest_synonym,
44+
)
45+
)
4246
elif isinstance(named_flag, model.Positional):
4347
args.update(dict(optional=False, position=named_flag.position))
4448

acclimatise/model.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,19 +108,19 @@ def command_tree(self) -> typing.Generator["Command", None, None]:
108108
for command in self.subcommands:
109109
yield from command.command_tree()
110110

111-
positional: typing.List["Positional"]
111+
command: typing.List[str]
112112
"""
113-
All positional arguments supported by this command
113+
The command line used to invoke this command, e.g. ["bwa", "mem"]
114114
"""
115115

116-
named: typing.List["Flag"]
116+
positional: typing.List["Positional"] = field(default_factory=list)
117117
"""
118-
All named arguments (flags) supported by this command
118+
All positional arguments supported by this command
119119
"""
120120

121-
command: typing.List[str]
121+
named: typing.List["Flag"] = field(default_factory=list)
122122
"""
123-
The command line used to invoke this command, e.g. ["bwa", "mem"]
123+
All named arguments (flags) supported by this command
124124
"""
125125

126126
parent: typing.Optional["Command"] = None

acclimatise/usage_parser/elements.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ def action(s, loc, toks):
3636

3737
mandatory_element = (
3838
element_char.copy()
39-
.setParseAction(lambda s, loc, toks: UsageElement(text=toks[0],))
39+
.setParseAction(
40+
lambda s, loc, toks: UsageElement(
41+
text=toks[0],
42+
)
43+
)
4044
.setName("MandatoryElement")
4145
)
4246
"""

docs/changes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Changelog
77
1.0.2 (2020-08-25)
88
------------------
99
* Ensure we never return ``None`` from the ``DockerExecutor``
10+
* Add initial parsing of "output inputs". Thanks to `@bernt-matthias <https://github.com/bernt-matthias>`_ (`#15 <https://github.com/aCLImatise/CliHelpParser/pull/15>`_). However this information is not yet used in the converters.
1011

1112
1.0.1 (2020-08-22)
1213
------------------

test/executors/test_docker.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
def test_docker(bwamem_help):
88
client = docker.from_env()
99
container = client.containers.run(
10-
"biocontainers/bwa:v0.7.17_cv1", entrypoint=["sleep", "999999999"], detach=True,
10+
"biocontainers/bwa:v0.7.17_cv1",
11+
entrypoint=["sleep", "999999999"],
12+
detach=True,
1113
)
1214

1315
exec = DockerExecutor(container)
@@ -23,7 +25,9 @@ def test_docker_kill():
2325
"""
2426
client = docker.from_env(timeout=99999)
2527
container = client.containers.run(
26-
"ubuntu:latest", entrypoint=["sleep", "999999999"], detach=True,
28+
"ubuntu:latest",
29+
entrypoint=["sleep", "999999999"],
30+
detach=True,
2731
)
2832

2933
exec = DockerExecutor(container)
@@ -54,7 +58,9 @@ def test_infinite_output():
5458
"""
5559
client = docker.from_env(timeout=99999)
5660
container = client.containers.run(
57-
"ubuntu:latest", entrypoint=["sleep", "999999999"], detach=True,
61+
"ubuntu:latest",
62+
entrypoint=["sleep", "999999999"],
63+
detach=True,
5864
)
5965

6066
exec = DockerExecutor(container)

test/name_generation/test_single_flag.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,11 @@ def test_name_to_words(gen):
5454
"""
5555
Check that we can get an argument name even if the argument's flag is a symbol
5656
"""
57-
arg = Flag(synonyms=["--genomepaths"], description="", args=EmptyFlagArg(),)
57+
arg = Flag(
58+
synonyms=["--genomepaths"],
59+
description="",
60+
args=EmptyFlagArg(),
61+
)
5862

5963
name = gen.choose_variable_names([arg])[0].name
6064
assert "genome" in name

test/test_cli.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,14 @@ def test_explore_samtools_no_subcommands(runner, caplog):
6969
caplog.set_level(100000)
7070
with tempfile.TemporaryDirectory() as tempdir:
7171
result = runner.invoke(
72-
main, ["explore", "samtools", "--no-subcommands", "--out-dir", tempdir,],
72+
main,
73+
[
74+
"explore",
75+
"samtools",
76+
"--no-subcommands",
77+
"--out-dir",
78+
tempdir,
79+
],
7380
)
7481
cli_worked(result)
7582
# Since we aren't looking at subcommands, there should be one file for each format

0 commit comments

Comments
 (0)