diff --git a/CHANGES.md b/CHANGES.md index 1a26791..0ff9db2 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,6 +1,8 @@ # Changelog ## Unreleased +- Build Script: Replace version instead of appending to the index file. + ## 2024/05/21 v0.0.2 - Initial release diff --git a/cratedb_sqlparse_js/cratedb_sqlparse/index.js b/cratedb_sqlparse_js/cratedb_sqlparse/index.js index 344bb4a..692a1f4 100644 --- a/cratedb_sqlparse_js/cratedb_sqlparse/index.js +++ b/cratedb_sqlparse_js/cratedb_sqlparse/index.js @@ -1,2 +1,3 @@ import {sqlparse} from "./parser.js"; export {sqlparse}; +export const __cratedb_version__ = "5.6.4" diff --git a/cratedb_sqlparse_py/cratedb_sqlparse/__init__.py b/cratedb_sqlparse_py/cratedb_sqlparse/__init__.py index c9b943b..6146498 100644 --- a/cratedb_sqlparse_py/cratedb_sqlparse/__init__.py +++ b/cratedb_sqlparse_py/cratedb_sqlparse/__init__.py @@ -1,3 +1,5 @@ from .parser import ParsingException, sqlparse __all__ = ["sqlparse", "ParsingException"] + +__cratedb_version__ = "5.6.4" diff --git a/setup_grammar.py b/setup_grammar.py index c834f8c..3ed23eb 100644 --- a/setup_grammar.py +++ b/setup_grammar.py @@ -2,6 +2,7 @@ import logging import subprocess import sys +import re from enum import Enum from pathlib import Path @@ -137,9 +138,18 @@ def set_version(target: Antlr4Target, version: str): index_file = 'index.js' variable = 'export const __cratedb_version__' - # FIXME: Need to apply "replace" instead of "append"? - with open(target_path / index_file, "a") as f: - f.write(f"{variable} = {version}\n") + with open(target_path / index_file, "r+") as f: + content = f.read() + + # Removes the current content on disk. + f.seek(0) + f.truncate() + + updated_content = re.sub(f'({variable} = )"(.*)"', r'\1' + version, content) + + f.write(updated_content) + + logger.info(f'Updated {variable} to {version} in {index_file}') if __name__ == '__main__': @@ -150,14 +160,17 @@ def set_version(target: Antlr4Target, version: str): TODO: Improve efficiency by generating runtime parser for all implemented languages at once. """ setup_logging() + input_target = sys.argv[1] version = '5.6.4' + if input_target.startswith("py"): target = Antlr4Target.python elif input_target.startswith("js") or input_target.startswith("java"): target = Antlr4Target.js else: raise NotImplementedError(f"Parser generator for target {input_target} not implemented") + download_cratedb_grammar(version) compile_grammar(target) patch_lexer(target)