Skip to content
Open
Show file tree
Hide file tree
Changes from 8 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 .github/workflows/unittests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
python-version: [3.9, "3.10", "3.11", "3.12", "3.13", "3.14"]
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
os: [ubuntu-latest]
steps:
- uses: actions/checkout@v5
Expand Down
40 changes: 7 additions & 33 deletions json_schemas/generate_json_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@
import pathlib
from typing import Any, Type

from marshmallow import Schema, fields
from marshmallow_jsonschema import JSONSchema # type:ignore[import]
from pydantic import BaseModel, ValidationError
from pydantic import BaseModel, TypeAdapter

from ahbicht.json_serialization.tree_schema import TokenSchema # , TreeSchema
# from ahbicht.json_serialization.tree_schema import TREE_ADAPTER
from ahbicht.models.categorized_key_extract import CategorizedKeyExtract
from ahbicht.models.condition_nodes import EvaluatedFormatConstraint
from ahbicht.models.content_evaluation_result import ContentEvaluationResult
Expand All @@ -22,48 +20,24 @@
)
from ahbicht.models.mapping_results import ConditionKeyConditionTextMapping, PackageKeyConditionExpressionMapping

schema_types: list[Type[Schema] | Type[BaseModel]] = [
schema_types: list[Type[TypeAdapter] | Type[BaseModel]] = [
RequirementConstraintEvaluationResult, # pydantic
FormatConstraintEvaluationResult, # pydantic
EvaluatedFormatConstraint, # pydantic
AhbExpressionEvaluationResult, # pydantic
ConditionKeyConditionTextMapping, # pydantic
PackageKeyConditionExpressionMapping, # pydantic
TokenSchema, # marshmallow
# TREE_ADAPTER, # doesn't work yet but that's ok for now
CategorizedKeyExtract, # pydantic
ContentEvaluationResult, # pydantic
# TreeSchema
# As of 2021-11 the TreeSchema fails, probably because of recursion or the lambda:
# (<class 'AttributeError'>, AttributeError("'function' object has no attribute 'fields'"), ....)
]
json_schema = JSONSchema()
for schema_type in schema_types:
this_directory = pathlib.Path(__file__).parent.absolute()
file_name: str
json_schema_dict: dict[str, Any]
try: # marshmallow json schema approach (deprecated - to be phased out one after another)
FILE_NAME = schema_type.__name__ + ".json" # pylint:disable=invalid-name
schema_instance = schema_type()
if "requirement_indicator" in schema_instance.fields: # type:ignore[union-attr]
# raises attribute error for pydantic classes
# workaround for marshmallow: in the schemas we want the requirement indicator to appear as simple string
# the schema used internally is just a workaround
assert hasattr(schema_instance, "fields")
assert hasattr(schema_instance, "load_fields")
assert hasattr(schema_instance, "dump_fields")
assert hasattr(schema_instance, "declared_fields")
for field_dict in [
schema_instance.fields,
schema_instance.load_fields,
schema_instance.dump_fields,
schema_instance.declared_fields,
]:
field_dict["requirement_indicator"] = fields.String(name="requirement_indicator")
json_schema_dict = json_schema.dump(schema_instance)
except (AttributeError, ValidationError): # means, we're creating a json schema from a pydantic class
FILE_NAME = schema_type.__name__ + "Schema.json" # other than for the marshmallow classes, we add 'Schema' here
assert hasattr(schema_type, "model_json_schema")
json_schema_dict = schema_type.model_json_schema()
FILE_NAME = schema_type.__name__ + "Schema.json"
assert hasattr(schema_type, "model_json_schema")
json_schema_dict = schema_type.model_json_schema()
file_path = this_directory / FILE_NAME
# We want our JSON schemas to be compatible with a typescript code generator:
# https://github.com/bcherny/json-schema-to-typescript/
Expand Down
6 changes: 2 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "ahbicht"
description = "Python Library to parse AHB expressions."
license = { text = "MIT" }
requires-python = ">=3.9"
requires-python = ">=3.10"
authors = [
{ name = "Annika Schlögl", email = "[email protected]" },
]
Expand All @@ -15,7 +15,6 @@ classifiers = [
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
Expand All @@ -26,7 +25,6 @@ classifiers = [
dependencies = [
"lark>=1.1.4",
"inject",
"marshmallow<4",
"pytz",
"efoli>=2.1.0",
"pydantic>=2"
Expand All @@ -37,7 +35,7 @@ dynamic = ["readme", "version"]
coverage = ["coverage==7.10.7"]
docs = ["sphinx==8.1.3", "sphinx-rtd-theme==3.0.2"]
formatting = ["black[jupyter]==25.9.0", "isort==6.1.0"]
json_schemas = ["marshmallow-jsonschema==0.13.0", "setuptools==80.9.0"]
json_schemas = []
linting = ["pylint==3.3.9"]
spellcheck = ["codespell==2.4.1"]
test_packaging = [
Expand Down
4 changes: 0 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ inject==5.3.0
# via ahbicht (pyproject.toml)
lark==1.3.0
# via ahbicht (pyproject.toml)
marshmallow==3.26.1
# via ahbicht (pyproject.toml)
packaging==25.0
# via marshmallow
pydantic==2.12.0
# via ahbicht (pyproject.toml)
pydantic-core==2.41.1
Expand Down

This file was deleted.

53 changes: 0 additions & 53 deletions src/ahbicht/json_serialization/concise_tree_schema.py

This file was deleted.

Loading