Skip to content

Commit

Permalink
Use lastest ANTLR4 version
Browse files Browse the repository at this point in the history
  • Loading branch information
christoph2 committed Oct 22, 2024
1 parent 5f97901 commit 9f574e7
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ cmake_policy(SET CMP0094 NEW)
find_package(Python3 COMPONENTS Interpreter Development)
find_package(pybind11 REQUIRED)

set(ANTLR4_TAG 4.13.2)

# set(ANTLR4_TAG 4.13.2)
set(ANTLR4_TAG $ENV{ANTLR4_TAG})

message("ANTLR4-TAG: " ${ANTLR4_TAG})

SET(CMAKE_C_STANDARD 17)
set(CMAKE_CXX_STANDARD 23)
Expand Down
19 changes: 11 additions & 8 deletions build_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import sysconfig
from pathlib import Path
from tempfile import TemporaryDirectory
from typing import List, Optional, Tuple
from typing import List, Optional, Tuple # noqa: UP035


TOP_DIR = Path(__file__).parent
Expand All @@ -26,9 +26,9 @@

def get_python_base() -> str:
# Applies in this form only to Windows.
if "base" in VARS and VARS["base"]:
if "base" in VARS and VARS["base"]: # noqa: RUF019
return VARS["base"]
if "installed_base" in VARS and VARS["installed_base"]:
if "installed_base" in VARS and VARS["installed_base"]: # noqa: RUF019
return VARS["installed_base"]


Expand Down Expand Up @@ -89,14 +89,14 @@ def get_py_config() -> dict:
return dict(exe=sys.executable, include=include, libdir=libdir, library=library)


def sort_by_version(version: str) -> Tuple[int]:
def sort_by_version(version: str) -> Tuple[int]: # noqa: UP006
h, m, s = version.split(".")
return int(h), int(m), int(s)


def fetch_tags(repo: str) -> List[str]:
def fetch_tags(repo: str) -> List[str]: # noqa: UP006
res = subprocess.run(["git", "ls-remote", "--tags", repo], shell=False, capture_output=True, text=True) # nosec
if res.returncode == 0:
if res.returncode != 0:
return []
tag_set = set()
for tag in res.stdout.splitlines():
Expand All @@ -120,6 +120,9 @@ def banner(msg: str) -> None:
def build_extension(debug: bool = False, use_temp_dir=False) -> None:
print("build_ext::build_extension()")

antlr4_tag = most_recent_tag("https://github.com/antlr/antlr4")
print("antlr4_tag", antlr4_tag)
os.environ["ANTLR4_TAG"] = antlr4_tag
debug = int(os.environ.get("DEBUG", 0)) or debug
cfg = "Debug" if debug else "Release"

Expand All @@ -135,8 +138,8 @@ def build_extension(debug: bool = False, use_temp_dir=False) -> None:
]
)
if py_cfg["libdir"]:
cmake_args.append(f"-DPython3_LIBRARY={str(Path(py_cfg['libdir']) / Path(py_cfg['library']))}")
build_args = ["--config Release", "--verbose"]
cmake_args.append(f"-DPython3_LIBRARY={str(Path(py_cfg['libdir']) / Path(py_cfg['library']))}") # noqa: RUF010
build_args = ["--config Release", "--verbose"] # f"-DANTLR4_TAG={antlr4_tag}"

if sys.platform.startswith("darwin"):
# Cross-compile support for macOS - respect ARCHFLAGS if set
Expand Down
9 changes: 7 additions & 2 deletions pya2l/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ class InvalidA2LDatabase(Exception):
class DB:
""""""

def __init__(self, loglevel="INFO") -> None:
self.loglevel = loglevel
self.logger = Logger(self.__class__.__name__, loglevel)

A2L_TEMPLATE = pkgutil.get_data("pya2l.cgen.templates", "a2l.tmpl")

def import_a2l(
Expand Down Expand Up @@ -115,7 +119,6 @@ def import_a2l(
from pya2l.preprocessor import Preprocessor

start_time = perf_counter()
self.logger = Logger(self.__class__.__name__, loglevel)
self.in_memory = in_memory

self._set_path_components(file_name, local)
Expand All @@ -127,7 +130,9 @@ def import_a2l(
pass # nosec
elif self._dbfn.exists():
raise OSError(f"file '{self._dbfn}' already exists.") # Use 'open_create()' or 'open_existing()'.--

if hasattr(self, "db"):
print("CLOSE db")
self.db.close()
print("Enter pre-processor...")

prepro = Preprocessor(loglevel=loglevel)
Expand Down

0 comments on commit 9f574e7

Please sign in to comment.