Repository 'tool_factory_2'
hg clone https://toolshed.g2.bx.psu.edu/repos/fubar/tool_factory_2

Changeset 108:e878bfc6b80c (2020-11-29)
Previous changeset 107:18e616939a91 (2020-11-28) Next changeset 109:0116bfe0fa5e (2020-11-29)
Commit message:
Uploaded
modified:
toolfactory/rgToolFactory2.py
toolfactory/rgToolFactory2.xml
b
diff -r 18e616939a91 -r e878bfc6b80c toolfactory/rgToolFactory2.py
--- a/toolfactory/rgToolFactory2.py Sat Nov 28 02:52:24 2020 +0000
+++ b/toolfactory/rgToolFactory2.py Sun Nov 29 04:32:22 2020 +0000
[
@@ -72,7 +72,7 @@
 IHELPOS = 4
 IOCLPOS = 5
 
-# --output_files "$otab.history_name~~~$otab.history_format~~~$otab.CL~~~otab.history_test
+# --output_files "$otab.history_name~~~$otab.history_format~~~$otab.history_CL~~~$otab.history_test"
 ONAMEPOS = 0
 OFMTPOS = 1
 OCLPOS = 2
@@ -115,13 +115,17 @@
         return '"%s"' % s
 
 
-html_escape_table = {"&": "&amp;", ">": "&gt;", "<": "&lt;", "$": r"\$"}
-
+html_escape_table = {"&": "&amp;", ">": "&gt;", "<": "&lt;", "$": r"\$","#":"&#35;", "$":"&#36;"}
+cheetah_escape_table = {"$": "\$","#":"\#"}
 
 def html_escape(text):
     """Produce entities within text."""
     return "".join(html_escape_table.get(c, c) for c in text)
 
+def cheetah_escape(text):
+    """Produce entities within text."""
+    return "".join(cheetah_escape_table.get(c, c) for c in text)
+
 
 def html_unescape(text):
     """Revert entities within text. Multiple character targets so use replace"""
@@ -129,6 +133,8 @@
     t = t.replace("&gt;", ">")
     t = t.replace("&lt;", "<")
     t = t.replace("\\$", "$")
+    t = t.replace("&#36;","$")
+    t = t.replace("&#35;","#")
     return t
 
 
@@ -289,11 +295,11 @@
         tscript = open(self.sfile, "w")
         tscript.write(self.script)
         tscript.close()
-        self.indentedScript = "  %s" % "\n".join([" %s" % html_escape(x) for x in rx])
-        self.escapedScript = "%s" % "\n".join([" %s" % html_escape(x) for x in rx])
+        self.indentedScript = "  %s" % "\n".join([" %s" % cheetah_escape(x) for x in rx])
+        self.escapedScript = "%s" % "\n".join([" %s" % cheetah_escape(x) for x in rx])
         art = "%s.%s" % (self.tool_name, self.executeme)
         artifact = open(art, "wb")
-        artifact.write(bytes(self.script, "utf8"))
+        artifact.write(bytes(self.escapedScript, "utf8"))
         artifact.close()
 
     def cleanuppar(self):
@@ -408,6 +414,7 @@
         """flake8 made me do this..."""
         for p in self.outfiles:
             newname, newfmt, newcl, test, oldcl = p
+            test = test.strip()
             ndash = self.getNdash(newcl)
             aparm = gxtp.OutputData(newcl, format=newfmt, num_dashes=ndash)
             aparm.positional = self.is_positional
@@ -419,24 +426,39 @@
                     aparm.positional = int(oldcl)
                     aparm.command_line_override = "$%s" % newcl
             self.toutputs.append(aparm)
-            usetest = None
             ld = None
-            if test > "":
+            if test.strip() > "":
                 if test.startswith("diff"):
-                    usetest = "diff"
+                    c = "diff"
+                    ld = 0
                     if test.split(":")[1].isdigit:
                         ld = int(test.split(":")[1])
-                else:
-                    usetest = test
-            tp = gxtp.TestOutput(
-                name=newcl,
-                value="%s_sample" % newcl,
-                format=newfmt,
-                compare=usetest,
-                lines_diff=ld,
-                delta=None,
-            )
-            self.testparam.append(tp)
+                    tp = gxtp.TestOutput(
+                                    name=newcl,
+                                    value="%s_sample" % newcl,
+                                    format=newfmt,
+                                    compare= c,
+                                    lines_diff=ld,
+                                )
+                elif test.startswith("sim_size"):
+                    c = "sim_size"
+                    tn = test.split(":")[1].strip()
+                    if tn > '':
+                        if '.' in tn:
+                            delta = None
+                            delta_frac = min(1.0,float(tn))
+                        else:
+                            delta = int(tn)
+                            delta_frac = None
+                    tp = gxtp.TestOutput(
+                                    name=newcl,
+                                    value="%s_sample" % newcl,
+                                    format=newfmt,
+                                    compare= c,
+                                    delta = delta,
+                                    delta_frac = delta_frac
+                                )
+                self.testparam.append(tp)
         for p in self.infiles:
             newname = p[ICLPOS]
             newfmt = p[IFMTPOS]
@@ -550,11 +572,12 @@
             self.newtool.command_override = self.xmlcl
         if self.args.help_text:
             helptext = open(self.args.help_text, "r").readlines()
-            safertext = [html_escape(x) for x in helptext]
-            if False and self.args.script_path:
-                scrp = self.script.split("\n")
-                scrpt = ["   %s" % x for x in scrp]  # try to stop templating
-                scrpt.insert(0, "```\n")
+            safertext = "\n".join([cheetah_escape(x) for x in helptext])
+            if self.args.script_path:
+                scr = self.script.split("\n")
+                scrp = [cheetah_escape(x) for x in scr]
+                scrpt = ['    %s' % x for x in scrpt if x.strip() > ''] # indent
+                scrpt.insert(0,'------\n\nScript::\n')
                 if len(scrpt) > 300:
                     safertext = (
                         safertext
@@ -563,9 +586,8 @@
                         + scrpt[-100:]
                     )
                 else:
-                    safertext = safertext + scrpt
-                safertext.append("\n```")
-            self.newtool.help = "\n".join([x for x in safertext])
+                    safertext = safertext + "\n".join(scrpt)
+            self.newtool.help = safertext
         else:
             self.newtool.help = (
                 "Please ask the tool author (%s) for help \
@@ -593,7 +615,7 @@
         self.newtool.inputs = self.tinputs
         if self.args.script_path:
             configfiles = gxtp.Configfiles()
-            configfiles.append(gxtp.Configfile(name="runme", text=self.script))
+            configfiles.append(gxtp.Configfile(name="runme", text=self.escapedScript))
             self.newtool.configfiles = configfiles
         tests = gxtp.Tests()
         test_a = gxtp.Test()
@@ -607,8 +629,7 @@
         )
         self.newtool.add_comment("Source in git at: %s" % (toolFactoryURL))
         self.newtool.add_comment(
-            "Cite: Creating re-usable tools from scripts doi: \
-            10.1093/bioinformatics/bts573"
+            "Cite: Creating re-usable tools from scripts doi:10.1093/bioinformatics/bts573"
         )
         exml0 = self.newtool.export()
         exml = exml0.replace(FAKEEXE, "")  # temporary work around until PR accepted
@@ -806,8 +827,6 @@
         repos = ts.repositories.get_repositories()
         rnames = [x.get("name", "?") for x in repos]
         rids = [x.get("id", "?") for x in repos]
-        sto.write(f"############names={rnames} rids={rids}\n")
-        sto.write(f"############names={repos}\n")
         tfcat = "ToolFactory generated tools"
         if self.tool_name not in rnames:
             tscat = ts.categories.get_categories()
@@ -827,7 +846,6 @@
                 category_ids=catID,
             )
             tid = res.get("id", None)
