jhanley634 / dojo-blackboard

An HTMX webserver for the Dojo's Tuesday night python meetups.
MIT License
3 stars 1 forks source link

53 bisect #55

Closed jhanley634 closed 1 day ago

jhanley634 commented 1 day ago

Summary by Sourcery

Enhance the line counting functionality by introducing an XmlLineCounter for XML files and refactoring the line counting logic to be more flexible. Add new tests to verify the handling of XML, HTML, and PHP files, and introduce a bisect test to identify discrepancies in line counts.

New Features:

Enhancements:

Tests:

sourcery-ai[bot] commented 1 day ago

Reviewer's Guide by Sourcery

This PR implements improvements to the source line counting functionality, focusing on better handling of different file types and comment styles. The changes include refactoring the line counter classes, adding XML file support, and introducing a binary search utility to help debug counting discrepancies.

Class diagram for updated line counting functionality

classDiagram
    class LineCounter {
        +int blank
        +int comment
        +int code
        +__init__(lines: Iterable[str] | Path)
        +_get_line_types(lines: list[str])
        +expand_comments(lines: Iterable[str])
    }
    class XmlLineCounter {
        +expand_comments(lines: Iterable[str])
    }
    class BashLineCounter {
    }
    class PythonLineCounter {
    }
    LineCounter <|-- XmlLineCounter
    LineCounter <|-- BashLineCounter
    LineCounter <|-- PythonLineCounter
    class DiscrepancyFinder {
        +list[str] lines
        +str suffix
        +bisect(n: int) int
        +_counts_equal(n: int) bool
        +_get_both_counts(n: int) tuple[ClocCounts, LineCounter]
    }

Class diagram for new bisect functionality

classDiagram
    class DiscrepancyFinder {
        +list[str] lines
        +str suffix
        +bisect(n: int) int
        +_counts_equal(n: int) bool
        +_get_both_counts(n: int) tuple[ClocCounts, LineCounter]
    }
    class ClocCounts {
    }
    class LineCounter {
    }
    DiscrepancyFinder --> ClocCounts
    DiscrepancyFinder --> LineCounter

File-Level Changes

Change Details Files
Added XML file type support with dedicated comment handling
  • Created new XmlLineCounter class to handle XML-style comments
  • Added support for comment syntax
  • Defined XML_LANGUAGES constant for file type detection
src/count/sloc.py
src/count/tests/sloc_html_test.py
Refactored line counter initialization and file type handling
  • Moved language-specific constants to module level
  • Created get_counts helper function to determine appropriate counter type
  • Modified LineCounter to accept both file paths and line iterables
  • Improved comment pattern handling across different file types
src/count/sloc.py
Added binary search utility for debugging count discrepancies
  • Created new bisect.py module with DiscrepancyFinder class
  • Implemented binary search to locate first line causing counting differences
  • Added temporary file handling for incremental testing
src/count/bisect.py
Updated test suite and dependencies
  • Added new test cases for XML file handling
  • Modified existing tests to use new counter initialization
  • Updated various package dependencies to newer versions
  • Adjusted ruff linter configuration
src/count/tests/sloc_test.py
requirements.txt
pyproject.toml

Possibly linked issues


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. - **Generate a pull request title:** Write `@sourcery-ai` anywhere in the pull request title to generate a 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. You can also use this command to specify where the summary should be inserted. #### Customizing Your Experience Access your [dashboard](https://app.sourcery.ai) 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 - [Contact our support team](mailto:support@sourcery.ai) for questions or feedback. - Visit our [documentation](https://docs.sourcery.ai) for detailed guides and information. - Keep in touch with the Sourcery team by following us on [X/Twitter](https://x.com/SourceryAI), [LinkedIn](https://www.linkedin.com/company/sourcery-ai/) or [GitHub](https://github.com/sourcery-ai).