Scope the filament AMS length check to presets the vendor bundle references

The tree-wide length check (freed from its BBL/OFL carve-out last commit)
was flagging 21 pre-existing SeeMeCNC files that no vendor index references
and that therefore never load, turning CI red for files with no bearing on
what ships. The rule now only fires on presets a vendor's filament_list
actually references; every .json under the vendor's filament directory is
still parsed through the duplicate-key hook, so that coverage is unchanged.

Also removed a duplicated BAMBU_MAP_PATH definition: update_bambu_filament_ids.py
now imports the constant from assign_filament_ids.py, which it already imports
several other constants from, instead of recomputing the same path independently.
This commit is contained in:
SoftFever
2026-09-04 14:42:57 +08:00
parent 40cc3340b1
commit db3d684ee0
3 changed files with 31 additions and 15 deletions

View File

@@ -79,8 +79,8 @@ FILAMENT_ID_LENGTH = 6 # base62 digits after the "OF" prefix -> 8 chars total
SCRIPTS_DIR = os.path.dirname(os.path.abspath(__file__))
PROFILES_DIR = os.path.normpath(os.path.join(SCRIPTS_DIR, "..", "resources", "profiles"))
SNAPSHOT_PATH = os.path.join(SCRIPTS_DIR, "filament_id_snapshot.json")
# Same path update_bambu_filament_ids.BAMBU_MAP_PATH computes; kept as a sibling
# constant (not imported) because that module imports FROM this one already.
# The single source of truth for the map path; update_bambu_filament_ids.py
# imports this rather than recomputing it.
BAMBU_MAP_PATH = os.path.normpath(
os.path.join(SCRIPTS_DIR, "..", "resources", "printers", "bambu_filament_ids.json"))

View File

@@ -290,19 +290,38 @@ def check_name_consistency(profiles_dir, vendor_name):
return error_count, 0
def check_filament_id(vendor_folder):
def check_filament_id(profiles_dir, vendor_name):
"""
Make sure filament_id is not longer than 8 characters, otherwise AMS won't work properly.
Runs tree-wide, every vendor alike: check_filament_ids (assign_filament_ids.py)
already requires every id in the tree to match the fixed-length "OF" format,
so this is a redundant belt-and-suspenders check, not a substitute for it.
Runs tree-wide, every vendor alike (BBL included: the id format is what
matters, not the vendor). Every .json file under the vendor's filament
directory is still parsed through the duplicate-key hook below, so that
coverage is unchanged; only the length rule itself is scoped to presets
the vendor's index (<vendor>.json filament_list) actually references. A
file the index does not reference never loads, so its filament_id length
cannot break AMS -- and some vendors (e.g. SeeMeCNC) ship such orphaned
files pre-dating this check, with no bearing on what ships.
"""
error = 0
vendor_path = Path(vendor_folder)
vendor_path = profiles_dir / vendor_name / "filament"
if not vendor_path.exists():
return 0
referenced = set()
vendor_file = profiles_dir / (vendor_name + ".json")
if vendor_file.exists():
try:
with open(vendor_file, 'r', encoding='UTF-8') as fp:
index = json.load(fp)
for entry in index.get('filament_list', []):
sub_path = entry.get('sub_path')
if sub_path:
referenced.add((profiles_dir / vendor_name / sub_path).resolve())
except Exception as e:
print_error(f"Error loading vendor profile {vendor_file}: {e}")
error += 1
# Use rglob to recursively find .json files.
for file_path in vendor_path.rglob("*.json"):
try:
@@ -320,13 +339,13 @@ def check_filament_id(vendor_folder):
if 'filament_id' not in data:
continue
filament_id = data['filament_id']
if len(filament_id) > 8:
if len(filament_id) > 8 and file_path.resolve() in referenced:
error += 1
print_error(f"Filament id too long \"{filament_id}\": {file_path}")
return error
def check_obsolete_keys(profiles_dir, vendor_name):
@@ -597,7 +616,7 @@ def main():
errors_found += check_vector_type_keys(profiles_dir, vendor_name)
errors_found += check_filament_id(vendor_path / "filament")
errors_found += check_filament_id(profiles_dir, vendor_name)
checked_vendor_count += 1
if args.vendor:

View File

@@ -55,6 +55,7 @@ import datetime
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from assign_filament_ids import ( # noqa: E402
BAMBU_MAP_PATH,
OFL,
OF_ID_RE,
PROFILES_DIR,
@@ -69,10 +70,6 @@ from assign_filament_ids import ( # noqa: E402
resolve_triple,
)
SCRIPTS_DIR = os.path.dirname(os.path.abspath(__file__))
BAMBU_MAP_PATH = os.path.normpath(
os.path.join(SCRIPTS_DIR, "..", "resources", "printers", "bambu_filament_ids.json"))
BAMBUSTUDIO_REPO = "https://github.com/bambulab/BambuStudio"