Skip to content
This repository was archived by the owner on Feb 3, 2025. It is now read-only.
Draft
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: 1 addition & 1 deletion dev_requirements/requirements-linting.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ platformdirs==4.2.2
# via pylint
pylint==3.2.6
# via -r dev_requirements/requirements-linting.in
tomlkit==0.12.5
tomlkit==0.13.2
# via pylint
3 changes: 1 addition & 2 deletions json_schemas/generate_json_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
import pathlib
from typing import List, Type

from kohlrahbi.models.anwendungshandbuch import DeepAnwendungshandbuchSchema
from marshmallow import Schema
from marshmallow_jsonschema import JSONSchema # type:ignore[import]

from maus.models.anwendungshandbuch import DeepAnwendungshandbuchSchema

schema_types: List[Type[Schema]] = [
DeepAnwendungshandbuchSchema
# add other schemas as you like
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ dependencies = [
"attrs>=22.1.0",
"marshmallow>=3.18.0",
"more_itertools",
"efoli>=0.0.3"
"efoli>=0.0.3",
"kohlrahbi>=1.6.0"
# add everything you add in requirements.in here
]
dynamic = ["readme", "version"]
Expand Down
1 change: 1 addition & 0 deletions requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ xmltodict
click
lark
efoli>=0.0.3
kohlrahbi>=1.6.0
# whenever adding something here, don't forget to also add it to pyproject.toml dependencies
68 changes: 55 additions & 13 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,67 @@
# This file is autogenerated by pip-compile with Python 3.11
# by the following command:
#
# pip-compile requirements.in
# pip-compile pyproject.toml
#
annotated-types==0.7.0
# via pydantic
attrs==23.2.0
# via -r requirements.in
# via maus (pyproject.toml)
click==8.1.7
# via -r requirements.in
# via kohlrahbi
colorama==0.4.6
# via
# click
# colorlog
colorlog==6.8.2
# via kohlrahbi
efoli==1.1.0
# via -r requirements.in
lark==1.2.2
# via -r requirements.in
# via
# kohlrahbi
# maus (pyproject.toml)
et-xmlfile==1.1.0
# via openpyxl
kohlrahbi==1.6.0
# via maus (pyproject.toml)
lxml==5.3.0
# via -r requirements.in
# via python-docx
marshmallow==3.21.3
# via -r requirements.in
more-itertools==10.3.0
# via -r requirements.in
# via maus (pyproject.toml)
more-itertools==10.4.0
# via
# kohlrahbi
# maus (pyproject.toml)
numpy==2.1.0
# via pandas
openpyxl==3.1.5
# via kohlrahbi
packaging==24.0
# via marshmallow
pandas==2.2.2
# via kohlrahbi
pydantic==2.8.2
# via kohlrahbi
pydantic-core==2.20.1
# via pydantic
python-dateutil==2.9.0.post0
# via pandas
python-docx==1.1.2
# via kohlrahbi
pytz==2024.1
# via efoli
xmltodict==0.13.0
# via -r requirements.in
# via
# efoli
# kohlrahbi
# pandas
six==1.16.0
# via python-dateutil
tomlkit==0.13.2
# via kohlrahbi
typing-extensions==4.12.2
# via
# pydantic
# pydantic-core
# python-docx
tzdata==2024.1
# via pandas
xlsxwriter==3.2.0
# via kohlrahbi
13 changes: 5 additions & 8 deletions src/maus/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,9 @@
# click is only an optional dependency when maus is used as CLI tool
raise

from kohlrahbi.models.anwendungshandbuch import DeepAnwendungshandbuch, FlatAnwendungshandbuch

from maus.mig_ahb_matching import to_deep_ahb
from maus.models.anwendungshandbuch import (
DeepAnwendungshandbuch,
DeepAnwendungshandbuchSchema,
FlatAnwendungshandbuchSchema,
)
from maus.models.message_implementation_guide import SegmentGroupHierarchySchema
from maus.reader.mig_xml_reader import MigXmlReader

Expand Down Expand Up @@ -79,7 +76,7 @@ def main(
raise click.Abort()

with open(flat_ahb_path, "r", encoding="utf-8") as flat_ahb_file:
flat_ahb = FlatAnwendungshandbuchSchema().load(json.load(flat_ahb_file))
flat_ahb = FlatAnwendungshandbuch.model_validate(json.load(flat_ahb_file))
with open(sgh_path, "r", encoding="utf-8") as sgh_file:
sgh = SegmentGroupHierarchySchema().loads(sgh_file.read())

Expand All @@ -93,14 +90,14 @@ def main(
raise click.Abort()

if output_path is not None:
maus_dict = DeepAnwendungshandbuchSchema().dump(maus)
maus_dict = maus.model_dump(mode="json")

with open(output_path, "w", encoding="utf-8") as maus_file:
json.dump(maus_dict, maus_file, indent=2, ensure_ascii=False, sort_keys=True)

if check_path is not None:
with open(check_path, "r", encoding="utf-8") as maus_file:
expected_maus: DeepAnwendungshandbuch = DeepAnwendungshandbuchSchema().loads(maus_file.read())
expected_maus: DeepAnwendungshandbuch = DeepAnwendungshandbuch.model_validate_json(maus_file.read())

# reset the line index to make the comparison work
# this is fine cause there is no logic built on top of the line index
Expand Down
5 changes: 3 additions & 2 deletions src/maus/maus_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
from pathlib import Path
from typing import Optional

from kohlrahbi.models.anwendungshandbuch import DeepAnwendungshandbuch

from maus.edifact import EdifactFormat, EdifactFormatVersion
from maus.models.anwendungshandbuch import DeepAnwendungshandbuch, DeepAnwendungshandbuchSchema

# pylint:disable=too-few-public-methods

Expand Down Expand Up @@ -60,7 +61,7 @@ def get_maus(
try:
with open(full_path, "r", encoding=self._encoding) as maus_infile:
file_content_json = json.load(maus_infile)
maus = DeepAnwendungshandbuchSchema().load(file_content_json)
maus = DeepAnwendungshandbuch.model_validate(file_content_json)
except FileNotFoundError:
return None
return maus
6 changes: 3 additions & 3 deletions src/maus/mig_ahb_matching.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
from itertools import groupby
from typing import List, Optional, Sequence, Set, Tuple

from kohlrahbi.models.anwendungshandbuch import _VERSION, AhbLine, DeepAnwendungshandbuch, FlatAnwendungshandbuch
from more_itertools import first, first_true, last

from maus.models.anwendungshandbuch import _VERSION, AhbLine, DeepAnwendungshandbuch, FlatAnwendungshandbuch
from maus.models.edifact_components import (
DataElement,
DataElementFreeText,
Expand Down Expand Up @@ -98,7 +98,7 @@ def to_deep_ahb(
Converts a flat ahb into a nested ahb using the provided segment hierarchy
"""
result = DeepAnwendungshandbuch(meta=flat_ahb.meta, lines=[])
result.meta.maus_version = _VERSION
result.meta.maus_version = _VERSION # pylint:disable=assigning-non-slot
parent_group_lists: List[List[SegmentGroup]] = []
used_stacks: Set[str] = set()
# The following lists are _not_ a view into the lines that are going to follow (hence no name starting with "next")
Expand Down Expand Up @@ -170,7 +170,7 @@ def to_deep_ahb(
used_stacks.add(stack.to_json_path())
append_next_segments_here = segment_group.segments # type:ignore[assignment]
if segment_group.discriminator == '$["Dokument"][0]["Nachricht"][0]':
result.lines.append(segment_group)
result.lines.append(segment_group) # pylint:disable=no-member
append_next_sg_here = segment_group.segment_groups # type:ignore[assignment]
parent_group_lists.append(result.lines)
elif position.is_sub_location_of(previous_position): # pylint:disable=used-before-assignment
Expand Down
Loading