Fix profile check error msg (#9414)

* Ensure file encoding

* Show correct file path in error message
This commit is contained in:
Noisyfox 2025-04-20 14:21:40 +08:00 committed by GitHub
parent cd2077ebaf
commit cd2df8f5ef
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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