|
24 | 24 | if parent_dir not in sys.path: |
25 | 25 | sys.path.insert(0, parent_dir) |
26 | 26 |
|
27 | | -from scripts.card_models import CardYAML, MappingYAML, ValidationError as PydanticValidationError |
| 27 | +try: |
| 28 | + from scripts.card_models import CardYAML, MappingYAML, ValidationError as PydanticValidationError |
| 29 | + PYDANTIC_AVAILABLE = True |
| 30 | +except ImportError: |
| 31 | + PYDANTIC_AVAILABLE = False |
| 32 | + PydanticValidationError = Exception # Fallback |
28 | 33 |
|
29 | 34 |
|
30 | 35 | class ConvertVars: |
@@ -644,13 +649,14 @@ def get_mapping_data_for_edition( |
644 | 649 | with open(mappingfile, "r", encoding="utf-8") as f: |
645 | 650 | try: |
646 | 651 | data = yaml.safe_load(f) |
647 | | - # Validate structure with Pydantic |
648 | | - try: |
649 | | - validated = MappingYAML(**data) |
650 | | - data = validated.model_dump(exclude_none=True) # Convert back to dict, exclude None values |
651 | | - except PydanticValidationError as ve: |
652 | | - logging.warning(f"Mapping file validation warning for {mappingfile}: {ve}") |
653 | | - # Continue with unvalidated data for backward compatibility |
| 652 | + # Validate structure with Pydantic if available |
| 653 | + if PYDANTIC_AVAILABLE: |
| 654 | + try: |
| 655 | + validated = MappingYAML(**data) |
| 656 | + data = validated.model_dump(exclude_none=True) # Convert back to dict, exclude None values |
| 657 | + except PydanticValidationError as ve: |
| 658 | + logging.warning(f"Mapping file validation warning for {mappingfile}: {ve}") |
| 659 | + # Continue with unvalidated data for backward compatibility |
654 | 660 | except yaml.YAMLError as e: |
655 | 661 | logging.info(f"Error loading yaml file: {mappingfile}. Error = {e}") |
656 | 662 | data = {} |
@@ -752,14 +758,15 @@ def get_language_data( |
752 | 758 | with open(language_file, "r", encoding="utf-8") as f: |
753 | 759 | try: |
754 | 760 | data = yaml.safe_load(f) |
755 | | - # Validate structure with Pydantic |
756 | | - try: |
757 | | - validated = CardYAML(**data) |
758 | | - data = validated.model_dump(exclude_none=True) # Convert back to dict, exclude None values |
759 | | - except PydanticValidationError as ve: |
760 | | - logging.error(f"Card file validation failed for {language_file}: {ve}") |
761 | | - # For card files, validation failure is more critical |
762 | | - data = {} |
| 761 | + # Validate structure with Pydantic if available |
| 762 | + if PYDANTIC_AVAILABLE: |
| 763 | + try: |
| 764 | + validated = CardYAML(**data) |
| 765 | + data = validated.model_dump(exclude_none=True) # Convert back to dict, exclude None values |
| 766 | + except PydanticValidationError as ve: |
| 767 | + logging.error(f"Card file validation failed for {language_file}: {ve}") |
| 768 | + # For card files, validation failure is more critical |
| 769 | + data = {} |
763 | 770 | except yaml.YAMLError as e: |
764 | 771 | logging.error(f"Error loading yaml file: {language_file}. Error = {e}") |
765 | 772 | data = {} |
|
0 commit comments