comparison toolfactory/rgToolFactory2.py @ 66:bc1977b1f7b5 draft

Uploaded
author fubar
date Wed, 11 Nov 2020 04:35:24 +0000
parents ed1ecd161295
children 2cb06a59d84b
comparison
equal deleted inserted replaced
65:ed1ecd161295 66:bc1977b1f7b5
743 --description=<short description> 743 --description=<short description>
744 [--remote_repository_url=<URL to .shed.yml on github>] 744 [--remote_repository_url=<URL to .shed.yml on github>]
745 [--homepage_url=<Homepage for tool.>] 745 [--homepage_url=<Homepage for tool.>]
746 [--long_description=<long description>] 746 [--long_description=<long description>]
747 [--category=<category name>]* 747 [--category=<category name>]*
748 748
749 749
750 planemo shed_update --check_diff --shed_target testtoolshed 750 planemo shed_update --check_diff --shed_target testtoolshed
751 """ 751 """
752 if os.path.exists(self.tlog): 752 if os.path.exists(self.tlog):
753 tout = open(self.tlog, "a") 753 tout = open(self.tlog, "a")
754 else: 754 else:
758 rnames = [x.get('name','?') for x in repos] 758 rnames = [x.get('name','?') for x in repos]
759 rids = [x.get('id','?') for x in repos] 759 rids = [x.get('id','?') for x in repos]
760 tout.write(f'############names={rnames} rids={rids}') 760 tout.write(f'############names={rnames} rids={rids}')
761 cat = 'ToolFactory generated tools' 761 cat = 'ToolFactory generated tools'
762 if self.args.tool_name not in rnames: 762 if self.args.tool_name not in rnames:
763 cll = ["planemo", "shed_create", "--shed_target", "local", 763 cll = ["planemo", "shed_create", "--shed_target", "local",
764 "--owner","fubar","--name", 764 "--owner","fubar","--name",
765 self.args.tool_name,"--shed_key", 765 self.args.tool_name,"--shed_key",
766 self.args.toolshed_api_key,] 766 self.args.toolshed_api_key,]
767 try: 767 try:
768 p = subprocess.run( 768 p = subprocess.run(
836 "planemo", 836 "planemo",
837 "test", 837 "test",
838 "--galaxy_root", 838 "--galaxy_root",
839 self.args.galaxy_root, 839 self.args.galaxy_root,
840 "--update_test_data", 840 "--update_test_data",
841 "--docker",
841 xreal, 842 xreal,
842 ] 843 ]
843 p = subprocess.run( 844 p = subprocess.run(
844 cll, shell=False, cwd=self.tooloutdir, stderr=dummy, stdout=dummy, 845 cll, shell=False, cwd=self.tooloutdir, stderr=dummy, stdout=dummy,
845 ) 846 )
846 else: 847 else:
847 cll = ["planemo", "test", "--galaxy_root", 848 cll = ["planemo", "test", "--galaxy_root",
848 self.args.galaxy_root, 849 self.args.galaxy_root, "--docker",
849 xreal,] 850 xreal,]
850 p = subprocess.run( 851 p = subprocess.run(
851 cll, shell=False, cwd=self.tooloutdir, stderr=tout, stdout=tout 852 cll, shell=False, cwd=self.tooloutdir, stderr=tout, stdout=tout
852 ) 853 )
853 tout.close() 854 tout.close()
891 shutil.copyfile(pth, dest) 892 shutil.copyfile(pth, dest)
892 893
893 def makeToolTar(self): 894 def makeToolTar(self):
894 """ move outputs into test-data and prepare the tarball 895 """ move outputs into test-data and prepare the tarball
895 """ 896 """
897 excludeme = "tool_test_output"
898 def exclude_function(tarinfo):
899 filename = tarinfo.name
900 return None if filename.startswith(excludeme) or os.path.splitext(filename)[1].startswith(excludeme) else tarinfo
901
896 for p in self.outfiles: 902 for p in self.outfiles:
897 src = p[ONAMEPOS] 903 src = p[ONAMEPOS]
898 if os.path.isfile(src): 904 if os.path.isfile(src):
899 dest = os.path.join(self.testdir, "%s_sample" % src) 905 dest = os.path.join(self.testdir, "%s_sample" % src)
900 shutil.copyfile(src, dest) 906 shutil.copyfile(src, dest)
905 "### problem - output file %s not found in tooloutdir %s" 911 "### problem - output file %s not found in tooloutdir %s"
906 % (src, self.tooloutdir) 912 % (src, self.tooloutdir)
907 ) 913 )
908 self.newtarpath = "toolfactory_%s.tgz" % self.tool_name 914 self.newtarpath = "toolfactory_%s.tgz" % self.tool_name
909 tf = tarfile.open(self.newtarpath, "w:gz") 915 tf = tarfile.open(self.newtarpath, "w:gz")
910 tf.add(name=self.tooloutdir, arcname=self.tool_name) 916 tf.add(name=self.tooloutdir, arcname=self.tool_name, filter=exclude_function)
911 tf.close() 917 tf.close()
912 shutil.copyfile(self.newtarpath, self.args.new_tool) 918 shutil.copyfile(self.newtarpath, self.args.new_tool)
913 919
914 def moveRunOutputs(self): 920 def moveRunOutputs(self):
915 """need to move planemo or run outputs into toolfactory collection 921 """need to move planemo or run outputs into toolfactory collection
924 ext = ".txt" 930 ext = ".txt"
925 ofn = "%s%s" % (entry.name.replace(".", "_"), ext) 931 ofn = "%s%s" % (entry.name.replace(".", "_"), ext)
926 dest = os.path.join(self.repdir, ofn) 932 dest = os.path.join(self.repdir, ofn)
927 src = os.path.join(self.tooloutdir, entry.name) 933 src = os.path.join(self.tooloutdir, entry.name)
928 shutil.copyfile(src, dest) 934 shutil.copyfile(src, dest)
929 if entry.name.startswith('tool_test_output'):
930 os.unlink(src)
931 935
932 936
933 def main(): 937 def main():
934 """ 938 """
935 This is a Galaxy wrapper. It expects to be called by a special purpose tool.xml as: 939 This is a Galaxy wrapper. It expects to be called by a special purpose tool.xml as:
985 for i, x in enumerate(args.additional_parameters): 989 for i, x in enumerate(args.additional_parameters):
986 args.additional_parameters[i] = args.additional_parameters[i].replace('"', "") 990 args.additional_parameters[i] = args.additional_parameters[i].replace('"', "")
987 r = ScriptRunner(args) 991 r = ScriptRunner(args)
988 r.writeShedyml() 992 r.writeShedyml()
989 r.makeTool() 993 r.makeTool()
990 retcode = r.planemo_test(genoutputs=True) # this fails :( - see PR 994 if args.make_Tool == "generate":
991 r.moveRunOutputs() 995 retcode = r.run()
992 r.makeToolTar() 996 r.moveRunOutputs()
993 retcode = r.planemo_test(genoutputs=False) 997 r.makeToolTar()
994 r.moveRunOutputs() 998 else:
995 if args.make_Tool == "gentestinstall": 999 retcode = r.planemo_test(genoutputs=True) # this fails :( - see PR
996 retcode = r.planemo_shedload() #r.shedLoad() 1000 r.moveRunOutputs()
997 print(f'planemo_shedload returned {retcode}') 1001 r.makeToolTar()
998 r.eph_galaxy_load() 1002 retcode = r.planemo_test(genoutputs=False)
1003 r.moveRunOutputs()
1004 if args.make_Tool == "gentestinstall":
1005 retcode = r.planemo_shedload() #r.shedLoad()
1006 print(f'planemo_shedload returned {retcode}')
1007 r.eph_galaxy_load()
999 1008
1000 1009
1001 1010
1002 if __name__ == "__main__": 1011 if __name__ == "__main__":
1003 main() 1012 main()