-            sto.write(f"##########create res={res}\n")
         else:
             i = rnames.index(self.tool_name)
             tid = rids[i]
b
diff -r 18e616939a91 -r e878bfc6b80c toolfactory/rgToolFactory2.xml
--- a/toolfactory/rgToolFactory2.xml Sat Nov 28 02:52:24 2020 +0000
+++ b/toolfactory/rgToolFactory2.xml Sun Nov 29 04:32:22 2020 +0000
[
@@ -79,7 +79,7 @@
             <param name="history_CL" type="text"  label="Positional: ordinal integer. Argparse: argument name expected for this output parameter. Use STDOUT if '>' required."
               help="If positional parameters, enter the integer ordinal expected for this parameter. If Argparse style, '--' will be prepended or '-' if single character" value=""/>
             <param name="history_test" type="text"  label="Test pass decision criterion for this output compared to test generation"
-              help="Available options are diff:lines, sim_size" value="diff:2"/>
+              help="Available options are diff:[lines], sim_size:[delta (integer) or delta_frac (float)" value="sim_size:0.01"/>
         </repeat>
      </xml>
      <xml name="additparam">
@@ -232,7 +232,7 @@
    <param name="tool_name" type="text" value="tool1"   label="New tool ID and title for outputs"
          help="Toolshed repository name. Choose thoughtfully to avoid namespace clashes with other tool writers. Lower case, digits and underscores only">
         <sanitizer invalid_char="">
-            <valid initial="string.letters,string.digits">
+            <valid initial="string.ascii_lowercase,string.digits">
                 <add value="_"/>
             </valid>
         </sanitizer>
@@ -243,8 +243,8 @@
     <conditional name="usescript">
         <param name="choosescript" type="select" display="radio" label="Supply a script to either a dependency (e.g. python/R/bash) or a system executable such as Bash"
         help = "For script interpreters like Python or bash. Parameters and i/o specified below must match script's expectations - if you pass parameters, the script must deal with them">
-            <option value="no" selected="true">No script required for this tool - just pass parameters on the command line to the first dependency listed above</option>
-            <option value="yes">Yes, a script is ready to be pasted below</option>
+            <option value="no">No script required for this tool - just pass parameters on the command line to the first dependency listed above</option>
+            <option value="yes" selected="true">Yes, a script is ready to be pasted below</option>
         </param>
         <when value="no">
             <param name="dynScript" type="hidden"  value="" />
@@ -324,8 +324,8 @@
         <param name="make_Tool" type="select" display="radio" label="Choose the steps you want to run. The TF Docker container is recommended for local installation"
           help="Installation in this Galaxy is optional" >
         <option value="generate" >Run to generate tests only. Should fail if dependencies needed.</option>
-        <option value="gentest" selected="true">Test with planemo after generating.</option>
-        <option value="gentestinstall">Install in this Galaxy after generation and testing. Must have local ToolShed as in the TF Docker container</option>
+        <option value="gentest">Test with planemo after generating.</option>
+        <option value="gentestinstall" selected="true">Install in this Galaxy after generation and testing. Must have local ToolShed as in the TF Docker container</option>
         </param>
        <when value="generate">
            <param name="galaxy_apikey" value="" type="hidden"  ></param>