Build AI methods with your coding agent, then run them anywhere: as an MCP for chatbots, as a webapp for people, or via API for your software.
validate a bundle path of a loaded bundle (#416)
Louis Choquelbb8ebf998159
diff --git a/pipelex/cli/commands/validate_cmd.py b/pipelex/cli/commands/validate_cmd.pyindex 7a0e732fb..756635d7f 100644--- a/pipelex/cli/commands/validate_cmd.py+++ b/pipelex/cli/commands/validate_cmd.py@@ -1,6 +1,7 @@from __future__ import annotationsimport asyncio+from pathlib import Pathfrom typing import TYPE_CHECKING, Annotatedimport click@@ -15,7 +16,7 @@ from pipelex.builder.builder_errors import PipelexBundleErrorfrom pipelex.builder.builder_validation import validate_dry_run_bundle_blueprintfrom pipelex.core.interpreter import PipelexInterpreterfrom pipelex.exceptions import LibraryLoadingError, PipeInputError-from pipelex.hub import get_pipes, get_required_pipe, get_telemetry_manager+from pipelex.hub import get_library_manager, get_pipes, get_required_pipe, get_telemetry_managerfrom pipelex.pipe_run.dry_run import dry_run_pipe, dry_run_pipesfrom pipelex.pipelex import Pipelexfrom pipelex.system.runtime import IntegrationMode@@ -23,7 +24,9 @@ from pipelex.system.telemetry.events import EventName, EventPropertyfrom pipelex.tools.misc.package_utils import get_package_versionif TYPE_CHECKING:+ from pipelex.core.pipes.pipe_abstract import PipeAbstractfrom pipelex.core.validation_errors import ValidationErrorDetailsProtocol+console = Console()COMMAND = "validate"@@ -118,6 +121,19 @@ def validate_cmd(async def validate_pipe(pipe_code: str | None = None, bundle_path: str | None = None):if bundle_path:+ absolute_bundle_path = str(Path(bundle_path).resolve())+ if absolute_bundle_path in get_library_manager().get_loaded_plx_paths():+ bundle_blueprint = PipelexInterpreter.load_bundle_blueprint(bundle_path=bundle_path)+ if not bundle_blueprint.pipe:+ typer.secho(f"Failed to validate bundle '{bundle_path}': no pipes found in bundle", fg=typer.colors.RED, err=True)+ raise typer.Exit(1)+ pipe_codes = list(bundle_blueprint.pipe.keys())+ pipes: list[PipeAbstract] = []+ for the_pipe_code in pipe_codes:+ pipes.append(get_required_pipe(pipe_code=the_pipe_code))+ await dry_run_pipes(pipes=pipes, raise_on_failure=True)+ typer.secho(f"✅ Successfully validated all pipes in bundle '{bundle_path}'", fg=typer.colors.GREEN)+ return# When validating a bundle, load_pipe_from_bundle validates ALL pipes in the bundletry:bundle_blueprint = PipelexInterpreter.load_bundle_blueprint(bundle_path=bundle_path)diff --git a/pipelex/libraries/library_manager.py b/pipelex/libraries/library_manager.pyindex dc877a1db..cf1ff455d 100644--- a/pipelex/libraries/library_manager.py+++ b/pipelex/libraries/library_manager.py@@ -73,6 +73,7 @@ class LibraryManager(LibraryManagerAbstract):self.domain_library = domain_libraryself.concept_library = concept_libraryself.pipe_library = pipe_library+ self.loaded_plx_paths: list[str] = []@overridedef validate_libraries(self):@@ -97,6 +98,10 @@ class LibraryManager(LibraryManagerAbstract):self.teardown()self.setup()+ @override+ def get_loaded_plx_paths(self) -> list[str]:+ return self.loaded_plx_paths+def _get_pipelex_plx_files_from_dirs(self, dirs: set[Path]) -> list[Path]:"""Get all valid Pipelex PLX files from the given directories."""all_plx_paths: list[Path] = []@@ -347,6 +352,8 @@ class LibraryManager(LibraryManagerAbstract):blueprint.source = str(plx_file_path)blueprints.append(blueprint)+ self.loaded_plx_paths.extend([str(plx_file_path) for plx_file_path in valid_plx_paths])+# Load all domains firstall_domains: list[Domain] = []for blueprint in blueprints:diff --git a/pipelex/libraries/library_manager_abstract.py b/pipelex/libraries/library_manager_abstract.pyindex 9c23a9f09..b3b6b3b83 100644--- a/pipelex/libraries/library_manager_abstract.py+++ b/pipelex/libraries/library_manager_abstract.py@@ -22,6 +22,10 @@ class LibraryManagerAbstract(ABC):def validate_libraries(self) -> None:pass+ @abstractmethod+ def get_loaded_plx_paths(self) -> list[str]:+ pass+@abstractmethoddef load_libraries(self, library_dirs: list[Path] | None = None, library_file_paths: list[Path] | None = None) -> None:pass