Overview
Comment: | [build] new option: force rebuild + code clarification (Python f-strings) |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk | build |
Files: | files | file ages | folders |
SHA3-256: |
a3f82d3151d0e2071053c7aafd6abb5f |
User & Date: | olr on 2020-04-22 06:20:17 |
Other Links: | manifest | tags |
Context
2020-04-22
| ||
10:58 | [build] fix URL id check-in: 959afab163 user: olr tags: trunk, build | |
06:20 | [build] new option: force rebuild + code clarification (Python f-strings) check-in: a3f82d3151 user: olr tags: trunk, build | |
04:33 | [build][core] stricter building process, store URLs in a separate dictionary [fr] ajustements (rebuild necessary to avoid bug) check-in: b543565245 user: olr tags: trunk, fr, core, build | |
Changes
Modified compile_rules.py from [0bae5e7ec9] to [f64fcce154].
︙ | ︙ | |||
135 136 137 138 139 140 141 | return 0 def createRule (s, nIdLine, sLang, bParagraph, dOptPriority): "returns rule as list [option name, regex, bCaseInsensitive, identifier, list of actions]" global dJSREGEXES | | | 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | return 0 def createRule (s, nIdLine, sLang, bParagraph, dOptPriority): "returns rule as list [option name, regex, bCaseInsensitive, identifier, list of actions]" global dJSREGEXES sLineId = f"#{nIdLine}" + ("p" if bParagraph else "s") sRuleId = sLineId #### GRAPH CALL if s.startswith("@@@@"): if bParagraph: print("Error. Graph call can be made only after the first pass (sentence by sentence)") exit() |
︙ | ︙ | |||
160 161 162 163 164 165 166 | if m: cWordLimitLeft = m.group('borders_and_case')[0] cCaseMode = m.group('borders_and_case')[1] cWordLimitRight = m.group('borders_and_case')[2] sOption = m.group('option')[1:] if m.group('option') else False sRuleId = m.group('ruleid')[1:-1] if sRuleId in aRULESET: | | | | | | | | | | | | | | | | 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 | if m: cWordLimitLeft = m.group('borders_and_case')[0] cCaseMode = m.group('borders_and_case')[1] cWordLimitRight = m.group('borders_and_case')[2] sOption = m.group('option')[1:] if m.group('option') else False sRuleId = m.group('ruleid')[1:-1] if sRuleId in aRULESET: print(f"# Error. Several rules have the same id: {sRuleId}") exit() aRULESET.add(sRuleId) nPriority = dOptPriority.get(sOption, 4) if m.group('priority'): nPriority = int(m.group('priority')[1:]) s = s[m.end(0):] else: print(f"# Warning. Rule wrongly shaped at line: {sLineId}") exit() #### REGEX TRIGGER i = s.find(" <<-") if i == -1: print(f"# Error: no condition at line {sLineId}") return None sRegex = s[:i].strip() s = s[i+4:] # JS groups positioning codes m = re.search("@@\\S+", sRegex) if m: tGroups = jsconv.groupsPositioningCodeToList(sRegex[m.start()+2:]) sRegex = sRegex[:m.start()].strip() # JS regex m = re.search("<js>.+</js>i?", sRegex) if m: dJSREGEXES[sLineId] = m.group(0) sRegex = sRegex[:m.start()].strip() if "<js>" in sRegex or "</js>" in sRegex: print(f"# Error: JavaScript regex not delimited at line {sLineId}") return None # quotes ? if sRegex.startswith('"') and sRegex.endswith('"'): sRegex = sRegex[1:-1] ## definitions for sDef, sRepl in dDEFINITIONS.items(): sRegex = sRegex.replace(sDef, sRepl) ## count number of groups (must be done before modifying the regex) nGroup = countGroupInRegex(sRegex) if nGroup > 0: if not tGroups: print(f"# Warning: groups positioning code for JavaScript should be defined at line {sLineId}") else: if nGroup != len(tGroups): print(f"# Error: groups positioning code irrelevant at line {sLineId}") ## word limit if cWordLimitLeft == '[' and not sRegex.startswith(("^", '’', "'", ",")): sRegex = sWORDLIMITLEFT + sRegex if cWordLimitRight == ']' and not sRegex.endswith(("$", '’', "'", ",")): sRegex = sRegex + sWORDLIMITRIGHT ## casing mode if cCaseMode == "i": bCaseInsensitive = True if not sRegex.startswith("(?i)"): sRegex = "(?i)" + sRegex elif cCaseMode == "s": bCaseInsensitive = False sRegex = sRegex.replace("(?i)", "") elif cCaseMode == "u": bCaseInsensitive = False sRegex = sRegex.replace("(?i)", "") sRegex = uppercase(sRegex, sLang) else: print(f"# Unknown case mode [{cCaseMode}] at line {sLineId}") ## check regex try: re.compile(sRegex) except re.error: print(f"# Regex error at line {sLineId}") print(sRegex) return None ## groups in non grouping parenthesis for _ in re.finditer(r"\(\?:[^)]*\([\[\w -]", sRegex): print(f"# Warning: groups inside non grouping parenthesis in regex at line {sLineId}") #### PARSE ACTIONS lActions = [] nAction = 1 for sAction in s.split(" <<- "): t = createAction(sRuleId + "_" + str(nAction), sAction, nGroup) nAction += 1 if t: lActions.append(t) if not lActions: return None return [sOption, sRegex, bCaseInsensitive, sLineId, sRuleId, nPriority, lActions, tGroups] def checkReferenceNumbers (sText, sActionId, nToken): "check if token references in <sText> greater than <nToken> (debugging)" for x in re.finditer(r"\\(\d+)", sText): if int(x.group(1)) > nToken: print(f"# Error in token index at line {sActionId} ({nToken} tokens only)") print(sText) def checkIfThereIsCode (sText, sActionId): "check if there is code in <sText> (debugging)" if re.search("[.]\\w+[(]|sugg\\w+[(]|\\([0-9]|\\[[0-9]", sText): print(f"# Warning at line {sActionId}: This message looks like code. Line should probably begin with =") print(sText) def createAction (sIdAction, sAction, nGroup): "returns an action to perform as a tuple (condition, action type, action[, iGroup [, message, URL ]])" m = re.search(r"([-~=>])(\d*|)>>", sAction) if not m: print(f"# No action at line {sIdAction}") return None #### CONDITION sCondition = sAction[:m.start()].strip() if sCondition: sCondition = prepareFunction(sCondition) lFUNCTIONS.append(("_c_"+sIdAction, sCondition)) checkReferenceNumbers(sCondition, sIdAction, nGroup) if ".match" in sCondition: print("# Error. JS compatibility. Don't use .match() in condition, use .search()") sCondition = "_c_"+sIdAction else: sCondition = None #### iGroup / positioning iGroup = int(m.group(2)) if m.group(2) else 0 if iGroup > nGroup: print(f"# Selected group > group number in regex at line {sIdAction}") #### ACTION sAction = sAction[m.end():].strip() cAction = m.group(1) if cAction == "-": ## error iMsg = sAction.find(" # ") if iMsg == -1: sMsg = "# Error. Error message not found." sURL = "" print(f"# No message. Action id: {sIdAction}") else: sMsg = sAction[iMsg+3:].strip() sAction = sAction[:iMsg].strip() sURL = "" mURL = re.search("[|] *(https?://.*)", sMsg) if mURL: sURL = mURL.group(1).strip() |
︙ | ︙ | |||
333 334 335 336 337 338 339 | checkIfThereIsCode(sAction, sIdAction) if cAction == ">": ## no action, break loop if condition is False return [sCondition, cAction, ""] if not sAction: | | | | | | 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 | checkIfThereIsCode(sAction, sIdAction) if cAction == ">": ## no action, break loop if condition is False return [sCondition, cAction, ""] if not sAction: print(f"# Error in action at line {sIdAction}: This action is empty.") return None if cAction == "-": ## error detected --> suggestion if sAction[0:1] == "=": lFUNCTIONS.append(("_s_"+sIdAction, sAction[1:])) sAction = "=_s_"+sIdAction elif sAction.startswith('"') and sAction.endswith('"'): sAction = sAction[1:-1] if not sMsg: print(f"# Error in action at line {sIdAction}: the message is empty.") return [sCondition, cAction, sAction, iGroup, sMsg, sURL] if cAction == "~": ## text processor if sAction[0:1] == "=": lFUNCTIONS.append(("_p_"+sIdAction, sAction[1:])) sAction = "=_p_"+sIdAction elif sAction.startswith('"') and sAction.endswith('"'): sAction = sAction[1:-1] return [sCondition, cAction, sAction, iGroup] if cAction == "=": ## disambiguator if sAction[0:1] == "=": sAction = sAction[1:] if "define" in sAction and not re.search(r"define\(dTokenPos, *m\.start.*, \[.*\] *\)", sAction): print(f"# Error in action at line {sIdAction}: second argument for define must be a list of strings") print(sAction) lFUNCTIONS.append(("_d_"+sIdAction, sAction)) sAction = "_d_"+sIdAction return [sCondition, cAction, sAction] print(f"# Unknown action at line {sIdAction}") return None def _calcRulesStats (lRules): "count rules and actions" d = {'=':0, '~': 0, '-': 0, '>': 0} for aRule in lRules: |
︙ | ︙ | |||
464 465 466 467 468 469 470 | def printBookmark (nLevel, sComment, nLine): "print bookmark within the rules file" print(" {:>6}: {}".format(nLine, " " * nLevel + sComment)) | | | | > | > | 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 | def printBookmark (nLevel, sComment, nLine): "print bookmark within the rules file" print(" {:>6}: {}".format(nLine, " " * nLevel + sComment)) def make (spLang, sLang, bUseCache=None): "compile rules, returns a dictionary of values" # for clarity purpose, don’t create any file here (except cache) dCacheVars = None if os.path.isfile("_build/data_cache.json"): print("> data cache found") sJSON = open("_build/data_cache.json", "r", encoding="utf-8").read() dCacheVars = json.loads(sJSON) sBuildDate = time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime(dCacheVars.get("fBuildTime", 0))) if bUseCache: print("> use cache (no rebuild asked)") print(" build made at: " + sBuildDate) return dCacheVars print("> read rules file...") try: sFileContent = open(spLang + "/rules.grx", 'r', encoding="utf-8").read() except OSError: print(f"# Error. Rules file in project <{sLang}> not found.") exit() # calculate hash of loaded file xHasher = hashlib.new("sha3_512") xHasher.update(sFileContent.encode("utf-8")) sFileHash = xHasher.hexdigest() if dCacheVars and bUseCache != False and sFileHash == dCacheVars.get("sFileHash", ""): # if <bUseCache> is None or True, we can use the cache print("> cache hash identical to file hash, use cache") print(" build made at: " + sBuildDate) return dCacheVars # removing comments, zeroing empty lines, creating definitions, storing tests, merging rule lines print(" parsing rules...") fBuildTime = time.time() |
︙ | ︙ | |||
519 520 521 522 523 524 525 | pass elif sLine.startswith("DEF:"): # definition m = re.match("DEF: +([a-zA-Z_][a-zA-Z_0-9]*) +(.+)$", sLine.strip()) if m: dDEFINITIONS["{"+m.group(1)+"}"] = m.group(2) else: | | | 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 | pass elif sLine.startswith("DEF:"): # definition m = re.match("DEF: +([a-zA-Z_][a-zA-Z_0-9]*) +(.+)$", sLine.strip()) if m: dDEFINITIONS["{"+m.group(1)+"}"] = m.group(2) else: print("# Error in definition: ", end="") print(sLine.strip()) elif sLine.startswith("DECL:"): # declensions m = re.match(r"DECL: +(\+\w+) (.+)$", sLine.strip()) if m: dDECLENSIONS[m.group(1)] = m.group(2).strip().split() else: |
︙ | ︙ | |||
624 625 626 627 628 629 630 | elif sFuncName.startswith("_s_"): # suggestion sParams = "sSentence, m" elif sFuncName.startswith("_p_"): # preprocessor sParams = "sSentence, m" elif sFuncName.startswith("_d_"): # disambiguator sParams = "sSentence, m, dTokenPos" else: | | | | | | 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 | elif sFuncName.startswith("_s_"): # suggestion sParams = "sSentence, m" elif sFuncName.startswith("_p_"): # preprocessor sParams = "sSentence, m" elif sFuncName.startswith("_d_"): # disambiguator sParams = "sSentence, m, dTokenPos" else: print(f"# Unknown function type in <{sFuncName}>") continue # Python sPyCallables += f"def {sFuncName} ({sParams}):\n" sPyCallables += f" return {sReturn}\n" # JavaScript sJSCallables += f" {sFuncName}: function ({sParams}) {{\n" sJSCallables += " return " + jsconv.py2js(sReturn) + ";\n" sJSCallables += " },\n" displayStats(lParagraphRules, lSentenceRules) dVars = { "fBuildTime": fBuildTime, |
︙ | ︙ |
Modified compile_rules_graph.py from [86b9b97d23] to [3a1bfb17f3].
︙ | ︙ | |||
97 98 99 100 101 102 103 | self.dDef = dDef self.dDecl = dDecl self.dOptPriority = dOptPriority self.dAntiPatterns = {} self.dActions = {} self.dFuncName = {} self.dFunctions = {} | < | 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | self.dDef = dDef self.dDecl = dDecl self.dOptPriority = dOptPriority self.dAntiPatterns = {} self.dActions = {} self.dFuncName = {} self.dFunctions = {} def _genTokenLines (self, sTokenLine): "tokenize a string and return a list of lines of tokens" lTokenLines = [] for sTokBlock in sTokenLine.split(): # replace merger characters by spaces if "␣" in sTokBlock: |
︙ | ︙ | |||
320 321 322 323 324 325 326 | if cAction == "-": ## error iMsg = sAction.find(" # ") if iMsg == -1: sMsg = "# Error. Error message not found." sURL = "" | | | 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 | if cAction == "-": ## error iMsg = sAction.find(" # ") if iMsg == -1: sMsg = "# Error. Error message not found." sURL = "" print("\n# Error. No message at: ", sLineId, sActionId) else: sMsg = sAction[iMsg+3:].strip() sAction = sAction[:iMsg].strip() sURL = "" mURL = re.search("[|] *(https?://.*)", sMsg) if mURL: sURL = mURL.group(1).strip() |
︙ | ︙ | |||
474 475 476 477 478 479 480 | iActionBlock = 0 aRuleName = set() for iLine, sLine in lRule: sLine = sLine.rstrip() if "\t" in sLine: # tabulation not allowed | | | | | | | 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 | iActionBlock = 0 aRuleName = set() for iLine, sLine in lRule: sLine = sLine.rstrip() if "\t" in sLine: # tabulation not allowed print("# Error. Tabulation at line: ", iLine) exit() elif sLine.startswith("@@@@GRAPH: "): # rules graph call m = re.match(r"@@@@GRAPH: *(\w+) *[|] *(\w+)", sLine.strip()) if m: sGraphName = m.group(1) sGraphCode = m.group(2) if sGraphName in dAllGraph or sGraphCode in dGraphCode: print(f"# Error at line {iLine}. Graph name <{sGraphName}> or graph code <{sGraphCode}> already exists.") exit() dAllGraph[sGraphName] = [] dGraphCode[sGraphName] = sGraphCode else: print("# Error. Graph name not found at line", iLine) exit() elif sLine.startswith("__") and sLine.endswith("__"): # new rule group m = re.match("__(\\w+)(!\\d|)__", sLine) if m: sRuleName = m.group(1) if sRuleName in aRuleName: print(f"# Error at line {iLine}. Rule name <{sRuleName}> already exists.") exit() aRuleName.add(sRuleName) iActionBlock = 1 nPriority = int(m.group(2)[1:]) if m.group(2) else -1 else: print("# Syntax error in rule group: ", sLine, " -- line:", iLine) exit() elif re.match(" \\S", sLine): # tokens line lTokenLine.append([iLine, sLine.strip()]) elif sLine.startswith(" ||"): # tokens line continuation iPrevLine, sPrevLine = lTokenLine[-1] |
︙ | ︙ | |||
531 532 533 534 535 536 537 | if re.search(r"[-=~/!>](?:-?\d\.?(?::\.?-?\d+|)|):?>>", sLine): bActionBlock = False elif re.match("[ ]*$", sLine): # empty line to end merging if not lTokenLine: continue if bActionBlock or not lActions: | | | | | 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 | if re.search(r"[-=~/!>](?:-?\d\.?(?::\.?-?\d+|)|):?>>", sLine): bActionBlock = False elif re.match("[ ]*$", sLine): # empty line to end merging if not lTokenLine: continue if bActionBlock or not lActions: print("# Error. No action found at line:", iLine) print(bActionBlock, lActions) exit() if not sGraphName: print("# Error. All rules must belong to a named graph. Line: ", iLine) exit() for j, sTokenLine in lTokenLine: dAllGraph[sGraphName].append((j, sRuleName, sTokenLine, iActionBlock, list(lActions), nPriority)) lTokenLine.clear() lActions.clear() iActionBlock += 1 else: print("# Unknown line at:", iLine) print(sLine) # processing rules print(" processing graph rules...") initProcessPoolExecutor(len(dAllGraph)) fStartTimer = time.time() # build graph |
︙ | ︙ |
Modified make.py from [1c6f30e738] to [2561b9d2fe].
︙ | ︙ | |||
30 31 32 33 34 35 36 | def getConfig (sLang): "load config.ini in <sLang> at gc_lang/<sLang>, returns xConfigParser object" xConfig = configparser.ConfigParser() xConfig.optionxform = str try: | | | | | < < | | | | | | > | | | 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | def getConfig (sLang): "load config.ini in <sLang> at gc_lang/<sLang>, returns xConfigParser object" xConfig = configparser.ConfigParser() xConfig.optionxform = str try: xConfig.read_file(open(f"gc_lang/{sLang}/config.ini", "r", encoding="utf-8")) except FileNotFoundError: print(f"# Error. Can’t read config file <{sLang}>") exit() return xConfig def createOptionsLabelProperties (dOptLbl): "create content for .properties files (LibreOffice)" sContent = "" for sOpt, tLabel in dOptLbl.items(): sContent += f"{sOpt}={tLabel[0]}\n" if tLabel[1]: sContent += f"hlp_{sOpt}={tLabel[1]}\n" return sContent def createDialogOptionsXDL (dVars): "create bundled dialog options file .xdl (LibreOffice)" iTab = 1 nPosY = 5 nWidth = 240 sContent = "" dOpt = dVars["dOptWriter"] dOptLabel = dVars["dOptLabel"][dVars["lang"]] for sGroup, lGroupOptions in dVars["lStructOpt"]: sContent += f'<dlg:fixedline dlg:id="{sGroup}" dlg:tab-index="{iTab}" dlg:top="{nPosY}" dlg:left="5" dlg:width="{nWidth}" dlg:height="10" dlg:value="&{sGroup}" />\n' iTab += 1 for lLineOptions in lGroupOptions: nElemWidth = nWidth // len(lLineOptions) nPosY += 10 nPosX = 10 for sOpt in lLineOptions: sHelp = f'dlg:help-text="&hlp_{sOpt}"' if dOptLabel[sOpt][1] else "" sChecked = "true" if dOpt[sOpt] else "false" sContent += f'<dlg:checkbox dlg:id="{sOpt}" dlg:tab-index="{iTab}" dlg:top="{nPosY}" dlg:left="{nPosX}" dlg:width="{nElemWidth}" dlg:height="10" dlg:value="&{sOpt}" dlg:checked="{sChecked}" {sHelp} />\n' iTab += 1 nPosX += nElemWidth nPosY += 10 return sContent def createOXT (spLang, dVars, dOxt, spLangPack, bInstall): "create extension for Writer" print("Building extension for Writer") spfZip = f"_build/{dVars['name']}-{dVars['lang']}-v{dVars['version']}.oxt" hZip = zipfile.ZipFile(spfZip, mode='w', compression=zipfile.ZIP_DEFLATED) # Package and parser copyGrammalectePyPackageInZipFile(hZip, spLangPack, "pythonpath/") hZip.write("grammalecte-cli.py", "pythonpath/grammalecte-cli.py") # Extension files |
︙ | ︙ | |||
114 115 116 117 118 119 120 | dVars["xcs_options"] = "\n".join([ '<prop oor:name="'+sOpt+'" oor:type="xs:string"><value></value></prop>' for sOpt in dVars["dOptPython"] ]) dVars["xcu_label_values"] = "\n".join([ '<value xml:lang="'+sLang+'">' + dVars["dOptLabel"][sLang]["__optiontitle__"] + '</value>' for sLang in dVars["dOptLabel"] ]) hZip.writestr("dialog/options_page.xdl", helpers.fileFile("gc_core/py/oxt/options_page.xdl", dVars)) hZip.writestr("dialog/OptionsDialog.xcs", helpers.fileFile("gc_core/py/oxt/OptionsDialog.xcs", dVars)) hZip.writestr("dialog/OptionsDialog.xcu", helpers.fileFile("gc_core/py/oxt/OptionsDialog.xcu", dVars)) hZip.writestr("dialog/" + dVars['lang'] + "_en.default", "") for sLangLbl, dOptLbl in dVars['dOptLabel'].items(): | | | 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | dVars["xcs_options"] = "\n".join([ '<prop oor:name="'+sOpt+'" oor:type="xs:string"><value></value></prop>' for sOpt in dVars["dOptPython"] ]) dVars["xcu_label_values"] = "\n".join([ '<value xml:lang="'+sLang+'">' + dVars["dOptLabel"][sLang]["__optiontitle__"] + '</value>' for sLang in dVars["dOptLabel"] ]) hZip.writestr("dialog/options_page.xdl", helpers.fileFile("gc_core/py/oxt/options_page.xdl", dVars)) hZip.writestr("dialog/OptionsDialog.xcs", helpers.fileFile("gc_core/py/oxt/OptionsDialog.xcs", dVars)) hZip.writestr("dialog/OptionsDialog.xcu", helpers.fileFile("gc_core/py/oxt/OptionsDialog.xcu", dVars)) hZip.writestr("dialog/" + dVars['lang'] + "_en.default", "") for sLangLbl, dOptLbl in dVars['dOptLabel'].items(): hZip.writestr(f"dialog/{dVars['lang']}_{sLangLbl}.properties", createOptionsLabelProperties(dOptLbl)) ## ADDONS OXT print("+ OXT: ", end="") for spfSrc, spfDst in dOxt.items(): print(spfSrc, end=", ") if os.path.isdir(spLang+'/'+spfSrc): for sf in os.listdir(spLang+'/'+spfSrc): |
︙ | ︙ | |||
144 145 146 147 148 149 150 | if dVars.get('unopkg', False): cmd = '"'+os.path.abspath(dVars.get('unopkg')+'" add -f '+spfZip) print(cmd) os.system(cmd) else: print("# Error: path and filename of unopkg not set in config.ini") | < < < < < < < < < < < < < | | 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | if dVars.get('unopkg', False): cmd = '"'+os.path.abspath(dVars.get('unopkg')+'" add -f '+spfZip) print(cmd) os.system(cmd) else: print("# Error: path and filename of unopkg not set in config.ini") def createPackageZip (dVars, spLangPack): "create server zip" spfZip = f"_build/{dVars['name']}-{dVars['lang']}-v{dVars['version']}.zip" hZip = zipfile.ZipFile(spfZip, mode='w', compression=zipfile.ZIP_DEFLATED) copyGrammalectePyPackageInZipFile(hZip, spLangPack) for spf in ["grammalecte-cli.py", "grammalecte-server.py", \ "README.txt", "LICENSE.txt", "LICENSE.fr.txt"]: hZip.write(spf) hZip.writestr("setup.py", helpers.fileFile("gc_lang/fr/setup.py", dVars)) |
︙ | ︙ | |||
324 325 326 327 328 329 330 | dVars["dic_personal_filename_js"] = "" lDict = [ ("main", s) for s in dVars['dic_filenames'].split(",") ] if bCommunityDict: lDict.append(("community", dVars['dic_community_filename'])) if bPersonalDict: lDict.append(("personal", dVars['dic_personal_filename'])) for sType, sFileName in lDict: | | | | 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 | dVars["dic_personal_filename_js"] = "" lDict = [ ("main", s) for s in dVars['dic_filenames'].split(",") ] if bCommunityDict: lDict.append(("community", dVars['dic_community_filename'])) if bPersonalDict: lDict.append(("personal", dVars['dic_personal_filename'])) for sType, sFileName in lDict: spfPyDic = f"graphspell/_dictionaries/{sFileName}.bdic" spfJSDic = f"graphspell-js/_dictionaries/{sFileName}.json" if not os.path.isfile(spfPyDic) or (bJavaScript and not os.path.isfile(spfJSDic)): buildDictionary(dVars, sType, bJavaScript) print(spfPyDic) file_util.copy_file(spfPyDic, "grammalecte/graphspell/_dictionaries") dVars['dic_'+sType+'_filename_py'] = sFileName + '.bdic' if bJavaScript: print(spfJSDic) |
︙ | ︙ | |||
372 373 374 375 376 377 378 379 380 381 382 383 384 385 | print("Python: " + sys.version) if sys.version < "3.7": print("Python 3.7+ required") return xParser = argparse.ArgumentParser() xParser.add_argument("lang", type=str, nargs='+', help="lang project to generate (name of folder in /lang)") xParser.add_argument("-uc", "--use_cache", help="use data cache instead of rebuilding rules", action="store_true") xParser.add_argument("-b", "--build_data", help="launch build_data.py (part 1 and 2)", action="store_true") xParser.add_argument("-bb", "--build_data_before", help="launch build_data.py (only part 1: before dictionary building)", action="store_true") xParser.add_argument("-ba", "--build_data_after", help="launch build_data.py (only part 2: before dictionary building)", action="store_true") xParser.add_argument("-d", "--dict", help="generate FSA dictionary", action="store_true") xParser.add_argument("-t", "--tests", help="run unit tests", action="store_true") xParser.add_argument("-p", "--perf", help="run performance tests", action="store_true") xParser.add_argument("-pm", "--perf_memo", help="run performance tests and store results in perf_memo.txt", action="store_true") | > | 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 | print("Python: " + sys.version) if sys.version < "3.7": print("Python 3.7+ required") return xParser = argparse.ArgumentParser() xParser.add_argument("lang", type=str, nargs='+', help="lang project to generate (name of folder in /lang)") xParser.add_argument("-uc", "--use_cache", help="use data cache instead of rebuilding rules", action="store_true") xParser.add_argument("-frb", "--force_rebuild", help="force rebuilding rules", action="store_true") xParser.add_argument("-b", "--build_data", help="launch build_data.py (part 1 and 2)", action="store_true") xParser.add_argument("-bb", "--build_data_before", help="launch build_data.py (only part 1: before dictionary building)", action="store_true") xParser.add_argument("-ba", "--build_data_after", help="launch build_data.py (only part 2: before dictionary building)", action="store_true") xParser.add_argument("-d", "--dict", help="generate FSA dictionary", action="store_true") xParser.add_argument("-t", "--tests", help="run unit tests", action="store_true") xParser.add_argument("-p", "--perf", help="run performance tests", action="store_true") xParser.add_argument("-pm", "--perf_memo", help="run performance tests and store results in perf_memo.txt", action="store_true") |
︙ | ︙ | |||
434 435 436 437 438 439 440 | if databuild and xArgs.build_data_after: databuild.after('gc_lang/'+sLang, dVars, xArgs.javascript) # copy dictionaries from Graphspell copyGraphspellDictionaries(dVars, xArgs.javascript, xArgs.add_community_dictionary, xArgs.add_personal_dictionary) # make | > > > > > | | | 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 | if databuild and xArgs.build_data_after: databuild.after('gc_lang/'+sLang, dVars, xArgs.javascript) # copy dictionaries from Graphspell copyGraphspellDictionaries(dVars, xArgs.javascript, xArgs.add_community_dictionary, xArgs.add_personal_dictionary) # make bUseCache = None # we may rebuild if it’s necessary if xArgs.use_cache: bUseCache = True # we use the cache if it exists if xArgs.force_rebuild: bUseCache = False # we rebuild sVersion = create(sLang, xConfig, xArgs.install, xArgs.javascript, bUseCache) # tests if xArgs.tests or xArgs.perf or xArgs.perf_memo: print("> Running tests") try: tests = importlib.import_module("grammalecte."+sLang+".tests") print(tests.__file__) except ImportError: print(f"# Error. Import failed: grammalecte.{sLang}.tests") traceback.print_exc() else: if xArgs.tests: xTestSuite = unittest.TestLoader().loadTestsFromModule(tests) unittest.TextTestRunner().run(xTestSuite) if xArgs.perf or xArgs.perf_memo: hDst = open("./gc_lang/"+sLang+"/perf_memo.txt", "a", encoding="utf-8", newline="\n") if xArgs.perf_memo else None |
︙ | ︙ |