diff toolfactory/rgToolFactory2.py @ 1:48458b0369aa draft

Uploaded
author fubar
date Sat, 17 Apr 2021 22:50:25 +0000
parents fc50a3f507ab
children
line wrap: on
line diff
--- a/toolfactory/rgToolFactory2.py	Sat Apr 10 02:16:35 2021 +0000
+++ b/toolfactory/rgToolFactory2.py	Sat Apr 17 22:50:25 2021 +0000
@@ -28,12 +28,15 @@
 import tempfile
 import time
 
+from bioblend import ConnectionError
+from bioblend import toolshed
+
 import galaxyxml.tool as gxt
 import galaxyxml.tool.parameters as gxtp
+
 import lxml
+
 import yaml
-from bioblend import ConnectionError
-from bioblend import toolshed
 
 myversion = "V2.2 February 2021"
 verbose = True
@@ -76,7 +79,7 @@
 
     """
 
-    def __init__(self, args=None):
+    def __init__(self, args=None):  # noqa
         """
         prepare command line cl for running the tool here
         and prepare elements needed for galaxyxml tool generation
@@ -229,20 +232,25 @@
         clsuffix = []
         xclsuffix = []
         for i, p in enumerate(self.infiles):
+            nam = p["infilename"]
             if p["origCL"].strip().upper() == "STDIN":
                 appendme = [
-                    p["infilename"],
-                    p["infilename"],
-                    "< %s" % p["infilename"],
+                    nam,
+                    nam,
+                    "< %s" % nam,
                 ]
                 xappendme = [
-                    p["infilename"],
-                    p["infilename"],
-                    "< $%s" % p["infilename"],
+                    nam,
+                    nam,
+                    "< $%s" % nam,
                 ]
             else:
+                rep = p["repeat"] == "1"
+                over = ""
+                if rep:
+                    over = f'#for $rep in $R_{nam}:\n--{nam} "$rep.{nam}"\n#end for'
                 appendme = [p["CL"], p["CL"], ""]
-                xappendme = [p["CL"], "$%s" % p["CL"], ""]
+                xappendme = [p["CL"], "$%s" % p["CL"], over]
             clsuffix.append(appendme)
             xclsuffix.append(xappendme)
         for i, p in enumerate(self.outfiles):
@@ -256,7 +264,7 @@
             nam = p["name"]
             rep = p["repeat"] == "1"
             if rep:
-                over = f" #for $rep in $R_{nam}:\n--{nam} $rep.{nam}\n#end for"
+                over = f'#for $rep in $R_{nam}:\n--{nam} "$rep.{nam}"\n#end for'
             else:
                 over = p["override"]
             clsuffix.append([p["CL"], nam, over])
@@ -423,7 +431,7 @@
         return ndash
 
     def doXMLparam(self):
-        """flake8 made me do this..."""
+        """Add all needed elements to tool"""  # noqa
         for p in self.outfiles:
             newname = p["name"]
             newfmt = p["format"]
@@ -486,7 +494,7 @@
             newname = p["infilename"]
             newfmt = p["format"]
             ndash = self.getNdash(newname)
-            reps = p.get("repeat", 0) == 1
+            reps = p.get("repeat", "0") == "1"
             if not len(p["label"]) > 0:
                 alab = p["CL"]
             else:
@@ -674,7 +682,7 @@
             tp = gxtp.TestOutput(name=newname, value="%s_sample" % newname)
             self.testparam.append(tp)
 
-    def makeXML(self):
+    def makeXML(self):  # noqa
         """
         Create a Galaxy xml tool wrapper for the new script
         Uses galaxyhtml
@@ -712,6 +720,10 @@
             safertext = safertext + "\n".join(scr)
         self.newtool.help = safertext
         self.newtool.version_command = f'echo "{self.args.tool_version}"'
+        std = gxtp.Stdios()
+        std1 = gxtp.Stdio()
+        std.append(std1)
+        self.newtool.stdios = std
         requirements = gxtp.Requirements()
         if self.args.packages:
             for d in self.args.packages.split(","):
@@ -725,7 +737,7 @@
                 requirements.append(
                     gxtp.Requirement("package", packg.strip(), ver.strip())
                 )
-            self.newtool.requirements = requirements
+        self.newtool.requirements = requirements
         if self.args.parampass == "0":
             self.doNoXMLparam()
         else:
@@ -1042,6 +1054,8 @@
         cll = [
             "planemo",
             "test",
+            "--galaxy_python_version",
+            self.args.python_version,
             "--conda_auto_init",
             "--test_data",
             os.path.abspath(self.testdir),
@@ -1062,6 +1076,36 @@
         tout.close()
         return p.returncode
 
+    def set_planemo_galaxy_root(self, galaxyroot='/galaxy-central', config_path=".planemo.yml"):
+        # bug in planemo - bogus '--dev-wheels' passed to run_tests.sh as at april 2021 - need a fiddled copy so it is ignored until fixed
+        CONFIG_TEMPLATE = """## Planemo Global Configuration File.
+## Everything in this file is completely optional - these values can all be
+## configured via command line options for the corresponding commands.
+
+## Specify a default galaxy_root for test and server commands here.
+galaxy_root: %s
+## Username used with toolshed(s).
+#shed_username: "<TODO>"
+sheds:
+  # For each tool shed you wish to target, uncomment key or both email and
+  # password.
+  toolshed:
+    #key: "<TODO>"
+    #email: "<TODO>"
+    #password: "<TODO>"
+  testtoolshed:
+    #key: "<TODO>"
+    #email: "<TODO>"
+    #password: "<TODO>"
+  local:
+    #key: "<TODO>"
+    #email: "<TODO>"
+    #password: "<TODO>"
+"""
+        if not os.path.exists(config_path):
+            with open(config_path, "w") as f:
+                f.write(CONFIG_TEMPLATE % galaxyroot)
+
 
 def main():
     """
@@ -1105,6 +1149,7 @@
     a("--galaxy_venv", default="/galaxy_venv")
     a("--collection", action="append", default=[])
     a("--include_tests", default=False, action="store_true")
+    a("--python_version", default="3.9")
     args = parser.parse_args()
     assert not args.bad_user, (
         'UNAUTHORISED: %s is NOT authorized to use this tool until Galaxy \
@@ -1124,9 +1169,6 @@
         r.moveRunOutputs()
         r.makeToolTar()
     else:
-        # r.planemo_test(genoutputs=True)  # this fails :( - see PR
-        # r.moveRunOutputs()
-        # r.makeToolTar(report_fail=False)
         r.planemo_test_once()
         r.moveRunOutputs()
         r.makeToolTar(report_fail=True)