From 2bc984ba09db16506c564e438f08a7eb60de1896 Mon Sep 17 00:00:00 2001 From: DeltaDaniel <139119540+DeltaDaniel@users.noreply.github.com> Date: Thu, 7 Nov 2024 17:00:59 +0100 Subject: [PATCH 1/9] output json for ebd section with no table --- src/ebd_toolchain/main.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/ebd_toolchain/main.py b/src/ebd_toolchain/main.py index 7979af4..e577c3e 100644 --- a/src/ebd_toolchain/main.py +++ b/src/ebd_toolchain/main.py @@ -80,7 +80,7 @@ def _dump_svg(svg_path: Path, ebd_graph: EbdGraph, converter: DotToSvgConverter) svg_file.write(svg_code) -def _dump_json(json_path: Path, ebd_table: EbdTable) -> None: +def _dump_json(json_path: Path, ebd_table: EbdTable | EbdNoTableSection) -> None: with open(json_path, "w+", encoding="utf-8") as json_file: json.dump(cattrs.unstructure(ebd_table), json_file, ensure_ascii=False, indent=2, sort_keys=True) @@ -144,8 +144,19 @@ def handle_known_error(error: Exception, ebd_key: str) -> None: continue assert ebd_kapitel is not None if isinstance(docx_tables, EbdNoTableSection): - _logger.warning("The EBD has no table: %s", ebd_key) - continue + if "json" in export_types: + ebd_meta_data = EbdTableMetaData( + ebd_code=ebd_key, + ebd_name=ebd_kapitel.section_title, + chapter=ebd_kapitel.chapter_title, # type:ignore[arg-type] + # pylint:disable=line-too-long + section=f"{ebd_kapitel.chapter}.{ebd_kapitel.section}.{ebd_kapitel.subsection}: {ebd_kapitel.section_title}", + role="N/A", + remark=docx_tables.remark, + ) + json_path = output_path / Path(f"{ebd_key}.json") + _dump_json(json_path, ebd_meta_data) + click.secho(f"💾 Successfully exported '{ebd_key}.json' to {json_path.absolute()}") try: converter = DocxTableConverter( docx_tables, From 05223bd177aa20a3a37c92ad9ce800fd8c90aba8 Mon Sep 17 00:00:00 2001 From: Konstantin Date: Thu, 7 Nov 2024 17:07:13 +0100 Subject: [PATCH 2/9] fix import error --- src/ebd_toolchain/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ebd_toolchain/main.py b/src/ebd_toolchain/main.py index e577c3e..bcae792 100644 --- a/src/ebd_toolchain/main.py +++ b/src/ebd_toolchain/main.py @@ -38,7 +38,7 @@ from rebdhuhn.graphviz import convert_dot_to_svg_kroki, convert_graph_to_dot from rebdhuhn.kroki import DotToSvgConverter, Kroki, KrokiDotBadRequestError, KrokiPlantUmlBadRequestError from rebdhuhn.models.ebd_graph import EbdGraph -from rebdhuhn.models.ebd_table import EbdTable +from rebdhuhn.models.ebd_table import EbdTable, EbdTableMetaData from rebdhuhn.models.errors import ( EbdCrossReferenceNotSupportedError, EndeInWrongColumnError, From ba12382339ca82eb5b0ee41a2cd8be5f11a6574e Mon Sep 17 00:00:00 2001 From: DeltaDaniel <139119540+DeltaDaniel@users.noreply.github.com> Date: Thu, 7 Nov 2024 17:07:30 +0100 Subject: [PATCH 3/9] linter --- src/ebd_toolchain/main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ebd_toolchain/main.py b/src/ebd_toolchain/main.py index e577c3e..686798f 100644 --- a/src/ebd_toolchain/main.py +++ b/src/ebd_toolchain/main.py @@ -38,7 +38,7 @@ from rebdhuhn.graphviz import convert_dot_to_svg_kroki, convert_graph_to_dot from rebdhuhn.kroki import DotToSvgConverter, Kroki, KrokiDotBadRequestError, KrokiPlantUmlBadRequestError from rebdhuhn.models.ebd_graph import EbdGraph -from rebdhuhn.models.ebd_table import EbdTable +from rebdhuhn.models.ebd_table import EbdTable, EbdTableMetaData from rebdhuhn.models.errors import ( EbdCrossReferenceNotSupportedError, EndeInWrongColumnError, @@ -80,7 +80,7 @@ def _dump_svg(svg_path: Path, ebd_graph: EbdGraph, converter: DotToSvgConverter) svg_file.write(svg_code) -def _dump_json(json_path: Path, ebd_table: EbdTable | EbdNoTableSection) -> None: +def _dump_json(json_path: Path, ebd_table: EbdTable | EbdTableMetaData) -> None: with open(json_path, "w+", encoding="utf-8") as json_file: json.dump(cattrs.unstructure(ebd_table), json_file, ensure_ascii=False, indent=2, sort_keys=True) From 86da6a21ccf1b89dd90bf76619137ccf4acd63cb Mon Sep 17 00:00:00 2001 From: Konstantin Date: Thu, 7 Nov 2024 17:10:02 +0100 Subject: [PATCH 4/9] like this? --- src/ebd_toolchain/main.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/ebd_toolchain/main.py b/src/ebd_toolchain/main.py index bcae792..6c7d980 100644 --- a/src/ebd_toolchain/main.py +++ b/src/ebd_toolchain/main.py @@ -80,9 +80,19 @@ def _dump_svg(svg_path: Path, ebd_graph: EbdGraph, converter: DotToSvgConverter) svg_file.write(svg_code) -def _dump_json(json_path: Path, ebd_table: EbdTable | EbdNoTableSection) -> None: +def _dump_json(json_path: Path, ebd_table: EbdTable | EbdNoTableSection | EbdTableMetaData) -> None: with open(json_path, "w+", encoding="utf-8") as json_file: json.dump(cattrs.unstructure(ebd_table), json_file, ensure_ascii=False, indent=2, sort_keys=True) + if isinstance(ebd_table, EbdTableMetaData): + json.dump( + cattrs.unstructure(EbdTable(metadata=ebd_table, rows=[])), + json_file, + ensure_ascii=False, + indent=2, + sort_keys=True, + ) + else: + json.dump(cattrs.unstructure(ebd_table), json_file, ensure_ascii=False, indent=2, sort_keys=True) @click.command() From dec618d7ef87dc05594a9c1e045f2d56e30bab2c Mon Sep 17 00:00:00 2001 From: DeltaDaniel <139119540+DeltaDaniel@users.noreply.github.com> Date: Thu, 7 Nov 2024 17:11:10 +0100 Subject: [PATCH 5/9] WIP --- src/ebd_toolchain/main.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ebd_toolchain/main.py b/src/ebd_toolchain/main.py index 686798f..b9419a7 100644 --- a/src/ebd_toolchain/main.py +++ b/src/ebd_toolchain/main.py @@ -147,7 +147,7 @@ def handle_known_error(error: Exception, ebd_key: str) -> None: if "json" in export_types: ebd_meta_data = EbdTableMetaData( ebd_code=ebd_key, - ebd_name=ebd_kapitel.section_title, + ebd_name=f"{ebd_kapitel.subsection_title}", chapter=ebd_kapitel.chapter_title, # type:ignore[arg-type] # pylint:disable=line-too-long section=f"{ebd_kapitel.chapter}.{ebd_kapitel.section}.{ebd_kapitel.subsection}: {ebd_kapitel.section_title}", @@ -158,6 +158,7 @@ def handle_known_error(error: Exception, ebd_key: str) -> None: _dump_json(json_path, ebd_meta_data) click.secho(f"💾 Successfully exported '{ebd_key}.json' to {json_path.absolute()}") try: + assert not isinstance(docx_tables, EbdNoTableSection) converter = DocxTableConverter( docx_tables, ebd_key=ebd_key, From 55b3c0f41ce164c6c5a606ca57f636c4e29245aa Mon Sep 17 00:00:00 2001 From: DeltaDaniel <139119540+DeltaDaniel@users.noreply.github.com> Date: Thu, 7 Nov 2024 17:15:12 +0100 Subject: [PATCH 6/9] linting --- src/ebd_toolchain/main.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ebd_toolchain/main.py b/src/ebd_toolchain/main.py index a9bded8..1dbc2d1 100644 --- a/src/ebd_toolchain/main.py +++ b/src/ebd_toolchain/main.py @@ -153,6 +153,7 @@ def handle_known_error(error: Exception, ebd_key: str) -> None: click.secho(f"Table not found: {ebd_key}: {str(table_not_found_error)}; Skip!", fg="yellow") continue assert ebd_kapitel is not None + assert ebd_kapitel.subsection_title is not None if isinstance(docx_tables, EbdNoTableSection): if "json" in export_types: ebd_meta_data = EbdTableMetaData( From 022e4e007119ace1c7c1fb66e39df6ad40c531b6 Mon Sep 17 00:00:00 2001 From: DeltaDaniel <139119540+DeltaDaniel@users.noreply.github.com> Date: Thu, 7 Nov 2024 17:19:58 +0100 Subject: [PATCH 7/9] bump rebdhuhn 0.5.2 -> 0.5.3 --- pyproject.toml | 2 +- requirements.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 69251d2..5bf6e57 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -18,7 +18,7 @@ classifiers = [ ] dependencies = [ "ebdamame>=0.1.3", - "rebdhuhn>=0.5.2", + "rebdhuhn>=0.5.3", "cattrs", "click", "pydantic-settings" diff --git a/requirements.txt b/requirements.txt index c99e06e..0dd3399 100644 --- a/requirements.txt +++ b/requirements.txt @@ -48,7 +48,7 @@ python-docx==1.1.2 # via ebdamame python-dotenv==1.0.1 # via pydantic-settings -rebdhuhn==0.5.2 +rebdhuhn==0.5.3 # via # ebd-toolchain (pyproject.toml) # ebdamame From 05c4a86161c055d3ae048a14e77a54bc93ed00c1 Mon Sep 17 00:00:00 2001 From: Daniel <139119540+DeltaDaniel@users.noreply.github.com> Date: Thu, 7 Nov 2024 17:29:18 +0100 Subject: [PATCH 8/9] Update src/ebd_toolchain/main.py Co-authored-by: konstantin --- src/ebd_toolchain/main.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ebd_toolchain/main.py b/src/ebd_toolchain/main.py index 1dbc2d1..2f76377 100644 --- a/src/ebd_toolchain/main.py +++ b/src/ebd_toolchain/main.py @@ -168,6 +168,7 @@ def handle_known_error(error: Exception, ebd_key: str) -> None: json_path = output_path / Path(f"{ebd_key}.json") _dump_json(json_path, ebd_meta_data) click.secho(f"💾 Successfully exported '{ebd_key}.json' to {json_path.absolute()}") + continue; try: assert not isinstance(docx_tables, EbdNoTableSection) converter = DocxTableConverter( From 7316c556e365991b1dfaa550804190f469f9e071 Mon Sep 17 00:00:00 2001 From: DeltaDaniel <139119540+DeltaDaniel@users.noreply.github.com> Date: Thu, 7 Nov 2024 17:30:17 +0100 Subject: [PATCH 9/9] typo --- src/ebd_toolchain/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ebd_toolchain/main.py b/src/ebd_toolchain/main.py index 2f76377..18f5e0a 100644 --- a/src/ebd_toolchain/main.py +++ b/src/ebd_toolchain/main.py @@ -168,7 +168,7 @@ def handle_known_error(error: Exception, ebd_key: str) -> None: json_path = output_path / Path(f"{ebd_key}.json") _dump_json(json_path, ebd_meta_data) click.secho(f"💾 Successfully exported '{ebd_key}.json' to {json_path.absolute()}") - continue; + continue try: assert not isinstance(docx_tables, EbdNoTableSection) converter = DocxTableConverter(