Skip to content

Comments

Defer import of system modules and Azure SDKs#527

Merged
JacobCallahan merged 1 commit intomasterfrom
lessblue
Feb 10, 2026
Merged

Defer import of system modules and Azure SDKs#527
JacobCallahan merged 1 commit intomasterfrom
lessblue

Conversation

@JacobCallahan
Copy link
Contributor

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.

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`.
Copilot AI review requested due to automatic review settings February 10, 2026 16:26
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 in wrapanapi/__init__.py and wrapanapi/systems/__init__.py to defer provider system imports until accessed.
  • Lazily import Azure SDK components in wrapanapi/systems/msazure.py via 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 tpapaioa self-requested a review February 10, 2026 19:25
@JacobCallahan JacobCallahan merged commit 8f6287c into master Feb 10, 2026
10 checks passed
@JacobCallahan JacobCallahan deleted the lessblue branch February 10, 2026 19:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants