Defer import of system modules and Azure SDKs#527
Merged
JacobCallahan merged 1 commit intomasterfrom Feb 10, 2026
Merged
Conversation
Fixes: - Resolve an issue where importing `VmState` in Robottelo could trigger errors due to the eager loading of all system provider modules and their heavy dependencies. This change allows `VmState` to be imported without pulling in unused provider SDKs. Refactoring: - Implement `__getattr__` in `wrapanapi/__init__.py` and `wrapanapi/systems/__init__.py` to lazily import system classes (e.g., `EC2System`, `VMWareSystem`). This defers the loading of module dependencies until a specific system class is accessed. - Introduce lazy importing for Azure SDK components within `wrapanapi/systems/msazure.py`. Azure dependencies are now loaded only when an Azure system or entity is instantiated, avoiding unnecessary module loading and potential import errors when the SDK is not present or needed. - Adjust a multi-line expression in `wrapanapi/systems/nuage.py` for improved readability. Configuration: - Update `ruff-pre-commit` to version `v0.15.0`. - Update `pyupgrade` to version `v3.21.2`.
There was a problem hiding this comment.
Pull request overview
This PR refactors wrapanapi to avoid eagerly importing all provider system modules (and their heavy SDK dependencies) when importing convenience symbols like VmState, and introduces lazy loading for Azure SDK dependencies so Azure packages are only required when Azure functionality is actually used.
Changes:
- Add module-level
__getattr__lazy loaders inwrapanapi/__init__.pyandwrapanapi/systems/__init__.pyto defer provider system imports until accessed. - Lazily import Azure SDK components in
wrapanapi/systems/msazure.pyvia an_ensure_azure_imports()gate invoked during Azure object construction. - Minor readability tweak in Nuage stats expression and bump pre-commit hook versions.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
wrapanapi/systems/nuage.py |
Reformat a multi-line lambda for clearer readability. |
wrapanapi/systems/msazure.py |
Introduce lazy Azure SDK imports to avoid import-time failures when Azure deps aren’t installed. |
wrapanapi/systems/__init__.py |
Replace eager provider imports with module __getattr__ lazy import dispatch. |
wrapanapi/__init__.py |
Replace eager convenience imports with module __getattr__ lazy import dispatch. |
.pre-commit-config.yaml |
Update ruff-pre-commit and pyupgrade hook revisions. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
tpapaioa
approved these changes
Feb 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes:
VmStatein Robottelo could trigger errors due to the eager loading of all system provider modules and their heavy dependencies. This change allowsVmStateto be imported without pulling in unused provider SDKs.Refactoring:
__getattr__inwrapanapi/__init__.pyandwrapanapi/systems/__init__.pyto lazily import system classes (e.g.,EC2System,VMWareSystem). This defers the loading of module dependencies until a specific system class is accessed.wrapanapi/systems/msazure.py. Azure dependencies are now loaded only when an Azure system or entity is instantiated, avoiding unnecessary module loading and potential import errors when the SDK is not present or needed.wrapanapi/systems/nuage.pyfor improved readability.Configuration:
ruff-pre-committo versionv0.15.0.pyupgradeto versionv3.21.2.