Skip to content

Conversation

ctoth
Copy link
Contributor

@ctoth ctoth commented Mar 7, 2025

Link to issue number:

N/A - Code organization improvement

Summary of the issue:

The addonHandler module was overly large with all functionality in init.py, making it difficult to maintain and understand. This PR reorganizes the code into smaller, more focused modules while preserving the same functionality, and adds tests for the AddonBundle component.

Description of user facing changes

None. This is a purely internal refactoring of the codebase with no user-facing changes.

Description of development approach

This PR splits the large addonHandler/__init__.py file into several logical modules:

  • addonBase.py - Contains base classes and common exceptions
  • addon.py - Contains the main Addon class implementation
  • AddonBundle.py - Contains bundle-related functionality
  • AddonManifest.py - Contains manifest-related functionality
  • addonState.py - Manages the state of addons in NVDA

The PR focuses on maintaining functionality while improving code organization. The main additions are unit tests for the AddonBundle functionality, which previously lacked test coverage.

Testing strategy:

  • Added comprehensive unit tests for the AddonBundle module
  • Manually verified that addon functionality still works correctly
  • Ensured that existing tests pass with the new structure

Known issues with pull request:

None

Code Review Checklist:

  • Documentation:
    • Change log entry - N/A (internal code reorganization)
    • User Documentation - N/A (no user-facing changes)
    • Developer / Technical Documentation - Improved through better docstrings
    • Context sensitive help for GUI changes - N/A (no GUI changes)
  • Testing:
    • Unit tests - Added new tests for AddonBundle
    • System (end to end) tests - Existing tests validate the functionality
    • Manual testing - Verified addon installation/management works as before
  • UX of all users considered - N/A (internal refactoring only)
  • API is compatible with existing add-ons - Preserved full API compatibility
  • Security precautions taken - No changes to security model

@coderabbitai summary

ctoth added 16 commits March 6, 2025 09:22
Split addon handling code into separate modules:
- AddonBase.py - Base classes AddonBase and AddonError
- AddonBundle.py - Bundle class for handling addon packages
- AddonManifest.py - Manifest class and manifest handling

This improves code organization by:
- Separating concerns into logical modules
- Reducing complexity of __init__.py

No functional changes, only code reorganization.
Move the Addon class from addonHandler/__init__.py into its own module (addon.py) to improve code organization and readability. Also move AddonStateCategory enum and state management from addonStore/models/status.py to addonHandler/addonState.py where it more logically belongs.

This is a refactoring change that:
- Reduces the size of addonHandler/__init__.py by extracting Addon class
- Places addon state management closer to the addon code
- Improves overall code modularity and organization
Tests cover bundle initialization, validation, extraction, and creation from directories, including various error handling scenarios. Both mocked and real file tests ensure proper functionality with different file types and path formats.
@SaschaCowley
Copy link
Member

@ctoth is this PR ready for review?

@ctoth ctoth closed this Mar 21, 2025
@ctoth ctoth reopened this Mar 21, 2025
@ctoth ctoth marked this pull request as ready for review March 21, 2025 03:47
@ctoth ctoth requested a review from a team as a code owner March 21, 2025 03:47
@ctoth ctoth requested a review from seanbudd March 21, 2025 03:47
@seanbudd seanbudd added the conceptApproved Similar 'triaged' for issues, PR accepted in theory, implementation needs review. label Apr 1, 2025
@seanbudd seanbudd added this to the 2025.2 milestone Apr 4, 2025
@@ -0,0 +1,121 @@
# A part of NonVisual Desktop Access (NVDA)
Copy link
Member

Choose a reason for hiding this comment

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

please use lowerCamelCase for file names i.e. addonBundle

@@ -0,0 +1,160 @@
# A part of NonVisual Desktop Access (NVDA)
Copy link
Member

Choose a reason for hiding this comment

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

please use lowerCamelCase for file names i.e. addonManifest


configspec = ConfigObj(
StringIO(
"""
Copy link
Member

Choose a reason for hiding this comment

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

could we perhaps move this to a separate ini file that is read from at run time?

@@ -0,0 +1,575 @@
# A part of NonVisual Desktop Access (NVDA)
Copy link
Member

Choose a reason for hiding this comment

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

Note: this file has not been fully reviewed - however the rest of this PR has been


def __repr__(self) -> str:
return f"{self.__class__.__name__} ({self.name!r} at path {self.path!r}, running={self.isRunning!r})"
def getCodeAddon(obj=None, frameDist=1):
Copy link
Member

Choose a reason for hiding this comment

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

please add type hints

log.warning("Error loading manifest:\n%s", manifest.errors)


class AddonManifest(ConfigObj):
Copy link
Member

Choose a reason for hiding this comment

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

this appears to be an API breaking change, it's missing from __all__

return minRequiredVersion <= lastTested


def validate_apiVersionString(value: str) -> Tuple[int, int, int]:
Copy link
Member

Choose a reason for hiding this comment

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

this appears to be an API breaking change, it's missing from __all__

return addonAPIVersion.getAPIVersionTupleFromString(value)
except ValueError as e:
raise ValidateError('"{}" is not a valid API Version string: {}'.format(value, e))
__all__ = [
Copy link
Member

Choose a reason for hiding this comment

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

Manually verified that addon functionality still works correctly

Can you confirm how you tested this? did you check the diff of dir(addonHandler) from the NVDA python console?

@seanbudd seanbudd marked this pull request as draft April 9, 2025 07:23
@AppVeyorBot
Copy link

See test results for failed build of commit 8a56a26377

@seanbudd seanbudd removed this from the 2025.2 milestone Jun 17, 2025
@seanbudd
Copy link
Member

@ctoth - do you intend to work on this still?

@seanbudd seanbudd added the blocked/merge-conflicts Merge conflicts exist on this PR label Jun 24, 2025
@seanbudd
Copy link
Member

seanbudd commented Aug 8, 2025

@ctoth - closing this as abandoned. Feel free to open a new PR if you wish to continue to make these changes

@seanbudd seanbudd closed this Aug 8, 2025
@seanbudd seanbudd added the Abandoned requested reports or updates are missing since more than 1 year, author or users are not available. label Aug 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Abandoned requested reports or updates are missing since more than 1 year, author or users are not available. blocked/merge-conflicts Merge conflicts exist on this PR conceptApproved Similar 'triaged' for issues, PR accepted in theory, implementation needs review.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants