refactor: restructure resolver logic and improve type safety (#1323)

# What does this PR do?

- Modularized `resolve_impls` by extracting helper functions for
validation, sorting, and instantiation.
- Improved readability by introducing `validate_and_prepare_providers`,
`sort_providers_by_dependency`, and `instantiate_providers`.
- Enhanced type safety with explicit type hints (`Tuple`, `Dict`, `Set`,
etc.).
- Fixed potential issues with provider module imports and added error
handling.
- Updated `pyproject.toml` to enforce type checking on `resolver.py`
using `mypy`.

Signed-off-by: Sébastien Han <seb@redhat.com>

- [//]: # (If resolving an issue, uncomment and update the line below)
[//]: # (Closes #[issue-number])

## Test Plan

Run the server.

[//]: # (## Documentation)

Signed-off-by: Sébastien Han <seb@redhat.com>
This commit is contained in:
Sébastien Han 2025-03-03 19:45:12 +01:00 committed by GitHub
parent cae6c00d8a
commit f86154dff5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 119 additions and 84 deletions

View file

@ -75,11 +75,7 @@ docs = [
"sphinxcontrib.mermaid",
"tomli",
]
codegen = [
"rich",
"pydantic",
"jinja2",
]
codegen = ["rich", "pydantic", "jinja2"]
[project.urls]
Homepage = "https://github.com/meta-llama/llama-stack"
@ -163,3 +159,7 @@ exclude = [
# packages that lack typing annotations, do not have stubs, or are unavailable.
module = ["yaml", "fire"]
ignore_missing_imports = true
[[tool.mypy.overrides]]
module = "llama_stack.distribution.resolver"
follow_imports = "normal" # This will force type checking on this module