Skip to content

Commit ccdd2d5

Browse files
committed
Pull in upstream changes to existing files from bioc work.
These new abstractions allow the downstream work to get away with a lot less duplication relative to master. So this improves this code and should really simplify the diff when a new PR for the bioconductor stuff is opened.
1 parent 024c291 commit ccdd2d5

File tree

3 files changed

+308
-211
lines changed

3 files changed

+308
-211
lines changed

planemo/commands/cmd_tool_init.py

Lines changed: 24 additions & 210 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
"""Module describing the planemo ``tool_init`` command."""
2-
import os
32

43
import click
54

@@ -8,226 +7,41 @@
87
from planemo import tool_builder
98
from planemo.cli import command_function
109

11-
REUSING_MACROS_MESSAGE = ("Macros file macros.xml already exists, assuming "
12-
" it has relevant planemo-generated definitions.")
1310

14-
15-
# --input_format
16-
# --output_format
17-
# --advanced_options
1811
@click.command("tool_init")
19-
@click.option(
20-
"-i",
21-
"--id",
22-
type=click.STRING,
23-
prompt=True,
24-
help="Short identifier for new tool (no whitespace)",
25-
)
12+
@options.tool_init_id_option()
2613
@options.force_option(what="tool")
27-
@click.option(
28-
"-t",
29-
"--tool",
30-
default=None,
31-
type=click.Path(exists=False,
32-
file_okay=True,
33-
dir_okay=False,
34-
writable=True,
35-
resolve_path=True),
36-
help="Output path for new tool (default is <id>.xml)",
37-
)
38-
@click.option(
39-
"-n",
40-
"--name",
41-
type=click.STRING,
42-
prompt=True,
43-
help="Name for new tool (user facing)",
44-
)
45-
@click.option(
46-
"--version",
47-
default="0.1.0",
48-
type=click.STRING,
49-
help="Tool XML version.",
50-
)
51-
@click.option(
52-
"-d",
53-
"--description",
54-
type=click.STRING,
55-
default=None,
56-
prompt=False,
57-
help="Short description for new tool (user facing)",
58-
)
59-
@click.option(
60-
"-c",
61-
"--command",
62-
type=click.STRING,
63-
default=None,
64-
prompt=False,
65-
help=("Command potentially including cheetah variables ()"
66-
"(e.g. 'seqtk seq -a $input > $output')"),
67-
)
68-
@click.option(
69-
"--example_command",
70-
type=click.STRING,
71-
default=None,
72-
prompt=False,
73-
help=("Example to command with paths to build Cheetah template from "
74-
"(e.g. 'seqtk seq -a 2.fastq > 2.fasta'). Option cannot be used "
75-
"with --command, should be used --example_input and "
76-
"--example_output."),
77-
)
78-
@click.option(
79-
"--example_input",
80-
type=click.STRING,
81-
default=None,
82-
prompt=False,
83-
multiple=True,
84-
help=("For use with --example_command, replace input file (e.g. 2.fastq "
85-
"with a data input parameter)."),
86-
)
87-
@click.option(
88-
"--example_output",
89-
type=click.STRING,
90-
default=None,
91-
prompt=False,
92-
multiple=True,
93-
help=("For use with --example_command, replace input file (e.g. 2.fastq "
94-
"with a tool output)."),
95-
)
96-
@click.option(
97-
"--version_command",
98-
type=click.STRING,
99-
default=None,
100-
prompt=False,
101-
help="Command to print version (e.g. 'seqtk --version')",
102-
)
103-
@click.option(
104-
"--input",
105-
type=click.STRING,
106-
default=None,
107-
prompt=False,
108-
multiple=True,
109-
help="An input description (e.g. input.fasta)",
110-
)
111-
@click.option(
112-
"--output",
113-
type=click.STRING,
114-
multiple=True,
115-
default=None,
116-
prompt=False,
117-
help=("An output location (e.g. output.bam), the Galaxy datatype is "
118-
"inferred from the extension."),
119-
)
120-
@click.option(
121-
"--named_output",
122-
type=click.STRING,
123-
multiple=True,
124-
default=None,
125-
prompt=False,
126-
help=("Create a named output for use with command block for example "
127-
"specify --named_output=output1.bam and then use '-o $output1' "
128-
"in your command block."),
129-
)
130-
@click.option(
131-
"--help_text",
132-
type=click.STRING,
133-
default=None,
134-
prompt=False,
135-
help="Help text (reStructuredText)",
136-
)
137-
@click.option(
138-
"--help_from_command",
139-
type=click.STRING,
140-
default=None,
141-
prompt=False,
142-
help="Auto populate help from supplied command.",
143-
)
144-
@click.option(
145-
"--requirement",
146-
type=click.STRING,
147-
default=None,
148-
multiple=True,
149-
prompt=False,
150-
help="Add a tool requirement package (e.g. 'seqtk' or 'seqtk@1.68')."
151-
)
152-
@click.option(
153-
"--container",
154-
type=click.STRING,
155-
default=None,
156-
multiple=True,
157-
prompt=False,
158-
help="Add a Docker image identifier for this tool."
159-
)
160-
@click.option(
161-
"--doi",
162-
type=click.STRING,
163-
default=None,
164-
multiple=True,
165-
prompt=False,
166-
help=("Supply a DOI (http://www.doi.org/) easing citation of the tool "
167-
"for Galaxy users (e.g. 10.1101/014043).")
168-
)
169-
@click.option(
170-
"--cite_url",
171-
type=click.STRING,
172-
default=None,
173-
multiple=True,
174-
prompt=False,
175-
help=("Supply a URL for citation.")
176-
)
177-
@click.option(
178-
"--test_case",
179-
is_flag=True,
180-
default=None,
181-
prompt=False,
182-
help=("For use with --example_commmand, generate a tool test case from "
183-
"the supplied example."),
184-
)
185-
@click.option(
186-
"--macros",
187-
is_flag=True,
188-
default=None,
189-
prompt=False,
190-
help="Generate a macros.xml for reuse across many tools.",
191-
)
14+
@options.tool_init_tool_option()
15+
@options.tool_init_name_option()
16+
@options.tool_init_version_option()
17+
@options.tool_init_description_option()
18+
@options.tool_init_command_option()
19+
@options.tool_init_example_command_option()
20+
@options.tool_init_example_input_option()
21+
@options.tool_init_example_output_option()
22+
@options.tool_init_named_output_option()
23+
@options.tool_init_input_option()
24+
@options.tool_init_output_option()
25+
@options.tool_init_help_text_option()
26+
@options.tool_init_help_from_command_option()
27+
@options.tool_init_doi_option()
28+
@options.tool_init_cite_url_option()
29+
@options.tool_init_test_case_option()
30+
@options.tool_init_macros_option()
31+
@options.tool_init_version_command_option()
32+
@options.tool_init_requirement_option()
33+
@options.tool_init_container_option()
19234
@options.build_cwl_option()
19335
@command_function
19436
def cli(ctx, **kwds):
19537
"""Generate tool outline from given arguments."""
19638
invalid = _validate_kwds(kwds)
197-
tool_id = kwds.get("id")
19839
if invalid:
19940
ctx.exit(invalid)
200-
output = kwds.get("tool")
201-
if not output:
202-
extension = "cwl" if kwds.get("cwl") else "xml"
203-
output = "%s.%s" % (tool_id, extension)
204-
if not io.can_write_to_path(output, **kwds):
205-
ctx.exit(1)
20641
tool_description = tool_builder.build(**kwds)
207-
io.write_file(output, tool_description.contents)
208-
io.info("Tool written to %s" % output)
209-
test_contents = tool_description.test_contents
210-
if test_contents:
211-
sep = "-" if "-" in tool_id else "_"
212-
tests_path = "%s%stests.yml" % (kwds.get("id"), sep)
213-
if not io.can_write_to_path(tests_path, **kwds):
214-
ctx.exit(1)
215-
io.write_file(tests_path, test_contents)
216-
io.info("Tool tests written to %s" % tests_path)
217-
218-
macros = kwds["macros"]
219-
macros_file = "macros.xml"
220-
if macros and not os.path.exists(macros_file):
221-
io.write_file(macros_file, tool_description.macro_contents)
222-
elif macros:
223-
io.info(REUSING_MACROS_MESSAGE)
224-
if tool_description.test_files:
225-
if not os.path.exists("test-data"):
226-
io.info("No test-data directory, creating one.")
227-
io.shell("mkdir -p 'test-data'")
228-
for test_file in tool_description.test_files:
229-
io.info("Copying test-file %s" % test_file)
230-
io.shell("cp '%s' 'test-data'" % test_file)
42+
tool_builder.write_tool_description(
43+
ctx, tool_description, **kwds
44+
)
23145

23246

23347
def _validate_kwds(kwds):

0 commit comments

Comments
 (0)