##// END OF EJS Templates
Merge pull request #1718 from bfroehle/cregexp_trait...
Min RK -
r6820:bcf5311c merge
parent child Browse files
Show More
@@ -22,7 +22,6 b' Authors:'
22 import copy
22 import copy
23 import logging
23 import logging
24 import os
24 import os
25 import re
26 import stat
25 import stat
27 import time
26 import time
28
27
@@ -58,7 +57,7 b' from IPython.config.application import Application'
58 from IPython.config.configurable import LoggingConfigurable
57 from IPython.config.configurable import LoggingConfigurable
59 from IPython.utils.text import EvalFormatter
58 from IPython.utils.text import EvalFormatter
60 from IPython.utils.traitlets import (
59 from IPython.utils.traitlets import (
61 Any, Integer, CFloat, List, Unicode, Dict, Instance, HasTraits,
60 Any, Integer, CFloat, List, Unicode, Dict, Instance, HasTraits, CRegExp
62 )
61 )
63 from IPython.utils.path import get_ipython_module_path, get_home_dir
62 from IPython.utils.path import get_ipython_module_path, get_home_dir
64 from IPython.utils.process import find_cmd, pycmd2argv, FindCmdError
63 from IPython.utils.process import find_cmd, pycmd2argv, FindCmdError
@@ -826,7 +825,7 b' def find_job_cmd():'
826
825
827 class WindowsHPCLauncher(BaseLauncher):
826 class WindowsHPCLauncher(BaseLauncher):
828
827
829 job_id_regexp = Unicode(r'\d+', config=True,
828 job_id_regexp = CRegExp(r'\d+', config=True,
830 help="""A regular expression used to get the job id from the output of the
829 help="""A regular expression used to get the job id from the output of the
831 submit_command. """
830 submit_command. """
832 )
831 )
@@ -857,7 +856,7 b' class WindowsHPCLauncher(BaseLauncher):'
857
856
858 def parse_job_id(self, output):
857 def parse_job_id(self, output):
859 """Take the output of the submit command and return the job id."""
858 """Take the output of the submit command and return the job id."""
860 m = re.search(self.job_id_regexp, output)
859 m = self.job_id_regexp.search(output)
861 if m is not None:
860 if m is not None:
862 job_id = m.group()
861 job_id = m.group()
863 else:
862 else:
@@ -1006,7 +1005,7 b' class BatchSystemLauncher(BaseLauncher):'
1006 help="The name of the command line program used to submit jobs.")
1005 help="The name of the command line program used to submit jobs.")
1007 delete_command = List([''], config=True,
1006 delete_command = List([''], config=True,
1008 help="The name of the command line program used to delete jobs.")
1007 help="The name of the command line program used to delete jobs.")
1009 job_id_regexp = Unicode('', config=True,
1008 job_id_regexp = CRegExp('', config=True,
1010 help="""A regular expression used to get the job id from the output of the
1009 help="""A regular expression used to get the job id from the output of the
1011 submit_command.""")
1010 submit_command.""")
1012 batch_template = Unicode('', config=True,
1011 batch_template = Unicode('', config=True,
@@ -1026,10 +1025,10 b' class BatchSystemLauncher(BaseLauncher):'
1026
1025
1027 # not configurable, override in subclasses
1026 # not configurable, override in subclasses
1028 # PBS Job Array regex
1027 # PBS Job Array regex
1029 job_array_regexp = Unicode('')
1028 job_array_regexp = CRegExp('')
1030 job_array_template = Unicode('')
1029 job_array_template = Unicode('')
1031 # PBS Queue regex
1030 # PBS Queue regex
1032 queue_regexp = Unicode('')
1031 queue_regexp = CRegExp('')
1033 queue_template = Unicode('')
1032 queue_template = Unicode('')
1034 # The default batch template, override in subclasses
1033 # The default batch template, override in subclasses
1035 default_template = Unicode('')
1034 default_template = Unicode('')
@@ -1060,7 +1059,7 b' class BatchSystemLauncher(BaseLauncher):'
1060
1059
1061 def parse_job_id(self, output):
1060 def parse_job_id(self, output):
1062 """Take the output of the submit command and return the job id."""
1061 """Take the output of the submit command and return the job id."""
1063 m = re.search(self.job_id_regexp, output)
1062 m = self.job_id_regexp.search(output)
1064 if m is not None:
1063 if m is not None:
1065 job_id = m.group()
1064 job_id = m.group()
1066 else:
1065 else:
@@ -1083,16 +1082,14 b' class BatchSystemLauncher(BaseLauncher):'
1083
1082
1084 # add jobarray or queue lines to user-specified template
1083 # add jobarray or queue lines to user-specified template
1085 # note that this is *only* when user did not specify a template.
1084 # note that this is *only* when user did not specify a template.
1086 regex = re.compile(self.job_array_regexp)
1085 # print self.job_array_regexp.search(self.batch_template)
1087 # print regex.search(self.batch_template)
1086 if not self.job_array_regexp.search(self.batch_template):
1088 if not regex.search(self.batch_template):
1089 self.log.debug("adding job array settings to batch script")
1087 self.log.debug("adding job array settings to batch script")
1090 firstline, rest = self.batch_template.split('\n',1)
1088 firstline, rest = self.batch_template.split('\n',1)
1091 self.batch_template = u'\n'.join([firstline, self.job_array_template, rest])
1089 self.batch_template = u'\n'.join([firstline, self.job_array_template, rest])
1092
1090
1093 regex = re.compile(self.queue_regexp)
1091 # print self.queue_regexp.search(self.batch_template)
1094 # print regex.search(self.batch_template)
1092 if self.queue and not self.queue_regexp.search(self.batch_template):
1095 if self.queue and not regex.search(self.batch_template):
1096 self.log.debug("adding PBS queue settings to batch script")
1093 self.log.debug("adding PBS queue settings to batch script")
1097 firstline, rest = self.batch_template.split('\n',1)
1094 firstline, rest = self.batch_template.split('\n',1)
1098 self.batch_template = u'\n'.join([firstline, self.queue_template, rest])
1095 self.batch_template = u'\n'.join([firstline, self.queue_template, rest])
@@ -1129,13 +1126,13 b' class PBSLauncher(BatchSystemLauncher):'
1129 help="The PBS submit command ['qsub']")
1126 help="The PBS submit command ['qsub']")
1130 delete_command = List(['qdel'], config=True,
1127 delete_command = List(['qdel'], config=True,
1131 help="The PBS delete command ['qsub']")
1128 help="The PBS delete command ['qsub']")
1132 job_id_regexp = Unicode(r'\d+', config=True,
1129 job_id_regexp = CRegExp(r'\d+', config=True,
1133 help="Regular expresion for identifying the job ID [r'\d+']")
1130 help="Regular expresion for identifying the job ID [r'\d+']")
1134
1131
1135 batch_file = Unicode(u'')
1132 batch_file = Unicode(u'')
1136 job_array_regexp = Unicode('#PBS\W+-t\W+[\w\d\-\$]+')
1133 job_array_regexp = CRegExp('#PBS\W+-t\W+[\w\d\-\$]+')
1137 job_array_template = Unicode('#PBS -t 1-{n}')
1134 job_array_template = Unicode('#PBS -t 1-{n}')
1138 queue_regexp = Unicode('#PBS\W+-q\W+\$?\w+')
1135 queue_regexp = CRegExp('#PBS\W+-q\W+\$?\w+')
1139 queue_template = Unicode('#PBS -q {queue}')
1136 queue_template = Unicode('#PBS -q {queue}')
1140
1137
1141
1138
@@ -1174,9 +1171,9 b' class PBSEngineSetLauncher(PBSLauncher, BatchClusterAppMixin):'
1174
1171
1175 class SGELauncher(PBSLauncher):
1172 class SGELauncher(PBSLauncher):
1176 """Sun GridEngine is a PBS clone with slightly different syntax"""
1173 """Sun GridEngine is a PBS clone with slightly different syntax"""
1177 job_array_regexp = Unicode('#\$\W+\-t')
1174 job_array_regexp = CRegExp('#\$\W+\-t')
1178 job_array_template = Unicode('#$ -t 1-{n}')
1175 job_array_template = Unicode('#$ -t 1-{n}')
1179 queue_regexp = Unicode('#\$\W+-q\W+\$?\w+')
1176 queue_regexp = CRegExp('#\$\W+-q\W+\$?\w+')
1180 queue_template = Unicode('#$ -q {queue}')
1177 queue_template = Unicode('#$ -q {queue}')
1181
1178
1182 class SGEControllerLauncher(SGELauncher, BatchClusterAppMixin):
1179 class SGEControllerLauncher(SGELauncher, BatchClusterAppMixin):
@@ -1218,13 +1215,13 b' class LSFLauncher(BatchSystemLauncher):'
1218 help="The PBS submit command ['bsub']")
1215 help="The PBS submit command ['bsub']")
1219 delete_command = List(['bkill'], config=True,
1216 delete_command = List(['bkill'], config=True,
1220 help="The PBS delete command ['bkill']")
1217 help="The PBS delete command ['bkill']")
1221 job_id_regexp = Unicode(r'\d+', config=True,
1218 job_id_regexp = CRegExp(r'\d+', config=True,
1222 help="Regular expresion for identifying the job ID [r'\d+']")
1219 help="Regular expresion for identifying the job ID [r'\d+']")
1223
1220
1224 batch_file = Unicode(u'')
1221 batch_file = Unicode(u'')
1225 job_array_regexp = Unicode('#BSUB[ \t]-J+\w+\[\d+-\d+\]')
1222 job_array_regexp = CRegExp('#BSUB[ \t]-J+\w+\[\d+-\d+\]')
1226 job_array_template = Unicode('#BSUB -J ipengine[1-{n}]')
1223 job_array_template = Unicode('#BSUB -J ipengine[1-{n}]')
1227 queue_regexp = Unicode('#BSUB[ \t]+-q[ \t]+\w+')
1224 queue_regexp = CRegExp('#BSUB[ \t]+-q[ \t]+\w+')
1228 queue_template = Unicode('#BSUB -q {queue}')
1225 queue_template = Unicode('#BSUB -q {queue}')
1229
1226
1230 def start(self, n):
1227 def start(self, n):
@@ -21,6 +21,7 b' Authors:'
21 # Imports
21 # Imports
22 #-----------------------------------------------------------------------------
22 #-----------------------------------------------------------------------------
23
23
24 import re
24 import sys
25 import sys
25 from unittest import TestCase
26 from unittest import TestCase
26
27
@@ -30,7 +31,7 b' from IPython.utils.traitlets import ('
30 HasTraits, MetaHasTraits, TraitType, Any, CBytes,
31 HasTraits, MetaHasTraits, TraitType, Any, CBytes,
31 Int, Long, Integer, Float, Complex, Bytes, Unicode, TraitError,
32 Int, Long, Integer, Float, Complex, Bytes, Unicode, TraitError,
32 Undefined, Type, This, Instance, TCPAddress, List, Tuple,
33 Undefined, Type, This, Instance, TCPAddress, List, Tuple,
33 ObjectName, DottedObjectName
34 ObjectName, DottedObjectName, CRegExp
34 )
35 )
35 from IPython.utils import py3compat
36 from IPython.utils import py3compat
36 from IPython.testing.decorators import skipif
37 from IPython.testing.decorators import skipif
@@ -890,3 +891,18 b' class TestMultiTuple(TraitTestBase):'
890 _default_value = (99,b'bottles')
891 _default_value = (99,b'bottles')
891 _good_values = [(1,b'a'), (2,b'b')]
892 _good_values = [(1,b'a'), (2,b'b')]
892 _bad_values = ((),10, b'a', (1,b'a',3), (b'a',1), (1, u'a'))
893 _bad_values = ((),10, b'a', (1,b'a',3), (b'a',1), (1, u'a'))
894
895 class CRegExpTrait(HasTraits):
896
897 value = CRegExp(r'')
898
899 class TestCRegExp(TraitTestBase):
900
901 def coerce(self, value):
902 return re.compile(value)
903
904 obj = CRegExpTrait()
905
906 _default_value = re.compile(r'')
907 _good_values = [r'\d+', re.compile(r'\d+')]
908 _bad_values = [r'(', None, ()]
General Comments 0
You need to be logged in to leave comments. Login now