From 84ca35c68ce9994405abc3509d9570b76ea06d09 Mon Sep 17 00:00:00 2001 From: Sujith Kanakkassery Date: Sun, 17 May 2026 06:49:23 +0530 Subject: [PATCH 1/2] Check Meta validation during indexing --- mlc/index.py | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/mlc/index.py b/mlc/index.py index 13858fddc..b73d3ee4b 100644 --- a/mlc/index.py +++ b/mlc/index.py @@ -232,8 +232,12 @@ def _index_single_repo(self, repo, repos_changed=False, if os.path.isfile(yaml_path): config_path = yaml_path + with open(config_path, "r") as f: + data = yaml.safe_load(f) or {} elif os.path.isfile(json_path): config_path = json_path + with open(config_path, "r") as f: + data = json.load(f) or {} else: # No config file found, remove from index if exists delete_flag = False @@ -257,6 +261,18 @@ def _index_single_repo(self, repo, repos_changed=False, if delete_flag: changed = True continue + + # Validate script meta against schema during indexing + if folder_type == "script": + errors, warnings = validate_meta(data, config_path) + for e in errors: + logger.error(f"Meta validation error: {e}") + for w in warnings: + logger.debug(f"Meta validation warning: {w}") + if errors: + raise ValueError( + f"Meta validation failed for {config_path}. Fix the above error(s) and try again.") + if current_item_keys is not None: current_item_keys.add(config_path) mtime = self.get_item_mtime(config_path) @@ -346,7 +362,7 @@ def _remove_index_entry(self, key): if removed_count > 0: logger.debug( f"Removed {removed_count} item(s) from {ft} index") - + def _delete_index_entries(self, folder_type, key, value): """ Remove index entries matching for the same path or same UID. @@ -400,22 +416,10 @@ def _process_config_file( tags = data.get("tags", []) alias = data.get("alias", None) - # Validate script meta against schema during indexing - if folder_type == "script": - errors, warnings = validate_meta(data, config_file) - for e in errors: - logger.error(f"Meta validation error: {e}") - for w in warnings: - logger.debug(f"Meta validation warning: {w}") - if errors: - raise ValueError( - f"Meta validation failed for {config_file}. Fix the above error(s) and try again.") - # Remove stale entry for the same meta file path if exists self._delete_index_entries(folder_type, "path", folder_path) - # Remove index entry with the same UID for other meta file if - # exists + # Remove index entry with the same UID for other meta file if exists self._delete_index_entries(folder_type, "uid", unique_id) self.indices[folder_type].append({ From dd8053cce7393c39f793dd69dd79a972fee0f500 Mon Sep 17 00:00:00 2001 From: Sujith Kanakkassery Date: Sun, 17 May 2026 09:52:18 +0530 Subject: [PATCH 2/2] Update meta validation to only check if a meta file is modified --- mlc/index.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/mlc/index.py b/mlc/index.py index b73d3ee4b..c8a90716a 100644 --- a/mlc/index.py +++ b/mlc/index.py @@ -261,9 +261,19 @@ def _index_single_repo(self, repo, repos_changed=False, if delete_flag: changed = True continue + + if current_item_keys is not None: + current_item_keys.add(config_path) + mtime = self.get_item_mtime(config_path) + old_mtime = self._get_stored_mtime(config_path) + + # skip if unchanged + if old_mtime == mtime and not repos_changed: + continue - # Validate script meta against schema during indexing + # Validate script meta against schema during indexing if meta changed or repos changed if folder_type == "script": + # logger.debug(f"-----Meta changed for {automation_path}, validating against schema... -----") errors, warnings = validate_meta(data, config_path) for e in errors: logger.error(f"Meta validation error: {e}") @@ -273,23 +283,13 @@ def _index_single_repo(self, repo, repos_changed=False, raise ValueError( f"Meta validation failed for {config_path}. Fix the above error(s) and try again.") - if current_item_keys is not None: - current_item_keys.add(config_path) - mtime = self.get_item_mtime(config_path) - old_mtime = self._get_stored_mtime(config_path) - - # skip if unchanged - if old_mtime == mtime and not repos_changed: - continue - self.modified_times[config_path] = { "mtime": mtime, "date_time": datetime.fromtimestamp(mtime).strftime("%Y-%m-%d %H:%M:%S") } # meta file changed, so reindex - self._process_config_file( - config_path, folder_type, automation_path, repo) + self._process_config_file(config_path, folder_type, automation_path, repo) changed = True return changed