qdk_chemistry.ui.validation module
Input validation and project management for QDK Chemistry.
- qdk_chemistry.ui.validation.class_data_type_name(dataclass_type)
Return a loader’s static wire-format identifier.
- qdk_chemistry.ui.validation.current_project_name()[source]
Return the project currently validated for this execution context.
- qdk_chemistry.ui.validation.current_project_dir()[source]
Return the absolute project directory validated for this execution context.
- qdk_chemistry.ui.validation.strip_filename_path(filename)[source]
Return only the filename, accepting both POSIX and Windows separators.
- qdk_chemistry.ui.validation.resolve_project_file(filename, *, allow_nested=False, allow_absolute=False)[source]
Resolve a client-provided filename inside the current project sandbox.
Absolute paths, traversal components, Windows drive or UNC paths, and symlinks that resolve outside the project are rejected.
- Parameters:
- Return type:
- Returns:
An absolute path contained by the current project directory.
- Raises:
RuntimeError – If called outside a validated project context.
ValueError – If the filename is invalid or escapes the project.
- exception qdk_chemistry.ui.validation.FilenameFormatError[source]
Bases:
ExceptionRaised when a filename has an invalid format for the expected data type.
- qdk_chemistry.ui.validation.resolve_project_path(project_name, projects_dir)[source]
Resolve a single-component project name beneath the projects directory.
- qdk_chemistry.ui.validation.ensure_filename_format(filename, data_type)[source]
Ensure filename contains the correct type marker for the given data type.
- Parameters:
- Return type:
- Returns:
The corrected filename with proper type marker
- Raises:
FilenameFormatError – If the data type is unrecognized or the file extension is invalid
- qdk_chemistry.ui.validation.validate_project(func)[source]
Decorator to validate project before executing the function.
Validates that a project exists and exposes its absolute directory through the current execution context. The process working directory is unchanged.
It expects the decorated function to have
project_nameas its first parameter afterself(if applicable).- Parameters:
func (
TypeVar(F, bound=Callable[...,Any])) – The function to decorate. Must haveproject_name: stras a parameter.- Returns:
The decorated function with project validation logic, or str: a JSON string with error information.
- Return type:
Example:
@validate_project @app.tool() def my_function(project_name: str, other_param: int) -> str: # This function will only execute if project_name is valid return "success"