33"""
44
55import itertools
6+ import logging
67import re
78from pathlib import Path
89from typing import Iterable , Sequence
1112
1213from . import change_schemas , loader
1314
15+ logger = logging .getLogger (__name__ )
16+
1417REGEX_IGNORE_VERSION = re .compile (r"v\d+\.\d+\.\d+(-rc\d+)?" )
1518
1619
@@ -21,11 +24,23 @@ def _diff_type_base(
2124 This function compares two type base schemas and yields the changes.
2225 """
2326 if schema_old .title != schema_new .title :
24- raise RuntimeError (
27+ logger . warning (
2528 (
2629 "Title should not change. Renaming is not detectable and the titles are autogenerated.\n "
27- f"{ schema_old .title } -> { schema_new .title } "
28- )
30+ "'%s' -> '%s'\n "
31+ "%s -> %s"
32+ ),
33+ schema_old .title ,
34+ schema_new .title ,
35+ old_trace ,
36+ new_trace ,
37+ )
38+ yield change_schemas .Change (
39+ type = change_schemas .ChangeType .FIELD_TITLE_CHANGED ,
40+ old = schema_old .title ,
41+ new = schema_new .title ,
42+ old_trace = old_trace ,
43+ new_trace = new_trace ,
2944 )
3045 if REGEX_IGNORE_VERSION .sub (schema_old .description , "{__gh_version__}" ) != REGEX_IGNORE_VERSION .sub (
3146 schema_new .description , "{__gh_version__}"
@@ -288,7 +303,9 @@ def _diff_root_schemas(
288303 yield from _diff_schema_type (schema_old , schema_new , old_trace , new_trace )
289304
290305
291- def diff_schemas (schemas_old : Path , schemas_new : Path ) -> Iterable [change_schemas .Change ]:
306+ def diff_schemas (
307+ schemas_old : Path , schemas_new : Path , old_trace : str , new_trace : str
308+ ) -> Iterable [change_schemas .Change ]:
292309 """
293310 This function compares two BO4E versions and yields the changes.
294311 Note: The paths to the old and the new schemas should correspond to the same root node of the tree structure.
@@ -302,23 +319,23 @@ def diff_schemas(schemas_old: Path, schemas_new: Path) -> Iterable[change_schema
302319 type = change_schemas .ChangeType .CLASS_REMOVED ,
303320 old = loader .load_schema_file (schemas_old / schema_file ),
304321 new = None ,
305- old_trace = f"{ '/' .join (schema_file .with_suffix ('' ).parts )} #" ,
306- new_trace = " #" ,
322+ old_trace = f"{ old_trace } / { '/' .join (schema_file .with_suffix ('' ).parts )} #" ,
323+ new_trace = f" { new_trace } / #" ,
307324 )
308325 for schema_file in new_schema_files - old_schema_files :
309326 yield change_schemas .Change (
310327 type = change_schemas .ChangeType .CLASS_ADDED ,
311328 old = None ,
312329 new = loader .load_schema_file (schemas_new / schema_file ),
313- old_trace = " #" ,
314- new_trace = f"{ '/' .join (schema_file .with_suffix ('' ).parts )} #" ,
330+ old_trace = f" { old_trace } / #" ,
331+ new_trace = f"{ new_trace } / { '/' .join (schema_file .with_suffix ('' ).parts )} #" ,
315332 )
316333 for schema_file in old_schema_files & new_schema_files :
317334 yield from _diff_root_schemas (
318335 loader .load_schema_file (schemas_old / schema_file ),
319336 loader .load_schema_file (schemas_new / schema_file ),
320- f"{ '/' .join (schema_file .with_suffix ('' ).parts )} #" ,
321- f"{ '/' .join (schema_file .with_suffix ('' ).parts )} #" ,
337+ f"{ old_trace } / { '/' .join (schema_file .with_suffix ('' ).parts )} #" ,
338+ f"{ new_trace } / { '/' .join (schema_file .with_suffix ('' ).parts )} #" ,
322339 )
323340
324341
@@ -333,7 +350,7 @@ def compare_bo4e_versions(
333350 dir_old_schemas = loader .pull_or_reuse_bo4e_version (version_old , gh_token )
334351 dir_new_schemas = loader .pull_or_reuse_bo4e_version (version_new , gh_token , from_local = from_local )
335352 print (f"Comparing { version_old } with { version_new } " )
336- yield from diff_schemas (dir_old_schemas , dir_new_schemas )
353+ yield from diff_schemas (dir_old_schemas , dir_new_schemas , version_old , version_new )
337354
338355
339356def compare_bo4e_versions_iteratively (
0 commit comments