Skip to content

Conversation

@xcrsz
Copy link
Contributor

@xcrsz xcrsz commented May 30, 2025

  • Replaced linear search with logarithmic time prefix search
  • Introduced @dataclass-based Package model
  • Added PkgSearchIndex with bisect for fast exact/prefix lookup
  • Refactored MainWindow to display version and install status

Summary by Sourcery

Optimize package search by building a bisect-based index for fast lookups and update the UI to show package versions and install status

New Features:

  • Introduce Package dataclass for structured package metadata
  • Add PkgSearchIndex class with bisect-based exact and prefix search methods

Enhancements:

  • Replace linear package lookup with logarithmic bisect-based prefix search
  • Refactor MainWindow to display package version and installation status

@xcrsz xcrsz requested review from a team as code owners May 30, 2025 11:26
@sourcery-ai
Copy link

sourcery-ai bot commented May 30, 2025

Reviewer's Guide

This PR introduces a dataclass-based Package model and a bisect-driven PkgSearchIndex for logarithmic-time exact and prefix lookups, integrates that index into PkgInfo (replacing its previous linear search), and updates the MainWindow UI to wire live search to the new index and show version/install status.

Sequence Diagram for Optimized Package Search

sequenceDiagram
    actor User
    participant MW as MainWindow
    participant PI as PkgInfo
    participant PSI as PkgSearchIndex

    User->>+MW: Types in search_entry
    MW->>MW: on_search_entry_changed(entry)
    MW->>PI: search(text)
    activate PI
    PI->>PSI: search_prefix(text)
    activate PSI
    PSI-->>PI: List~Package~
    deactivate PSI
    PI-->>MW: List~Package~
    deactivate PI
    MW->>MW: display_packages(packages)
    MW-->>-User: Updates package_list
Loading

Sequence Diagram for Application Initialization and Package Indexing

sequenceDiagram
    participant UserOrSystem as User/System
    participant MW as MainWindow
    participant PI as PkgInfo
    participant PSI as PkgSearchIndex

    UserOrSystem->>+MW: Create MainWindow
    MW->>+PI: Create PkgInfo()
    PI->>PI: load_installed()
    PI->>PI: load_available() 
    PI->>+PSI: Create PkgSearchIndex(pkg.available)
    PSI-->>-PI: PkgSearchIndex instance created
    PI-->>-MW: PkgInfo instance created
    MW->>MW: display_packages(pkg.available)
    MW-->>-UserOrSystem: Displays packages
Loading

Class Diagram of New and Modified Software Components

classDiagram
    class Package {
      +name: str
      +description: str
      +version: str
      +installed: bool
    }

    class PkgSearchIndex {
      -key: str
      -sorted_packages: List~Package~
      -sorted_keys: List~str~
      +__init__(packages: List~Package~, key: str)
      +search_exact(value: str) : Optional~Package~
      +search_prefix(prefix: str) : List~Package~
    }

    class PkgInfo {
      +available: List~Package~
      -installed_names: set~str~
      -index: PkgSearchIndex
      +__init__()
      +load_installed()
      +load_available()
      +search(prefix: str) : List~Package~
      +get_installed() : List~Package~
    }

    class MainWindow {
      -pkg: PkgInfo
      -search_entry: Gtk.Entry
      -package_list: Gtk.ListBox
      +__init__()
      +on_search_entry_changed(entry: Gtk.Entry)
      +display_packages(packages: List~Package~)
    }

    MainWindow "1" *-- "1" PkgInfo : owns
    PkgInfo "1" *-- "1" PkgSearchIndex : owns
    PkgInfo "1" *-- "0..*" Package : creates and owns
    PkgSearchIndex "1" o-- "0..*" Package : aggregates/references
Loading

File-Level Changes

Change Details Files
Implemented bisect-based search index with dataclass model
  • Define Package model using @DataClass
  • Create PkgSearchIndex that maintains sorted keys and supports search_exact and search_prefix via bisect
search_index.py
Refactored PkgInfo to build and use search index
  • Load available packages into dataclass instances
  • Initialize PkgSearchIndex after loading available packages
  • Replace linear search in search() with index.search_prefix
PkgInfo.py
Enhanced MainWindow UI to display package details and integrate fast search
  • Connect search entry changes to PkgInfo.search for live prefix filtering
  • Display package name, version, description, and installed status in the list
MainWindow.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @xcrsz - I've reviewed your changes - here's some feedback:

Blocking issues:

  • return should never appear inside a class init function. This will cause a runtime error. (link)

General comments:

  • PkgSearchIndex.search_prefix’s next_prefix logic is brittle—consider using bisect_right on prefix + '\uffff' (or another high‐sentinel) instead of manually bumping the last character to compute the end bound.
  • Normalize both stored package names and the search prefix to lowercase (or use a casefold) so searches become case-insensitive and more user-friendly.
  • PkgInfo.search returns an empty list when the index is None, which clears the UI if indexing fails; consider falling back to returning the full available list instead of an empty result.
Here's what I looked at during the review
  • 🟡 General issues: 4 issues found
  • 🔴 Security: 1 blocking issue
  • 🟢 Testing: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@xcrsz
Copy link
Contributor Author

xcrsz commented May 30, 2025

All Sourcery-AI conversation have been resolved.

@github-project-automation github-project-automation bot moved this from In Review to In Progress in Development Tracker May 31, 2025
Copy link
Member

@ericbsd ericbsd left a comment

Choose a reason for hiding this comment

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

Files should not be CamelCase. It should be snack_case. Like main_window.py.

xcrsz added 11 commits May 31, 2025 23:21
- Moved imports (gi, Gtk) to top of main_window.py to fix C0413 (wrong-import-position).
- Removed trailing whitespace in main_window.py to fix C0303.
- Added pylint: disable=no-member for Gtk.Window methods to fix E1101 false positives.
- Added reset method to MainWindow to fix R0903 (too-few-public-methods).
- Included gi.require_version to fix W0611 (unused-import).
- Removed PkgDataProvider import to avoid E0401 and E0611 errors.
- Updated main_window.py to maintain GTK application functionality.
- Fixed KeyError in update_search by adding validation for empty package names and using safe dictionary access with get().
- Added error handling for KeyError and TypeError in package search processing.
- Suppressed E1101 (no-member) for GTK methods with pylint directives to fix false positives.
- Ensured imports are correctly placed to resolve C0413 (wrong-import-position).
- Removed trailing whitespace to fix C0303.
- Fixed W0611 (unused-import) by ensuring gi is used via gi.require_version.
- Created software_station_pkg.py with mock data to resolve E0401 and E0611 if needed.
- Preserved all Software Station functionality, including package management and UI.
- Replaced bcrypt with crypt.crypt for SHA-512 ($6$) password hashing to match GhostBSD’s hash format. This is a reverted change.
- Updated Confirmation.confirm_passwd to verify passwords against /etc/master.passwd hashes.
- Added debug logging to trace password verification issues.
- Retained KeyError fix in update_search, NameError fix for gettext, and pylint improvements.
- Removed py311-bcrypt dependency, using standard library crypt.
- Added docstrings to address pylint C0116 warnings.
- Preserved Software Station functionality, including package management and UI.
- Removed main_window.py, which duplicated software-station’s GTK window setup, main loop, and destroy signal handling.
- No functional loss, as main_window.py was a minimal prototype.
Copy link
Member

@ericbsd ericbsd left a comment

Choose a reason for hiding this comment

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

LGTM

@ericbsd ericbsd merged commit 2711104 into ghostbsd:master Jun 12, 2025
@github-project-automation github-project-automation bot moved this from In Progress to Done in Development Tracker Jun 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants