Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace the version on the target index_files rather instead of appending #23

Merged
merged 1 commit into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions cratedb_sqlparse_js/cratedb_sqlparse/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
import {sqlparse} from "./parser.js";
export {sqlparse};
export const __cratedb_version__ = "5.6.4"
2 changes: 2 additions & 0 deletions cratedb_sqlparse_py/cratedb_sqlparse/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from .parser import ParsingException, sqlparse

__all__ = ["sqlparse", "ParsingException"]

__cratedb_version__ = "5.6.4"
19 changes: 16 additions & 3 deletions setup_grammar.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import logging
import subprocess
import sys
import re
from enum import Enum
from pathlib import Path

Expand Down Expand Up @@ -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__':
Expand All @@ -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)
Expand Down