From cd2df8f5efa174c5ea4afdef0e949097aef3e57c Mon Sep 17 00:00:00 2001 From: Noisyfox Date: Sun, 20 Apr 2025 14:21:40 +0800 Subject: [PATCH] Fix profile check error msg (#9414) * Ensure file encoding * Show correct file path in error message --- scripts/orca_extra_profile_check.py | 34 ++++++++++++++++------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/scripts/orca_extra_profile_check.py b/scripts/orca_extra_profile_check.py index 84f28d1ab2..7ebba70592 100644 --- a/scripts/orca_extra_profile_check.py +++ b/scripts/orca_extra_profile_check.py @@ -33,7 +33,7 @@ def check_filament_compatible_printers(vendor_folder): # Use rglob to recursively find .json files. for file_path in vendor_path.rglob("*.json"): try: - with open(file_path, 'r') as fp: + with open(file_path, 'r', encoding='UTF-8') as fp: # Use custom hook to detect duplicates. data = json.load(fp, object_pairs_hook=no_duplicates_object_pairs_hook) except ValueError as ve: @@ -51,31 +51,35 @@ def check_filament_compatible_printers(vendor_folder): error += 1 continue - profiles[profile_name] = data + profiles[profile_name] = { + 'file_path': file_path, + 'content': data, + } - def get_inherit_property(data, key): - if key in data: - return data[key] + def get_inherit_property(profile, key): + content = profile['content'] + if key in content: + return content[key] - if 'inherits' in data: - inherits = data['inherits'] + if 'inherits' in content: + inherits = content['inherits'] if inherits not in profiles: - raise ValueError(f"Parent profile not found: {inherits}") + raise ValueError(f"Parent profile not found: {inherits}, referrenced in {profile['file_path']}") return get_inherit_property(profiles[inherits], key) return None - for data in profiles.values(): - instantiation = str(data.get("instantiation", "")).lower() == "true" + for profile in profiles.values(): + instantiation = str(profile['content'].get("instantiation", "")).lower() == "true" if instantiation: try: - compatible_printers = get_inherit_property(data, "compatible_printers") + compatible_printers = get_inherit_property(profile, "compatible_printers") if not compatible_printers or (isinstance(compatible_printers, list) and not compatible_printers): - print(f"'compatible_printers' missing in {file_path}") + print(f"'compatible_printers' missing in {profile['file_path']}") error += 1 except ValueError as ve: - print(f"Unable to parse {file_path}: {ve}") + print(f"Unable to parse {profile['file_path']}: {ve}") error += 1 continue @@ -100,7 +104,7 @@ def load_available_filament_profiles(profiles_dir, vendor_name): for file_path in vendor_path.rglob("*.json"): try: - with open(file_path, 'r') as fp: + with open(file_path, 'r', encoding='UTF-8') as fp: data = json.load(fp) if "name" in data: profiles.add(data["name"]) @@ -136,7 +140,7 @@ def check_machine_default_materials(profiles_dir, vendor_name): # Check each machine profile for file_path in machine_dir.rglob("*.json"): try: - with open(file_path, 'r') as fp: + with open(file_path, 'r', encoding='UTF-8') as fp: data = json.load(fp) default_materials = None