Ticket #12530: trac_12530sage_combinat_scriptguardsnt.patch
File trac_12530sage_combinat_scriptguardsnt.patch, 8.7 KB (added by , 10 years ago) 


sagecombinat
# HG changeset patch # User Nicolas M. Thiery <nthiery@users.sf.net> # Date 1329503343 3600 # Node ID 7a8a21d105ac87e6c32bc597d10f1dc518866a34 # Parent 44a4edfb0f0d997d9615aee92a5f204fb8a6bb4e #12530: Improve the sagecombinat script to support guards for developpers versions diff git a/sagecombinat b/sagecombinat
a b 2 2 3 3 import os 4 4 import re 5 from re import split6 from sys import argv, stderr7 from subprocess import *8 5 from optparse import OptionParser 9 import ConfigParser 6 from sys import stderr 7 from subprocess import Popen, PIPE 8 from warnings import warn 10 9 11 10 if "SAGE_ROOT" in os.environ: 12 11 sage = os.environ["SAGE_ROOT"]+"/sage" … … def get_sage_root(): 88 87 sage_root = Popen(["echo 'echo ROOT${SAGE_ROOT}ROOT'  "+sage+" sh"], stdout=PIPE, shell=True).communicate()[0] 89 88 except OSError, e: 90 89 error("Could not start sage"+str(e)) 91 return split("ROOT", sage_root)[1] 90 return re.split("ROOT", sage_root)[1] 91 92 """ 93 A regexp matching Sage version strings 94 95 EXAMPLES:: 96 97 sage: re.search(version_regexp, "Sage Version 5.0").group() 98 '5.0' 99 sage: re.search(version_regexp, "Sage Version 5.4.2").group() 100 '5.4.2' 101 sage: re.search(version_regexp, "Sage Version 5.3.1.alpha3").group() 102 '5.3.1.alpha3' 103 sage: re.search(version_regexp, "Sage Version 5.3.1.alpha3 blah blah").group() 104 '5.3.1.alpha3' 105 sage: re.search(version_regexp, "Sage Version 5.3.beta2 blah blah").group() 106 '5.3.beta2' 107 sage: re.search(version_regexp, "Sage Version 5.rc0 blah blah").group() 108 '5.rc0' 109 110 sage: re.match(version_regexp, "Sage Version 5.rc0 blah blah") 111 sage: re.match(version_regexp, "5.rc0 blah").group() 112 '5.rc0' 113 sage: re.match(version_regexp+"$", "4_3_3:") 114 sage: re.match(version_regexp, "4_3_3:") 115 '4_3_3' 116 117 """ 118 version_regexp = '(\d+(\._))*(\d+)((\._)(alphabetarc)(\d+))?' 92 119 93 120 def get_sage_version(): 94 121 global sage … … def get_sage_version(): 98 125 except OSError, e: 99 126 error("Could not start sage"+str(e)) 100 127 101 match = re.search( '(\d+\.)*(\d+)',sage_version)128 match = re.search(version_regexp, sage_version) 102 129 if match is None: 103 130 error("Cannot determine Sage version number from"+sage_version) 104 131 else: 105 132 version = match.group() 106 133 return version 107 134 135 def encode_sage_version_for_comparison(version): 136 """ 137 Encodes a version of Sage as a list for comparison purposes 138 139 INPUT: 140 141  ``version``  a string 142 143 sage: encode_sage_version_for_comparison("4.2") 144 [4, 2, 0] 145 sage: encode_sage_version_for_comparison("5.0.beta3") 146 [5, 0, 3, 3, 0] 147 sage: encode_sage_version_for_comparison("4.2.1.rc0") 148 [4, 2, 1, 1, 0, 0] 149 sage: encode_sage_version_for_comparison("4.0.alpha3") 150 [4, 0, 3, 3, 0] 151 152 The only purpose of this encoding is that Python's standard 153 (lexicographic) comparison of lists implements the comparison of 154 Sage versions. 155 156 EXAMPLES:: 157 158 sage: e = encode_sage_version_for_comparison 159 sage: e("4.2") < e("4.2.1") 160 True 161 sage: e("4.2.1") < e("4.2.2") 162 True 163 sage: e("4.2.rc0") < e("4.2") 164 True 165 sage: e("4.7.2.rc0") < e("4.7.2.rc2") 166 True 167 sage: e("4.7.2.beta2") < e("4.7.2") 168 True 169 sage: e("4.7.2.beta2") < e("4.7.2.beta3") 170 True 171 sage: e("4.7.2.beta10") < e("4.7.2.rc0") 172 True 173 """ 174 version = version.replace("alpha", "3.") 175 version = version.replace("beta", "2.") 176 version = version.replace("rc", "1.") 177 return [int(s) for s in re.split("\._", version)]+[0] 178 179 def cmp_sage_versions(version1, version2): 180 """ 181 Compares two Sage versions given as strings 182 183 EXAMPLES:: 184 185 sage: cmp_sage_versions("4.2", "4.2.1") 186 1 187 sage: cmp_sage_versions("4.2.1", "4.2.2") 188 1 189 sage: cmp_sage_versions("4.2.rc0", "4.2") 190 1 191 sage: cmp_sage_versions("4.7.2.rc0", "4.7.2.rc2") 192 1 193 sage: cmp_sage_versions("4.7.2.beta2", "4.7.2") 194 1 195 sage: cmp_sage_versions("4.7.2.beta2", "4.7.2.beta3") 196 1 197 sage: cmp_sage_versions("4.7.2.beta10", "4.7.2.rc0") 198 1 199 sage: cmp_sage_versions("4.7.2.beta10", "4.7.2.beta10") 200 0 201 202 """ 203 return cmp(encode_sage_version_for_comparison(version1), encode_sage_version_for_comparison(version2)) 108 204 109 205 def cd_to_combinat(): 110 206 global sage_combinat_root … … def hg_query(command, dir): 117 213 r""" 118 214 Runs hg in the directory dir, and returns its output as a string 119 215 """ 216 cd_to_combinat() # make sure we are in the sage combinat directory 120 217 return Popen(["cd %s && %s %s"%(dir,hg,command)], stdout=PIPE, shell=True).communicate()[0].rstrip() 121 218 122 219 def hg_status(): … … def hg_series(): 136 233 return hg_query("qseries", sage_combinat_root) 137 234 138 235 def hg_all_patches(): 139 return split("\r\n\r\n",hg_series())236 return re.split("\r\n\r\n",hg_series()) 140 237 141 238 def hg_qnext(): 142 239 global sage_combinat_root 143 240 return hg_query("qnext", sage_combinat_root) 144 241 145 242 def hg_all_guards(): 146 return split("\r\n\r\n",147 hg_query("qselect s", sage_combinat_root))243 return re.split("\r\n\r\n", 244 hg_query("qselect s", sage_combinat_root)) 148 245 149 246 def hg_active_guards(): 150 247 # hg qselect v returns all the active guards, one per line 151 248 # the first line is always "active guards" or "no active guards" 152 return split("\r\n\r\n",153 hg_query("qselect v", sage_combinat_root))[1:]249 return re.split("\r\n\r\n", 250 hg_query("qselect v", sage_combinat_root))[1:] 154 251 155 252 def hg_are_all_patch_applied(): 156 253 return hg_qnext() == "All patches applied" … … def qselect_backward_compatibility_patch 181 278 182 279 # FIXME: how to change the guards on a one by one basis 183 280 184 non_version_guards = filter(lambda guard: re.match( "^(sage_)?(\d+_)*(\d+)$", guard) is None, hg_active_guards())281 non_version_guards = filter(lambda guard: re.match(version_regexp, guard) is None, hg_active_guards()) 185 282 info("Current non version guards: %s"%" ".join(non_version_guards)) 186 283 187 284 if options.n: 188 285 non_version_guards = [] 189 286 … … def qselect_backward_compatibility_patch 191 288 192 289 info("Updated non version guards: %s"%" ".join(non_version_guards)) 193 290 194 sage_version_as_list = [int(s) for s in re.split("\.", sage_version)]195 291 def is_newversion_guard(guard): 196 292 """ 197 Returns true if this is a guard of the form a_b_c with a.b.c> sage_version293 Returns true if this is a guard for version X (like 4_3_3 or 5_0_beta4) with X > sage_version 198 294 """ 199 if not re.match("^\+(sage_)?(\d+_)*(\d+)$",guard): 295 if not re.match(version_regexp+"$", guard): 296 if re.match(version_regexp, guard): 297 # Catch erroneous guards like 4_3_3: 298 message = "Invalid version guard in the mercurial queue: %s"%guard 299 if options.force: 300 warn(message) 301 else: 302 error(message) 200 303 return False 201 guard = re.sub("^\+(sage_)?","", guard) 202 guard_as_list = [int(s) for s in re.split("_", guard)] 203 if guard_as_list > sage_version_as_list: 304 if cmp_sage_versions(guard, sage_version) > 0: 204 305 info("Keep backward compatibility patches for sage "+re.sub("_",".",guard)) 205 306 return True 206 307 else: 207 308 info("Skip backward compatibility patches for sage "+re.sub("_",".",guard)) 208 309 return False 209 310 210 version_guards = map(lambda guard: guard[1:], # get rid of leading "+" 211 filter(is_newversion_guard, hg_all_guards())) 311 version_guards = filter(is_newversion_guard, 312 map(lambda guard: guard[1:], # get rid of leading "+" 313 hg_all_guards())) 212 314 213 315 info("Updating guards") 214 316 system(hg+" qselect q n") … … def update(update_from_sage_main = False 223 325  push back the patches 224 326  rebuild 225 327 """ 226 cd_to_combinat()227 328 check_for_no_diff() 228 329 229 330 info("Storing top applied patch") … … elif args[0] == "install": 305 406 info("Done") 306 407 assert(os.path.exists(sage_combinat_hg)) 307 408 assert(not os.path.exists(sage_combinat_patch_queue)) 308 cd_to_combinat()309 409 check_for_no_diff(check_patch_queue=False) 310 410 info("Uploading sagecombinat patches into .hg/patches:") 311 411 system("cd .hg/; "+hg+" clone %s patches"%options.server) … … elif args[0] == "update": 320 420 update() 321 421 322 422 elif args[0] == "upgrade": 323 cd_to_combinat()324 423 check_for_no_diff() 325 424 info("Upgrading sage") 326 425 system(sage+" upgrade")