From dd983cfad880e3ea2e3963b9dac0cab49ffebd29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Freitas?= Date: Wed, 21 Aug 2024 16:36:46 +0100 Subject: [PATCH 1/5] Fix example configurations --- example/example.fcp | 18 ++++++++++-------- example/example.fpi | 17 ++++++++--------- example/iib.fcp | 8 +++++--- 3 files changed, 23 insertions(+), 20 deletions(-) diff --git a/example/example.fcp b/example/example.fcp index 05b31f01..8327485c 100644 --- a/example/example.fcp +++ b/example/example.fcp @@ -1,3 +1,5 @@ +version: "3" + import iib; /*this is a comment*/ @@ -5,22 +7,22 @@ enum master_state { OFF = 0; ON = 1; INVALID = 2; -} +}; enum master_state2 { OFF = 0; ON = 1; INVALID = 2; -} +}; /* this is a comment */ struct master_ts { /* this is a comment regarding master_ts_state */ - master_ts_state: u1 | unit("m/s"); - master_ts_off_reason: u7; -} + master_ts_state @ 0: u1 | unit("m/s"); + master_ts_off_reason @ 1: u7; +}; struct master_cell_error { - cell_id: u8; - cell_error: u16; -} + cell_id @ 0: u8; + cell_error @ 1: u16; +}; diff --git a/example/example.fpi b/example/example.fpi index fb0c4c3f..b90303b6 100644 --- a/example/example.fpi +++ b/example/example.fpi @@ -1,6 +1,6 @@ -device master { - id : 14; -} +version: "3" + +device master: id(14) {}; /*Sent by master and this is a comment*/ broadcast master_ts { @@ -10,8 +10,8 @@ broadcast master_ts { type: master_ts; signal master_ts_state { scale: 2.0; - } -} + }; +}; broadcast master_status { @@ -19,7 +19,7 @@ broadcast master_status { dlc : 8; device: master; type: master_ts; -} +}; broadcast master_cell_error{ id: 960; @@ -30,6 +30,5 @@ broadcast master_cell_error{ mux_count: 144; mux: cell_id; start: 48; - } -} - + }; +}; diff --git a/example/iib.fcp b/example/iib.fcp index 418ba256..276a71c1 100644 --- a/example/iib.fcp +++ b/example/iib.fcp @@ -1,4 +1,6 @@ +version: "3" + struct iib_status { - timestamp: u32; - status: u8; -} + timestamp @ 0: u32; + status @ 1: u8; +}; From b3f496d0deb6d3ff979a457d6179d74bfde22f00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Freitas?= Date: Wed, 21 Aug 2024 16:43:37 +0100 Subject: [PATCH 2/5] Avoid loading plugins that are not requested --- fcp/codegen.py | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/fcp/codegen.py b/fcp/codegen.py index fb4313c5..055129d2 100644 --- a/fcp/codegen.py +++ b/fcp/codegen.py @@ -25,9 +25,7 @@ def gen(self, fcp, templates, skels, output_path): self.output_path = pathlib.Path(output_path) - for path, content in self.generate( - fcp, self.output_path, templates, skels - ).items(): + for path, content in self.generate(fcp, templates, skels).items(): logging.info(f"Generating {path}") os.makedirs(path.parent, exist_ok=True) with open(path, "w", encoding="utf-8") as file: @@ -52,24 +50,22 @@ def __init__(self): def list_generators(self): """Find installed generators""" - return { - name: importlib.import_module(name) - for finder, name, ispkg in pkgutil.iter_modules() - if name.startswith("fcp_") - } + return [ + name for _, name, _ in pkgutil.iter_modules() if name.startswith("fcp_") + ] def get_generator(self, generator_name): """Get generator by name.""" generators = self.list_generators() - if "fcp_" + generator_name not in generators.keys(): - available_generators = [name[4:] for name in generators.keys()] + if "fcp_" + generator_name not in generators: + available_generators = [name[4:] for name in generators] logging.error("Code generator %s not available", generator_name) logging.info( "Currently available code generators: %s", available_generators ) sys.exit(1) - return generators["fcp_" + generator_name] + return importlib.import_module("fcp_" + generator_name) def get_templates(self, template_dir): if template_dir is None: From c42c860028efd832fcf8b27fb27a3f2ee131bed7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Freitas?= Date: Wed, 21 Aug 2024 16:43:54 +0100 Subject: [PATCH 3/5] Create no op plugin --- plugins/fcp_nop/fcp_nop/__init__.py | 1 + plugins/fcp_nop/fcp_nop/generator.py | 15 +++++++++++++++ plugins/fcp_nop/setup.py | 15 +++++++++++++++ 3 files changed, 31 insertions(+) create mode 100644 plugins/fcp_nop/fcp_nop/__init__.py create mode 100644 plugins/fcp_nop/fcp_nop/generator.py create mode 100644 plugins/fcp_nop/setup.py diff --git a/plugins/fcp_nop/fcp_nop/__init__.py b/plugins/fcp_nop/fcp_nop/__init__.py new file mode 100644 index 00000000..5a371e07 --- /dev/null +++ b/plugins/fcp_nop/fcp_nop/__init__.py @@ -0,0 +1 @@ +from .generator import Generator, Verifier diff --git a/plugins/fcp_nop/fcp_nop/generator.py b/plugins/fcp_nop/fcp_nop/generator.py new file mode 100644 index 00000000..50ef30c9 --- /dev/null +++ b/plugins/fcp_nop/fcp_nop/generator.py @@ -0,0 +1,15 @@ +from fcp.codegen import CodeGenerator +from fcp.verifier import BaseVerifier, simple_error + + +class Verifier(BaseVerifier): + pass + + +class Generator(CodeGenerator): + def __init__(self): + pass + + def generate(self, fcp, templates={}, skels={}): + print(fcp) + return {} diff --git a/plugins/fcp_nop/setup.py b/plugins/fcp_nop/setup.py new file mode 100644 index 00000000..5f4505b9 --- /dev/null +++ b/plugins/fcp_nop/setup.py @@ -0,0 +1,15 @@ +from setuptools import setup, find_packages + +setup( + name="fcp_nop", + description="", + version="0.1", + author="Joao Freitas", + author_email="joaj.freitas@gmail.com", + license="GPLv3", + url="https://gitlab.com/joajfreitas/fcp-cgen", + packages=find_packages(), + install_requires=["fcp"], + long_description="", + long_description_content_type="text/markdown", +) From 8943259bd242fbe72c1499867833625d54d24488 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Freitas?= Date: Wed, 21 Aug 2024 16:44:03 +0100 Subject: [PATCH 4/5] Disable pylint --- hooks/pre-commit | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hooks/pre-commit b/hooks/pre-commit index 64b090a2..741fcb7c 100755 --- a/hooks/pre-commit +++ b/hooks/pre-commit @@ -3,4 +3,4 @@ set -e hooks/check_release_notes hooks/black -hoos/pylint +#hooks/pylint From a025f15cc35a2d3a9afd56c807c63f1ad46cfedb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Freitas?= Date: Wed, 21 Aug 2024 17:54:02 +0100 Subject: [PATCH 5/5] Create pyproject.toml --- fcp/version.py | 1 - {src => fcp_c_src}/Makefile | 0 {src => fcp_c_src}/a.out | Bin {src => fcp_c_src}/candata.h | 0 {src => fcp_c_src}/minunit.h | 0 {src => fcp_c_src}/signal_parser.c | 0 {src => fcp_c_src}/signal_parser.h | 0 {src => fcp_c_src}/signal_parser_test.c | 0 hooks/check_release_notes | 2 +- pyproject.toml | 22 ++++++++++++++++++++++ {fcp => src/fcp}/__init__.py | 0 {fcp => src/fcp}/__main__.py | 0 {fcp => src/fcp}/codegen.py | 0 {fcp => src/fcp}/result.py | 0 {fcp => src/fcp}/specs/__init__.py | 0 {fcp => src/fcp}/specs/arg.py | 0 {fcp => src/fcp}/specs/broadcast.py | 0 {fcp => src/fcp}/specs/cmd.py | 0 {fcp => src/fcp}/specs/comment.py | 0 {fcp => src/fcp}/specs/config.py | 0 {fcp => src/fcp}/specs/device.py | 0 {fcp => src/fcp}/specs/enum.py | 0 {fcp => src/fcp}/specs/log.py | 0 {fcp => src/fcp}/specs/metadata.py | 0 {fcp => src/fcp}/specs/serde_extend.py | 0 {fcp => src/fcp}/specs/signal.py | 0 {fcp => src/fcp}/specs/struct.py | 0 {fcp => src/fcp}/specs/v1.py | 0 {fcp => src/fcp}/specs/v2.py | 0 {fcp => src/fcp}/tests/__init__.py | 0 {fcp => src/fcp}/tests/test_v2.py | 0 {fcp => src/fcp}/v2_parser.py | 0 {fcp => src/fcp}/verifier.py | 0 src/fcp/version.py | 1 + {fcp => src/fcp}/writers.py | 0 35 files changed, 24 insertions(+), 2 deletions(-) delete mode 100644 fcp/version.py rename {src => fcp_c_src}/Makefile (100%) rename {src => fcp_c_src}/a.out (100%) rename {src => fcp_c_src}/candata.h (100%) rename {src => fcp_c_src}/minunit.h (100%) rename {src => fcp_c_src}/signal_parser.c (100%) rename {src => fcp_c_src}/signal_parser.h (100%) rename {src => fcp_c_src}/signal_parser_test.c (100%) create mode 100644 pyproject.toml rename {fcp => src/fcp}/__init__.py (100%) rename {fcp => src/fcp}/__main__.py (100%) rename {fcp => src/fcp}/codegen.py (100%) rename {fcp => src/fcp}/result.py (100%) rename {fcp => src/fcp}/specs/__init__.py (100%) rename {fcp => src/fcp}/specs/arg.py (100%) rename {fcp => src/fcp}/specs/broadcast.py (100%) rename {fcp => src/fcp}/specs/cmd.py (100%) rename {fcp => src/fcp}/specs/comment.py (100%) rename {fcp => src/fcp}/specs/config.py (100%) rename {fcp => src/fcp}/specs/device.py (100%) rename {fcp => src/fcp}/specs/enum.py (100%) rename {fcp => src/fcp}/specs/log.py (100%) rename {fcp => src/fcp}/specs/metadata.py (100%) rename {fcp => src/fcp}/specs/serde_extend.py (100%) rename {fcp => src/fcp}/specs/signal.py (100%) rename {fcp => src/fcp}/specs/struct.py (100%) rename {fcp => src/fcp}/specs/v1.py (100%) rename {fcp => src/fcp}/specs/v2.py (100%) rename {fcp => src/fcp}/tests/__init__.py (100%) rename {fcp => src/fcp}/tests/test_v2.py (100%) rename {fcp => src/fcp}/v2_parser.py (100%) rename {fcp => src/fcp}/verifier.py (100%) create mode 100644 src/fcp/version.py rename {fcp => src/fcp}/writers.py (100%) diff --git a/fcp/version.py b/fcp/version.py deleted file mode 100644 index 8d50a59e..00000000 --- a/fcp/version.py +++ /dev/null @@ -1 +0,0 @@ -VERSION = "1.00.0" diff --git a/src/Makefile b/fcp_c_src/Makefile similarity index 100% rename from src/Makefile rename to fcp_c_src/Makefile diff --git a/src/a.out b/fcp_c_src/a.out similarity index 100% rename from src/a.out rename to fcp_c_src/a.out diff --git a/src/candata.h b/fcp_c_src/candata.h similarity index 100% rename from src/candata.h rename to fcp_c_src/candata.h diff --git a/src/minunit.h b/fcp_c_src/minunit.h similarity index 100% rename from src/minunit.h rename to fcp_c_src/minunit.h diff --git a/src/signal_parser.c b/fcp_c_src/signal_parser.c similarity index 100% rename from src/signal_parser.c rename to fcp_c_src/signal_parser.c diff --git a/src/signal_parser.h b/fcp_c_src/signal_parser.h similarity index 100% rename from src/signal_parser.h rename to fcp_c_src/signal_parser.h diff --git a/src/signal_parser_test.c b/fcp_c_src/signal_parser_test.c similarity index 100% rename from src/signal_parser_test.c rename to fcp_c_src/signal_parser_test.c diff --git a/hooks/check_release_notes b/hooks/check_release_notes index 21a8fb0a..ebb0094f 100755 --- a/hooks/check_release_notes +++ b/hooks/check_release_notes @@ -4,7 +4,7 @@ import sys import os def main(args): - with open("fcp/version.py") as f: + with open("src/fcp/version.py") as f: txt = f.read() version = txt.split("=")[1].strip() version = "v"+version[1:-1]+".md" diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..ed93aca6 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,22 @@ +[project] +name = "fcp" +version = "1.0.0" +description = "CAN bus manager" +license = {file = "LICENSE.txt"} +readme = "README.md" +url = "https://github.com/joajfreitas/fcp-core" +requires-python = ">=3.12" +dependencies = [ + "click", + "lark", + "coloredlogs", + "serde", + "termcolor" +] + +[build-system] +requires = ["hatchling"] +build-backend = "hatchling.build" + +[project.scripts] +fcp = "fcp.__main__:main" diff --git a/fcp/__init__.py b/src/fcp/__init__.py similarity index 100% rename from fcp/__init__.py rename to src/fcp/__init__.py diff --git a/fcp/__main__.py b/src/fcp/__main__.py similarity index 100% rename from fcp/__main__.py rename to src/fcp/__main__.py diff --git a/fcp/codegen.py b/src/fcp/codegen.py similarity index 100% rename from fcp/codegen.py rename to src/fcp/codegen.py diff --git a/fcp/result.py b/src/fcp/result.py similarity index 100% rename from fcp/result.py rename to src/fcp/result.py diff --git a/fcp/specs/__init__.py b/src/fcp/specs/__init__.py similarity index 100% rename from fcp/specs/__init__.py rename to src/fcp/specs/__init__.py diff --git a/fcp/specs/arg.py b/src/fcp/specs/arg.py similarity index 100% rename from fcp/specs/arg.py rename to src/fcp/specs/arg.py diff --git a/fcp/specs/broadcast.py b/src/fcp/specs/broadcast.py similarity index 100% rename from fcp/specs/broadcast.py rename to src/fcp/specs/broadcast.py diff --git a/fcp/specs/cmd.py b/src/fcp/specs/cmd.py similarity index 100% rename from fcp/specs/cmd.py rename to src/fcp/specs/cmd.py diff --git a/fcp/specs/comment.py b/src/fcp/specs/comment.py similarity index 100% rename from fcp/specs/comment.py rename to src/fcp/specs/comment.py diff --git a/fcp/specs/config.py b/src/fcp/specs/config.py similarity index 100% rename from fcp/specs/config.py rename to src/fcp/specs/config.py diff --git a/fcp/specs/device.py b/src/fcp/specs/device.py similarity index 100% rename from fcp/specs/device.py rename to src/fcp/specs/device.py diff --git a/fcp/specs/enum.py b/src/fcp/specs/enum.py similarity index 100% rename from fcp/specs/enum.py rename to src/fcp/specs/enum.py diff --git a/fcp/specs/log.py b/src/fcp/specs/log.py similarity index 100% rename from fcp/specs/log.py rename to src/fcp/specs/log.py diff --git a/fcp/specs/metadata.py b/src/fcp/specs/metadata.py similarity index 100% rename from fcp/specs/metadata.py rename to src/fcp/specs/metadata.py diff --git a/fcp/specs/serde_extend.py b/src/fcp/specs/serde_extend.py similarity index 100% rename from fcp/specs/serde_extend.py rename to src/fcp/specs/serde_extend.py diff --git a/fcp/specs/signal.py b/src/fcp/specs/signal.py similarity index 100% rename from fcp/specs/signal.py rename to src/fcp/specs/signal.py diff --git a/fcp/specs/struct.py b/src/fcp/specs/struct.py similarity index 100% rename from fcp/specs/struct.py rename to src/fcp/specs/struct.py diff --git a/fcp/specs/v1.py b/src/fcp/specs/v1.py similarity index 100% rename from fcp/specs/v1.py rename to src/fcp/specs/v1.py diff --git a/fcp/specs/v2.py b/src/fcp/specs/v2.py similarity index 100% rename from fcp/specs/v2.py rename to src/fcp/specs/v2.py diff --git a/fcp/tests/__init__.py b/src/fcp/tests/__init__.py similarity index 100% rename from fcp/tests/__init__.py rename to src/fcp/tests/__init__.py diff --git a/fcp/tests/test_v2.py b/src/fcp/tests/test_v2.py similarity index 100% rename from fcp/tests/test_v2.py rename to src/fcp/tests/test_v2.py diff --git a/fcp/v2_parser.py b/src/fcp/v2_parser.py similarity index 100% rename from fcp/v2_parser.py rename to src/fcp/v2_parser.py diff --git a/fcp/verifier.py b/src/fcp/verifier.py similarity index 100% rename from fcp/verifier.py rename to src/fcp/verifier.py diff --git a/src/fcp/version.py b/src/fcp/version.py new file mode 100644 index 00000000..3277f64c --- /dev/null +++ b/src/fcp/version.py @@ -0,0 +1 @@ +VERSION = "1.0.0" diff --git a/fcp/writers.py b/src/fcp/writers.py similarity index 100% rename from fcp/writers.py rename to src/fcp/writers.py